sanity 5.28.0-next.7 → 5.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-dts/types2.d.ts +2 -1
- package/lib/_chunks-es/PostMessagePerspective.js +8 -7
- package/lib/_chunks-es/PostMessagePerspective.js.map +1 -1
- package/lib/_chunks-es/PostMessageSchema.js +7 -4
- package/lib/_chunks-es/PostMessageSchema.js.map +1 -1
- package/lib/_chunks-es/PresentationToolGrantsCheck.js +38 -30
- package/lib/_chunks-es/PresentationToolGrantsCheck.js.map +1 -1
- package/lib/_chunks-es/createAgentBundlesStore.js +52 -0
- package/lib/_chunks-es/createAgentBundlesStore.js.map +1 -0
- package/lib/_chunks-es/resources.js +1 -0
- package/lib/_chunks-es/resources.js.map +1 -1
- package/lib/_chunks-es/resources2.js +1 -0
- package/lib/_chunks-es/resources2.js.map +1 -1
- package/lib/_chunks-es/resources3.js +1 -0
- package/lib/_chunks-es/resources3.js.map +1 -1
- package/lib/_chunks-es/resources4.js +1 -0
- package/lib/_chunks-es/resources4.js.map +1 -1
- package/lib/_chunks-es/resources5.js +1 -0
- package/lib/_chunks-es/resources5.js.map +1 -1
- package/lib/_chunks-es/resources6.js +1 -0
- package/lib/_chunks-es/resources6.js.map +1 -1
- package/lib/_chunks-es/version.js +2 -2
- package/lib/index.js +22 -66
- package/lib/index.js.map +1 -1
- package/package.json +14 -14
|
@@ -3,7 +3,7 @@ import { SanityDocument } from "@sanity/types";
|
|
|
3
3
|
import { ClientPerspective, StackablePerspective } from "@sanity/client";
|
|
4
4
|
import { Observable } from "rxjs";
|
|
5
5
|
import { DocumentStore, DocumentValuePermission, PermissionCheckResult, SanityClient as SanityClient$1 } from "sanity";
|
|
6
|
-
import { PreviewUrlResolver } from "/home/runner/work/sanity/sanity/node_modules/.pnpm/@sanity+preview-url-secret@4.0.
|
|
6
|
+
import { PreviewUrlResolver } from "/home/runner/work/sanity/sanity/node_modules/.pnpm/@sanity+preview-url-secret@4.0.6_@sanity+client@7.22.0/node_modules/@sanity/preview-url-secret/dist/define-preview-url.js";
|
|
7
7
|
import * as _$xstate from "xstate";
|
|
8
8
|
import { ActorRefFrom } from "xstate";
|
|
9
9
|
interface Context$2 {
|
|
@@ -209,6 +209,7 @@ interface PreviewProps {
|
|
|
209
209
|
viewport: PresentationViewport;
|
|
210
210
|
vercelProtectionBypass: string | null;
|
|
211
211
|
previewUrlRef: PreviewUrlRef;
|
|
212
|
+
handlesPerspectiveChange: boolean;
|
|
212
213
|
}
|
|
213
214
|
/** @public */
|
|
214
215
|
interface PreviewHeaderProps extends PreviewProps {
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { c } from "react/compiler-runtime";
|
|
2
|
-
import { memo, useEffect } from "react";
|
|
2
|
+
import { memo, useEffect, startTransition } from "react";
|
|
3
3
|
const PostMessagePerspective = (props) => {
|
|
4
|
-
const $ = c(
|
|
4
|
+
const $ = c(9), {
|
|
5
5
|
comlink,
|
|
6
|
-
perspective
|
|
6
|
+
perspective,
|
|
7
|
+
setHandlesPerspectiveChange
|
|
7
8
|
} = props;
|
|
8
9
|
let t0, t1;
|
|
9
|
-
$[0] !== comlink || $[1] !== perspective ? (t0 = () => comlink.on("visual-editing/fetch-perspective", () => ({
|
|
10
|
+
$[0] !== comlink || $[1] !== perspective || $[2] !== setHandlesPerspectiveChange ? (t0 = () => comlink.on("visual-editing/fetch-perspective", (payload) => (startTransition(() => setHandlesPerspectiveChange(payload?.handlesPerspectiveChange === !0)), {
|
|
10
11
|
perspective
|
|
11
|
-
})), t1 = [comlink, perspective], $[0] = comlink, $[1] = perspective, $[2] =
|
|
12
|
+
})), t1 = [comlink, perspective, setHandlesPerspectiveChange], $[0] = comlink, $[1] = perspective, $[2] = setHandlesPerspectiveChange, $[3] = t0, $[4] = t1) : (t0 = $[3], t1 = $[4]), useEffect(t0, t1);
|
|
12
13
|
let t2, t3;
|
|
13
|
-
return $[
|
|
14
|
+
return $[5] !== comlink || $[6] !== perspective ? (t2 = () => {
|
|
14
15
|
comlink.post("presentation/perspective", {
|
|
15
16
|
perspective
|
|
16
17
|
});
|
|
17
|
-
}, t3 = [comlink, perspective], $[
|
|
18
|
+
}, t3 = [comlink, perspective], $[5] = comlink, $[6] = perspective, $[7] = t2, $[8] = t3) : (t2 = $[7], t3 = $[8]), useEffect(t2, t3), null;
|
|
18
19
|
};
|
|
19
20
|
var PostMessagePerspective_default = memo(PostMessagePerspective);
|
|
20
21
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostMessagePerspective.js","sources":["../../src/presentation/PostMessagePerspective.tsx"],"sourcesContent":["import {type ClientPerspective} from '@sanity/client'\nimport {type FC, memo, useEffect} from 'react'\n\nimport {type VisualEditingConnection} from './types'\n\nexport interface PostMessagePerspectiveProps {\n comlink: VisualEditingConnection\n perspective: ClientPerspective\n}\n\nconst PostMessagePerspective: FC<PostMessagePerspectiveProps> = (props) => {\n const {comlink, perspective} = props\n\n // Return the perspective when requested\n useEffect(() => {\n return comlink.on('visual-editing/fetch-perspective', () =>
|
|
1
|
+
{"version":3,"file":"PostMessagePerspective.js","sources":["../../src/presentation/PostMessagePerspective.tsx"],"sourcesContent":["import {type ClientPerspective} from '@sanity/client'\nimport {type FC, memo, startTransition, useEffect} from 'react'\n\nimport {type VisualEditingConnection} from './types'\n\nexport interface PostMessagePerspectiveProps {\n comlink: VisualEditingConnection\n perspective: ClientPerspective\n setHandlesPerspectiveChange: (payload: boolean) => void\n}\n\nconst PostMessagePerspective: FC<PostMessagePerspectiveProps> = (props) => {\n const {comlink, perspective, setHandlesPerspectiveChange} = props\n\n // Return the perspective when requested\n useEffect(() => {\n return comlink.on('visual-editing/fetch-perspective', (payload) => {\n // Report back whether the visual editing handler is set up to own perspective switching or not, if the payload is `undefined` then it means the visual editing instance isn't recent enough and we treat it as false\n startTransition(() => setHandlesPerspectiveChange(payload?.handlesPerspectiveChange === true))\n return {perspective}\n })\n }, [comlink, perspective, setHandlesPerspectiveChange])\n\n // Dispatch a perspective message when the perspective changes\n useEffect(() => {\n comlink.post('presentation/perspective', {perspective})\n }, [comlink, perspective])\n\n return null\n}\n\nexport default memo(PostMessagePerspective)\n"],"names":["PostMessagePerspective","props","$","_c","comlink","perspective","setHandlesPerspectiveChange","t0","t1","on","payload","startTransition","handlesPerspectiveChange","useEffect","t2","t3","post","memo"],"mappings":";;AAWA,MAAMA,yBAA0DC,CAAAA,UAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GAC9D;AAAA,IAAAC;AAAAA,IAAAC;AAAAA,IAAAC;AAAAA,EAAAA,IAA4DL;AAAK,MAAAM,IAAAC;AAAAN,IAAA,CAAA,MAAAE,WAAAF,SAAAG,eAAAH,EAAA,CAAA,MAAAI,+BAGvDC,KAAAA,MACDH,QAAOK,GAAI,oCAAoCC,CAAAA,aAEpDC,gBAAgB,MAAML,4BAA4BI,SAAOE,6BAA+B,EAAI,CAAC,GACtF;AAAA,IAAAP;AAAAA,EAAAA,EACR,GACAG,MAACJ,SAASC,aAAaC,2BAA2B,GAACJ,OAAAE,SAAAF,OAAAG,aAAAH,OAAAI,6BAAAJ,OAAAK,IAAAL,OAAAM,OAAAD,KAAAL,EAAA,CAAA,GAAAM,KAAAN,EAAA,CAAA,IANtDW,UAAUN,IAMPC,EAAmD;AAAC,MAAAM,IAAAC;AAAA,SAAAb,EAAA,CAAA,MAAAE,WAAAF,SAAAG,eAG7CS,KAAAA,MAAA;AACRV,YAAOY,KAAM,4BAA4B;AAAA,MAAAX;AAAAA,IAAAA,CAAa;AAAA,EAAC,GACtDU,KAAA,CAACX,SAASC,WAAW,GAACH,OAAAE,SAAAF,OAAAG,aAAAH,OAAAY,IAAAZ,OAAAa,OAAAD,KAAAZ,EAAA,CAAA,GAAAa,KAAAb,EAAA,CAAA,IAFzBW,UAAUC,IAEPC,EAAsB,GAElB;AAAI;AAGb,IAAA,iCAAeE,KAAKjB,sBAAsB;"}
|
|
@@ -469,29 +469,32 @@ function PostMessageSchema(props) {
|
|
|
469
469
|
}, {
|
|
470
470
|
tag: "presentation-schema",
|
|
471
471
|
perspective
|
|
472
|
-
}), mapped = arr.map((path_0, i_0) =>
|
|
472
|
+
}), mapped = arr.map((path_0, i_0) => typeof result?.[i_0] == "string" ? {
|
|
473
473
|
path: path_0,
|
|
474
474
|
type: result[i_0]
|
|
475
|
-
}));
|
|
475
|
+
} : null).filter(_temp2);
|
|
476
476
|
return {
|
|
477
477
|
id,
|
|
478
478
|
paths: mapped
|
|
479
479
|
};
|
|
480
480
|
})), newState = /* @__PURE__ */ new Map();
|
|
481
481
|
return unionTypes.forEach((action) => {
|
|
482
|
-
newState.set(action.id, new Map(action.paths.map(
|
|
482
|
+
newState.set(action.id, new Map(action.paths.map(_temp3)));
|
|
483
483
|
}), {
|
|
484
484
|
types: newState
|
|
485
485
|
};
|
|
486
486
|
}), t4 = [comlink, client, perspective], $[6] = client, $[7] = comlink, $[8] = perspective, $[9] = t3, $[10] = t4) : (t3 = $[9], t4 = $[10]), useEffect(t3, t4), null;
|
|
487
487
|
}
|
|
488
|
-
function
|
|
488
|
+
function _temp3(t0) {
|
|
489
489
|
const {
|
|
490
490
|
path: path_1,
|
|
491
491
|
type
|
|
492
492
|
} = t0;
|
|
493
493
|
return [path_1, type];
|
|
494
494
|
}
|
|
495
|
+
function _temp2(item) {
|
|
496
|
+
return item !== null;
|
|
497
|
+
}
|
|
495
498
|
function _temp(path, i) {
|
|
496
499
|
return `"${i}": ${path}[0]._type`;
|
|
497
500
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostMessageSchema.js","sources":["../../src/presentation/overlays/schema/helpers.ts","../../src/presentation/overlays/schema/SchemaIcon.tsx","../../src/presentation/overlays/schema/extract.tsx","../../src/presentation/overlays/schema/PostMessageSchema.tsx"],"sourcesContent":["import {\n type ArraySchemaType,\n type NumberSchemaType,\n type ObjectField,\n type ObjectFieldType,\n type ObjectSchemaType,\n type ReferenceSchemaType,\n type Rule,\n type Schema as SchemaDef,\n type SchemaType as SanitySchemaType,\n type StringSchemaType,\n} from '@sanity/types'\nimport {type SchemaType} from 'groq-js'\n\nexport function isFieldRequired(field: ObjectField): boolean {\n const {validation} = field.type\n if (!validation) {\n return false\n }\n const rules = Array.isArray(validation) ? validation : [validation]\n for (const rule of rules) {\n let required = false\n\n // hack to check if a field is required. We create a proxy that returns itself when a method is called,\n // if the method is \"required\" we set a flag\n const proxy = new Proxy(\n {},\n {\n get: (target, methodName) => () => {\n if (methodName === 'required') {\n required = true\n }\n return proxy\n },\n },\n ) as Rule\n\n if (typeof rule === 'function') {\n rule(proxy)\n if (required) {\n return true\n }\n }\n\n if (typeof rule === 'object' && rule !== null && '_required' in rule) {\n if (rule._required === 'required') {\n return true\n }\n }\n }\n\n return false\n}\n\nfunction isType(\n typeDef: SanitySchemaType | ObjectField | ObjectFieldType,\n typeName: string,\n): boolean {\n let type: SchemaType | ObjectField | ObjectFieldType | undefined = typeDef\n while (type) {\n if (type.name === typeName || (type.type && type.type.name === typeName)) {\n return true\n }\n\n type = type.type\n }\n return false\n}\n\nexport function isObjectType(typeDef: SanitySchemaType): typeDef is ObjectSchemaType {\n return isType(typeDef, 'object') || typeDef.jsonType === 'object' || 'fields' in typeDef\n}\nexport function isArrayType(typeDef: SanitySchemaType): typeDef is ArraySchemaType {\n return isType(typeDef, 'array')\n}\nexport function isReferenceType(typeDef: SanitySchemaType): typeDef is ReferenceSchemaType {\n return isType(typeDef, 'reference')\n}\n// @todo\nexport function isCrossDatasetReferenceType(typeDef: SanitySchemaType): boolean {\n return isType(typeDef, 'crossDatasetReference')\n}\nexport function isStringType(typeDef: SanitySchemaType): typeDef is StringSchemaType {\n return isType(typeDef, 'string')\n}\nexport function isNumberType(typeDef: SanitySchemaType): typeDef is NumberSchemaType {\n return isType(typeDef, 'number')\n}\n\n// Traverse the type tree and return the \"last\" type, ie deepest type in the tree\nexport function lastType(typeDef: SanitySchemaType): SanitySchemaType | undefined {\n let type: SchemaType | ObjectField | ObjectFieldType | undefined = typeDef\n while (type) {\n if (!type.type) {\n return type\n }\n type = type.type\n }\n\n return undefined\n}\n\n// Traverse the type tree and gather all the fields\nexport function gatherFields(type: SanitySchemaType | ObjectSchemaType): ObjectField[] {\n if ('fields' in type) {\n return type.type ? gatherFields(type.type).concat(type.fields) : type.fields\n }\n\n return []\n}\n\n// Sorts the types by their dependencies by using a topological sort depth-first algorithm.\nexport function sortByDependencies(compiledSchema: SchemaDef): string[] {\n const seen = new Set<SanitySchemaType>()\n\n // Walks the dependencies of a schema type and adds them to the dependencies set\n function walkDependencies(\n schemaType: SanitySchemaType,\n dependencies: Set<SanitySchemaType>,\n ): void {\n if (seen.has(schemaType)) {\n return\n }\n seen.add(schemaType)\n\n if ('fields' in schemaType) {\n for (const field of gatherFields(schemaType)) {\n const last = lastType(field.type)\n if (last!.name === 'document') {\n dependencies.add(last!)\n continue\n }\n\n let schemaTypeName: string | undefined\n if (schemaType.type!.type) {\n schemaTypeName = field.type.type!.name\n } else if ('jsonType' in schemaType.type!) {\n schemaTypeName = field.type.jsonType\n }\n\n if (schemaTypeName === 'object' || schemaTypeName === 'block') {\n if (isReferenceType(field.type)) {\n field.type.to.forEach((ref) => dependencies.add(ref.type!))\n } else {\n dependencies.add(field.type)\n }\n }\n walkDependencies(field.type, dependencies)\n }\n } else if ('of' in schemaType) {\n for (const item of schemaType.of) {\n walkDependencies(item, dependencies)\n }\n }\n }\n const dependencyMap = new Map<SanitySchemaType, Set<SanitySchemaType>>()\n compiledSchema.getTypeNames().forEach((typeName) => {\n const schemaType = compiledSchema.get(typeName)\n if (schemaType === undefined || schemaType.type === null) {\n return\n }\n const dependencies = new Set<SanitySchemaType>()\n\n walkDependencies(schemaType, dependencies)\n dependencyMap.set(schemaType, dependencies)\n seen.clear() // Clear the seen set for the next type\n })\n\n // Sorts the types by their dependencies\n const typeNames: string[] = []\n // holds a temporary mark for types that are currently being visited, to detect cyclic dependencies\n const currentlyVisiting = new Set<SanitySchemaType>()\n\n // holds a permanent mark for types that have been already visited\n const visited = new Set<SanitySchemaType>()\n\n // visit implements a depth-first search\n function visit(type: SanitySchemaType) {\n if (visited.has(type)) {\n return\n }\n // If we find a type that is already in the temporary mark, we have a cyclic dependency.\n if (currentlyVisiting.has(type)) {\n return\n }\n // mark this as a temporary mark, meaning it's being visited\n currentlyVisiting.add(type)\n const deps = dependencyMap.get(type)\n if (deps !== undefined) {\n deps.forEach((dep) => visit(dep))\n }\n currentlyVisiting.delete(type)\n visited.add(type)\n\n if (!typeNames.includes(type.name)) {\n typeNames.unshift(type.name)\n }\n }\n // Visit all types in the dependency map\n for (const [type] of dependencyMap) {\n visit(type)\n }\n\n return typeNames\n}\n","import {type SchemaType as SanitySchemaType} from '@sanity/types'\nimport {isValidElement} from 'react'\n\nexport function SchemaIcon({schemaType}: {schemaType: SanitySchemaType}): React.JSX.Element | null {\n const Icon = schemaType.icon\n\n return Icon ? isValidElement(Icon) ? Icon : <Icon /> : null\n}\n","import {\n type InsertMenuOptions,\n type SchemaArrayNode,\n type SchemaBooleanNode,\n type SchemaInlineNode,\n type SchemaNode,\n type SchemaNullNode,\n type SchemaNumberNode,\n type SchemaObjectField,\n type SchemaObjectNode,\n type SchemaStringNode,\n type SchemaType,\n type SchemaUnionNode,\n type SchemaUnionNodeOptions,\n type SchemaUnionOption,\n type SchemaUnknownNode,\n} from '@sanity/presentation-comlink'\nimport {\n type ArraySchemaType,\n type NumberSchemaType,\n type ObjectSchemaType,\n type ReferenceSchemaType,\n type SchemaType as SanitySchemaType,\n type StringSchemaType,\n} from '@sanity/types'\nimport {renderToString} from 'react-dom/server'\nimport {type Workspace} from 'sanity'\n\nimport {\n gatherFields,\n isArrayType,\n isCrossDatasetReferenceType,\n isFieldRequired,\n isNumberType,\n isObjectType,\n isReferenceType,\n isStringType,\n lastType,\n sortByDependencies,\n} from './helpers'\nimport {SchemaIcon} from './SchemaIcon'\n\nconst documentDefaultFields = (typeName: string): Record<string, SchemaObjectField> => ({\n _id: {\n type: 'objectField',\n name: '_id',\n value: {\n type: 'string',\n },\n },\n _type: {\n type: 'objectField',\n name: '_type',\n value: {\n type: 'string',\n value: typeName,\n },\n },\n _createdAt: {\n type: 'objectField',\n name: '_createdAt',\n value: {\n type: 'string',\n },\n },\n _updatedAt: {\n type: 'objectField',\n name: '_updatedAt',\n value: {\n type: 'string',\n },\n },\n _rev: {\n type: 'objectField',\n name: '_rev',\n value: {\n type: 'string',\n },\n },\n})\n\nfunction createStringNodeDefintion(\n stringSchemaType: StringSchemaType,\n): SchemaStringNode | SchemaUnionNode<SchemaStringNode> {\n const listOptions = stringSchemaType.options?.list\n if (listOptions && Array.isArray(listOptions)) {\n return {\n type: 'union',\n of: listOptions.map((v) => ({\n type: 'string',\n value: typeof v === 'string' ? v : v.value,\n })),\n }\n }\n return {\n type: 'string',\n }\n}\n\nfunction createNumberNodeDefintion(\n numberSchemaType: NumberSchemaType,\n): SchemaNumberNode | SchemaUnionNode<SchemaNumberNode> {\n const listOptions = numberSchemaType.options?.list\n if (listOptions && Array.isArray(listOptions)) {\n return {\n type: 'union',\n of: listOptions.map((v) => ({\n type: 'number',\n value: typeof v === 'number' ? v : v.value,\n })),\n }\n }\n return {\n type: 'number',\n }\n}\n\nfunction createReferenceNode(name: string, inArray: boolean = false): SchemaObjectNode {\n const fields: Record<string, SchemaObjectField> = {\n _ref: {\n type: 'objectField',\n name: '_ref',\n value: {\n type: 'string',\n },\n },\n _type: {\n type: 'objectField',\n name: '_type',\n value: {\n type: 'string',\n value: 'reference',\n },\n },\n _weak: {\n type: 'objectField',\n name: '_weak',\n value: {\n type: 'boolean',\n },\n optional: true,\n },\n }\n\n if (inArray) {\n fields._key = {\n type: 'objectField',\n name: '_key',\n value: {\n type: 'string',\n },\n } satisfies SchemaObjectField\n }\n\n return {\n type: 'object',\n fields,\n dereferencesTo: name,\n } satisfies SchemaObjectNode\n}\n\nfunction createReferenceNodeDefintion(\n reference: ReferenceSchemaType,\n): SchemaObjectNode | SchemaUnionNode<SchemaObjectNode> {\n const references = gatherReferenceNames(reference)\n if (references.length === 1) {\n return createReferenceNode(references[0])\n }\n\n return {\n type: 'union',\n of: references.map((name) => ({\n type: 'unionOption',\n name,\n value: createReferenceNode(name),\n })),\n }\n}\n\n// Traverse the reference type tree and gather all the reference names\nfunction gatherReferenceNames(type: ReferenceSchemaType): string[] {\n const allReferences = gatherReferenceTypes(type)\n // Remove duplicates\n return [...new Set(allReferences.map((ref) => ref.name))]\n}\n\nfunction gatherReferenceTypes(type: ReferenceSchemaType): ObjectSchemaType[] {\n const refTo = 'to' in type ? type.to : []\n if ('type' in type && isReferenceType(type.type!)) {\n return [...gatherReferenceTypes(type.type), ...refTo]\n }\n\n return refTo\n}\n\nconst typesMap = new Map<string, Omit<SchemaStringNode, 'name'> | Omit<SchemaBooleanNode, 'name'>>([\n ['text', {type: 'string'}],\n ['url', {type: 'string'}],\n ['datetime', {type: 'string'}],\n ['date', {type: 'string'}],\n ['boolean', {type: 'boolean'}],\n ['email', {type: 'string'}],\n])\n\nexport function extractSchema(workspace: Workspace): SchemaType[] {\n const inlineFields = new Set<SanitySchemaType>()\n const {schema: schemaDef, basePath} = workspace\n\n const sortedSchemaTypeNames = sortByDependencies(schemaDef)\n return sortedSchemaTypeNames\n .map((typeName) => {\n const schemaType = schemaDef.get(typeName)\n if (schemaType === undefined) {\n return undefined\n }\n const base = convertBaseType(schemaType)\n\n if (base === null) {\n return undefined\n }\n\n if (base.type === 'type') {\n inlineFields.add(schemaType)\n }\n\n return base\n })\n .filter((type: SchemaType | undefined): type is SchemaType => type !== undefined)\n\n function extractIcon(schemaType: SanitySchemaType): string | undefined {\n if (!schemaType.icon) return undefined\n return renderToString(<SchemaIcon schemaType={schemaType} />)\n }\n\n function convertBaseType(schemaType: SanitySchemaType): SchemaType | null {\n let typeName: string | undefined\n if (schemaType.type) {\n typeName = schemaType.type.name\n } else if ('jsonType' in schemaType) {\n typeName = schemaType.jsonType\n }\n\n if (typeName === 'document') {\n const object = createObject(schemaType)\n if (object.type === 'unknown') {\n return null\n }\n\n return {\n type: 'document',\n name: schemaType.name,\n title: typeof schemaType.title === 'string' ? schemaType.title : undefined,\n icon: extractIcon(schemaType),\n fields: {\n ...documentDefaultFields(schemaType.name),\n ...object.fields,\n },\n }\n }\n\n const value = convertSchemaType(schemaType)\n if (value.type === 'unknown') {\n return null\n }\n\n if (value.type === 'object') {\n return {\n name: schemaType.name,\n type: 'type',\n value: {\n type: 'object',\n fields: {\n _type: {\n type: 'objectField',\n name: '_type',\n value: {\n type: 'string',\n value: schemaType.name,\n },\n },\n ...value.fields,\n },\n },\n }\n }\n\n return {\n name: schemaType.name,\n title: typeof schemaType.title === 'string' ? schemaType.title : undefined,\n type: 'type',\n value,\n }\n }\n\n function createObject(\n schemaType: ObjectSchemaType | SanitySchemaType,\n ): SchemaObjectNode | SchemaUnknownNode {\n const fields: Record<string, SchemaObjectField> = {}\n\n for (const field of gatherFields(schemaType)) {\n const value = convertSchemaType(field.type)\n if (value === null) {\n continue\n }\n\n fields[field.name] = {\n type: 'objectField',\n name: field.name,\n title: typeof field.type.title === 'string' ? field.type.title : undefined,\n value,\n optional: !isFieldRequired(field),\n }\n }\n\n return {\n type: 'object',\n fields,\n }\n }\n\n function convertSchemaType(schemaType: SanitySchemaType): SchemaNode {\n if (lastType(schemaType)?.name === 'document') {\n return createReferenceNode(schemaType.name)\n }\n\n if (inlineFields.has(schemaType.type!)) {\n return {type: 'inline', name: schemaType.type!.name} satisfies SchemaInlineNode\n }\n\n if (schemaType.type?.type?.name === 'object') {\n return {type: 'inline', name: schemaType.type.name} satisfies SchemaInlineNode\n }\n\n if (isStringType(schemaType)) {\n return createStringNodeDefintion(schemaType)\n }\n\n if (isNumberType(schemaType)) {\n return createNumberNodeDefintion(schemaType)\n }\n\n const mapped = typesMap.get(schemaType.type?.name || '')\n if (mapped) {\n return mapped\n }\n\n if (schemaType.type && typesMap.has(schemaType.type.name)) {\n return typesMap.get(schemaType.type.name)!\n }\n\n // Cross dataset references are not supported\n if (isCrossDatasetReferenceType(schemaType)) {\n return {type: 'unknown'} satisfies SchemaUnknownNode // we don't support cross-dataset references at the moment\n }\n\n if (isReferenceType(schemaType)) {\n return createReferenceNodeDefintion(schemaType)\n }\n\n if (isArrayType(schemaType)) {\n return createArray(schemaType)\n }\n\n if (isObjectType(schemaType)) {\n return createObject(schemaType)\n }\n\n throw new Error(`Type \"${schemaType.name}\" not found`)\n }\n\n function createUnionNodeOptions(\n schemaType: ArraySchemaType,\n of: SchemaUnionOption[],\n ): SchemaUnionNodeOptions | undefined {\n const {options} = schemaType\n if (!options) return undefined\n const opts = {\n ...options,\n }\n if (options.insertMenu) {\n opts.insertMenu = {\n ...options.insertMenu,\n views: (options.insertMenu as InsertMenuOptions).views?.map((view) =>\n view.name === 'grid'\n ? {\n name: 'grid',\n previewImageUrls: view.previewImageUrl\n ? of.reduce(\n (acc, {name}) => {\n const url = view.previewImageUrl?.(name)\n if (!url) return acc\n // If the URL is relative, make it absolute\n try {\n // oxlint-disable-next-line no-new\n new URL(url)\n acc[name] = url\n } catch {\n acc[name] = new URL(\n url,\n `${window.location.origin}${basePath ? `${basePath}/` : ''}`,\n ).toString()\n }\n return acc\n },\n {} as Record<string, string | undefined>,\n )\n : undefined,\n }\n : view,\n ),\n }\n }\n return opts\n }\n\n function createArray(\n arraySchemaType: ArraySchemaType,\n ): SchemaArrayNode | SchemaUnionNode | SchemaNullNode {\n const of: SchemaUnionOption[] = []\n for (const item of arraySchemaType.of) {\n let field = convertSchemaType(item)\n const option = {\n type: 'unionOption',\n icon: extractIcon(item),\n name: item.name,\n title: typeof item.title === 'string' ? item.title : undefined,\n value: field,\n } satisfies SchemaUnionOption\n if (field.type === 'inline') {\n field = {\n type: 'object',\n fields: {\n _key: createKeyField(),\n },\n rest: field,\n } satisfies SchemaObjectNode\n } else if (field.type === 'object') {\n field.rest = {\n type: 'object',\n fields: {\n _key: createKeyField(),\n },\n }\n }\n option.value = field\n of.push(option)\n }\n\n if (of.length === 0) {\n return {type: 'null'}\n }\n\n if (of.length > 1) {\n return {\n type: 'union',\n of,\n options: createUnionNodeOptions(arraySchemaType, of),\n }\n }\n\n const {name, title, value} = of[0]\n return {\n type: 'array',\n of: {\n type: 'arrayItem',\n name,\n title: typeof title === 'string' ? title : undefined,\n value,\n },\n }\n }\n}\n\nfunction createKeyField(): SchemaObjectField<SchemaStringNode> {\n return {\n type: 'objectField',\n name: '_key',\n value: {\n type: 'string',\n },\n }\n}\n","/* eslint-disable max-nested-callbacks */\nimport {type ClientPerspective} from '@sanity/client'\nimport {type UnresolvedPath} from '@sanity/presentation-comlink'\nimport {memo, useEffect} from 'react'\nimport {\n getPublishedId,\n isReleasePerspective,\n RELEASES_STUDIO_CLIENT_OPTIONS,\n useClient,\n useWorkspace,\n} from 'sanity'\n\nimport {API_VERSION} from '../../constants'\nimport {type VisualEditingConnection} from '../../types'\nimport {extractSchema} from './extract'\n\nexport interface PostMessageSchemaProps {\n comlink: VisualEditingConnection\n perspective: ClientPerspective\n}\n\nfunction getDocumentPathArray(paths: UnresolvedPath[]) {\n const documentPathMap = paths.reduce(\n (acc, {id, path}) => {\n if (acc[id]) {\n acc[id].add(path)\n } else {\n acc[id] = new Set<string>([path])\n }\n return acc\n },\n {} as Record<string, Set<string>>,\n )\n\n return Object.entries(documentPathMap)\n}\n\n/**\n * Experimental approach for sending a representation of the workspace schema\n * over postMessage so it can be used to enrich the Visual Editing experience\n */\nfunction PostMessageSchema(props: PostMessageSchemaProps): React.JSX.Element | null {\n const {comlink, perspective} = props\n\n const workspace = useWorkspace()\n\n // Send a representation of the schema to the visual editing context\n useEffect(() => {\n try {\n const schema = extractSchema(workspace)\n /**\n * @deprecated switch to explict schema fetching (using\n * 'visual-editing/schema') at next major\n */\n comlink.post('presentation/schema', {schema})\n\n return comlink.on('visual-editing/schema', () => ({schema}))\n } catch {\n return undefined\n }\n }, [comlink, workspace])\n\n const client = useClient(\n isReleasePerspective(perspective) ? RELEASES_STUDIO_CLIENT_OPTIONS : {apiVersion: API_VERSION},\n )\n\n // Resolve union types from an array of unresolved paths\n useEffect(() => {\n return comlink.on('visual-editing/schema-union-types', async (data) => {\n const documentPathArray = getDocumentPathArray(data.paths)\n const unionTypes = await Promise.all(\n documentPathArray.map(async ([id, paths]) => {\n const arr = Array.from(paths)\n const projection = arr.map((path, i) => `\"${i}\": ${path}[0]._type`).join(',')\n const query = `*[_id == $id][0]{${projection}}`\n // Should implement max 25 concurrent queries here\n const result = await client.fetch(\n query,\n {id: getPublishedId(id)},\n {\n tag: 'presentation-schema',\n perspective,\n },\n )\n const mapped = arr.map((path, i) => ({path: path, type: result[i]}))\n return {id, paths: mapped}\n }),\n )\n\n const newState = new Map()\n unionTypes.forEach((action) => {\n newState.set(action.id, new Map(action.paths.map(({path, type}) => [path, type])))\n })\n return {types: newState}\n })\n }, [comlink, client, perspective])\n\n return null\n}\n\nexport default memo(PostMessageSchema)\n"],"names":["isFieldRequired","field","validation","type","rules","Array","isArray","rule","required","proxy","Proxy","get","target","methodName","_required","isType","typeDef","typeName","name","isObjectType","jsonType","isArrayType","isReferenceType","isCrossDatasetReferenceType","isStringType","isNumberType","lastType","gatherFields","concat","fields","sortByDependencies","compiledSchema","seen","Set","walkDependencies","schemaType","dependencies","has","add","last","schemaTypeName","to","forEach","ref","item","of","dependencyMap","Map","getTypeNames","undefined","set","clear","typeNames","currentlyVisiting","visited","visit","deps","dep","delete","includes","unshift","SchemaIcon","t0","$","_c","Icon","icon","t1","isValidElement","documentDefaultFields","_id","value","_type","_createdAt","_updatedAt","_rev","createStringNodeDefintion","stringSchemaType","listOptions","options","list","map","v","createNumberNodeDefintion","numberSchemaType","createReferenceNode","inArray","_ref","_weak","optional","_key","dereferencesTo","createReferenceNodeDefintion","reference","references","gatherReferenceNames","length","allReferences","gatherReferenceTypes","refTo","typesMap","extractSchema","workspace","inlineFields","schema","schemaDef","basePath","base","convertBaseType","filter","extractIcon","renderToString","object","createObject","title","convertSchemaType","mapped","createArray","Error","createUnionNodeOptions","opts","insertMenu","views","view","previewImageUrls","previewImageUrl","reduce","acc","url","URL","window","location","origin","toString","arraySchemaType","option","createKeyField","rest","push","getDocumentPathArray","paths","documentPathMap","id","path","Object","entries","PostMessageSchema","props","comlink","perspective","useWorkspace","post","on","useEffect","t2","isReleasePerspective","RELEASES_STUDIO_CLIENT_OPTIONS","apiVersion","API_VERSION","client","useClient","t3","t4","data","documentPathArray","unionTypes","Promise","all","t5","arr","from","query","_temp","join","result","fetch","getPublishedId","tag","path_0","i_0","i","newState","action","_temp2","types","path_1","memo"],"mappings":";;;;;;AAcO,SAASA,gBAAgBC,OAA6B;AAC3D,QAAM;AAAA,IAACC;AAAAA,EAAAA,IAAcD,MAAME;AAC3B,MAAI,CAACD;AACH,WAAO;AAET,QAAME,QAAQC,MAAMC,QAAQJ,UAAU,IAAIA,aAAa,CAACA,UAAU;AAClE,aAAWK,QAAQH,OAAO;AACxB,QAAII,WAAW;AAIf,UAAMC,QAAQ,IAAIC,MAChB,IACA;AAAA,MACEC,KAAKA,CAACC,QAAQC,eAAe,OACvBA,eAAe,eACjBL,WAAW,KAENC;AAAAA,IAAAA,CAGb;AASA,QAPI,OAAOF,QAAS,eAClBA,KAAKE,KAAK,GACND,aAKF,OAAOD,QAAS,YAAYA,SAAS,QAAQ,eAAeA,QAC1DA,KAAKO,cAAc;AACrB,aAAO;AAAA,EAGb;AAEA,SAAO;AACT;AAEA,SAASC,OACPC,SACAC,UACS;AACT,MAAId,OAA+Da;AACnE,SAAOb,QAAM;AACX,QAAIA,KAAKe,SAASD,YAAad,KAAKA,QAAQA,KAAKA,KAAKe,SAASD;AAC7D,aAAO;AAGTd,WAAOA,KAAKA;AAAAA,EACd;AACA,SAAO;AACT;AAEO,SAASgB,aAAaH,SAAwD;AACnF,SAAOD,OAAOC,SAAS,QAAQ,KAAKA,QAAQI,aAAa,YAAY,YAAYJ;AACnF;AACO,SAASK,YAAYL,SAAuD;AACjF,SAAOD,O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A;AAAA,IAAAiF,MAAA0C;AAAAA,IAAAtL;AAAAA,EAAAA,IAAA2D;AAAY,SAAK,CAACiF,QAAM5I,IAAI;AAAC;AAlDvF,SAAAyK,MAAA7B,MAAAqC,GAAA;AAAA,SAgCkD,IAAIA,CAAC,MAAMrC,IAAI;AAAW;AA2B5E,IAAA,4BAAe2C,KAAKxC,iBAAiB;"}
|
|
1
|
+
{"version":3,"file":"PostMessageSchema.js","sources":["../../src/presentation/overlays/schema/helpers.ts","../../src/presentation/overlays/schema/SchemaIcon.tsx","../../src/presentation/overlays/schema/extract.tsx","../../src/presentation/overlays/schema/PostMessageSchema.tsx"],"sourcesContent":["import {\n type ArraySchemaType,\n type NumberSchemaType,\n type ObjectField,\n type ObjectFieldType,\n type ObjectSchemaType,\n type ReferenceSchemaType,\n type Rule,\n type Schema as SchemaDef,\n type SchemaType as SanitySchemaType,\n type StringSchemaType,\n} from '@sanity/types'\nimport {type SchemaType} from 'groq-js'\n\nexport function isFieldRequired(field: ObjectField): boolean {\n const {validation} = field.type\n if (!validation) {\n return false\n }\n const rules = Array.isArray(validation) ? validation : [validation]\n for (const rule of rules) {\n let required = false\n\n // hack to check if a field is required. We create a proxy that returns itself when a method is called,\n // if the method is \"required\" we set a flag\n const proxy = new Proxy(\n {},\n {\n get: (target, methodName) => () => {\n if (methodName === 'required') {\n required = true\n }\n return proxy\n },\n },\n ) as Rule\n\n if (typeof rule === 'function') {\n rule(proxy)\n if (required) {\n return true\n }\n }\n\n if (typeof rule === 'object' && rule !== null && '_required' in rule) {\n if (rule._required === 'required') {\n return true\n }\n }\n }\n\n return false\n}\n\nfunction isType(\n typeDef: SanitySchemaType | ObjectField | ObjectFieldType,\n typeName: string,\n): boolean {\n let type: SchemaType | ObjectField | ObjectFieldType | undefined = typeDef\n while (type) {\n if (type.name === typeName || (type.type && type.type.name === typeName)) {\n return true\n }\n\n type = type.type\n }\n return false\n}\n\nexport function isObjectType(typeDef: SanitySchemaType): typeDef is ObjectSchemaType {\n return isType(typeDef, 'object') || typeDef.jsonType === 'object' || 'fields' in typeDef\n}\nexport function isArrayType(typeDef: SanitySchemaType): typeDef is ArraySchemaType {\n return isType(typeDef, 'array')\n}\nexport function isReferenceType(typeDef: SanitySchemaType): typeDef is ReferenceSchemaType {\n return isType(typeDef, 'reference')\n}\n// @todo\nexport function isCrossDatasetReferenceType(typeDef: SanitySchemaType): boolean {\n return isType(typeDef, 'crossDatasetReference')\n}\nexport function isStringType(typeDef: SanitySchemaType): typeDef is StringSchemaType {\n return isType(typeDef, 'string')\n}\nexport function isNumberType(typeDef: SanitySchemaType): typeDef is NumberSchemaType {\n return isType(typeDef, 'number')\n}\n\n// Traverse the type tree and return the \"last\" type, ie deepest type in the tree\nexport function lastType(typeDef: SanitySchemaType): SanitySchemaType | undefined {\n let type: SchemaType | ObjectField | ObjectFieldType | undefined = typeDef\n while (type) {\n if (!type.type) {\n return type\n }\n type = type.type\n }\n\n return undefined\n}\n\n// Traverse the type tree and gather all the fields\nexport function gatherFields(type: SanitySchemaType | ObjectSchemaType): ObjectField[] {\n if ('fields' in type) {\n return type.type ? gatherFields(type.type).concat(type.fields) : type.fields\n }\n\n return []\n}\n\n// Sorts the types by their dependencies by using a topological sort depth-first algorithm.\nexport function sortByDependencies(compiledSchema: SchemaDef): string[] {\n const seen = new Set<SanitySchemaType>()\n\n // Walks the dependencies of a schema type and adds them to the dependencies set\n function walkDependencies(\n schemaType: SanitySchemaType,\n dependencies: Set<SanitySchemaType>,\n ): void {\n if (seen.has(schemaType)) {\n return\n }\n seen.add(schemaType)\n\n if ('fields' in schemaType) {\n for (const field of gatherFields(schemaType)) {\n const last = lastType(field.type)\n if (last!.name === 'document') {\n dependencies.add(last!)\n continue\n }\n\n let schemaTypeName: string | undefined\n if (schemaType.type!.type) {\n schemaTypeName = field.type.type!.name\n } else if ('jsonType' in schemaType.type!) {\n schemaTypeName = field.type.jsonType\n }\n\n if (schemaTypeName === 'object' || schemaTypeName === 'block') {\n if (isReferenceType(field.type)) {\n field.type.to.forEach((ref) => dependencies.add(ref.type!))\n } else {\n dependencies.add(field.type)\n }\n }\n walkDependencies(field.type, dependencies)\n }\n } else if ('of' in schemaType) {\n for (const item of schemaType.of) {\n walkDependencies(item, dependencies)\n }\n }\n }\n const dependencyMap = new Map<SanitySchemaType, Set<SanitySchemaType>>()\n compiledSchema.getTypeNames().forEach((typeName) => {\n const schemaType = compiledSchema.get(typeName)\n if (schemaType === undefined || schemaType.type === null) {\n return\n }\n const dependencies = new Set<SanitySchemaType>()\n\n walkDependencies(schemaType, dependencies)\n dependencyMap.set(schemaType, dependencies)\n seen.clear() // Clear the seen set for the next type\n })\n\n // Sorts the types by their dependencies\n const typeNames: string[] = []\n // holds a temporary mark for types that are currently being visited, to detect cyclic dependencies\n const currentlyVisiting = new Set<SanitySchemaType>()\n\n // holds a permanent mark for types that have been already visited\n const visited = new Set<SanitySchemaType>()\n\n // visit implements a depth-first search\n function visit(type: SanitySchemaType) {\n if (visited.has(type)) {\n return\n }\n // If we find a type that is already in the temporary mark, we have a cyclic dependency.\n if (currentlyVisiting.has(type)) {\n return\n }\n // mark this as a temporary mark, meaning it's being visited\n currentlyVisiting.add(type)\n const deps = dependencyMap.get(type)\n if (deps !== undefined) {\n deps.forEach((dep) => visit(dep))\n }\n currentlyVisiting.delete(type)\n visited.add(type)\n\n if (!typeNames.includes(type.name)) {\n typeNames.unshift(type.name)\n }\n }\n // Visit all types in the dependency map\n for (const [type] of dependencyMap) {\n visit(type)\n }\n\n return typeNames\n}\n","import {type SchemaType as SanitySchemaType} from '@sanity/types'\nimport {isValidElement} from 'react'\n\nexport function SchemaIcon({schemaType}: {schemaType: SanitySchemaType}): React.JSX.Element | null {\n const Icon = schemaType.icon\n\n return Icon ? isValidElement(Icon) ? Icon : <Icon /> : null\n}\n","import {\n type InsertMenuOptions,\n type SchemaArrayNode,\n type SchemaBooleanNode,\n type SchemaInlineNode,\n type SchemaNode,\n type SchemaNullNode,\n type SchemaNumberNode,\n type SchemaObjectField,\n type SchemaObjectNode,\n type SchemaStringNode,\n type SchemaType,\n type SchemaUnionNode,\n type SchemaUnionNodeOptions,\n type SchemaUnionOption,\n type SchemaUnknownNode,\n} from '@sanity/presentation-comlink'\nimport {\n type ArraySchemaType,\n type NumberSchemaType,\n type ObjectSchemaType,\n type ReferenceSchemaType,\n type SchemaType as SanitySchemaType,\n type StringSchemaType,\n} from '@sanity/types'\nimport {renderToString} from 'react-dom/server'\nimport {type Workspace} from 'sanity'\n\nimport {\n gatherFields,\n isArrayType,\n isCrossDatasetReferenceType,\n isFieldRequired,\n isNumberType,\n isObjectType,\n isReferenceType,\n isStringType,\n lastType,\n sortByDependencies,\n} from './helpers'\nimport {SchemaIcon} from './SchemaIcon'\n\nconst documentDefaultFields = (typeName: string): Record<string, SchemaObjectField> => ({\n _id: {\n type: 'objectField',\n name: '_id',\n value: {\n type: 'string',\n },\n },\n _type: {\n type: 'objectField',\n name: '_type',\n value: {\n type: 'string',\n value: typeName,\n },\n },\n _createdAt: {\n type: 'objectField',\n name: '_createdAt',\n value: {\n type: 'string',\n },\n },\n _updatedAt: {\n type: 'objectField',\n name: '_updatedAt',\n value: {\n type: 'string',\n },\n },\n _rev: {\n type: 'objectField',\n name: '_rev',\n value: {\n type: 'string',\n },\n },\n})\n\nfunction createStringNodeDefintion(\n stringSchemaType: StringSchemaType,\n): SchemaStringNode | SchemaUnionNode<SchemaStringNode> {\n const listOptions = stringSchemaType.options?.list\n if (listOptions && Array.isArray(listOptions)) {\n return {\n type: 'union',\n of: listOptions.map((v) => ({\n type: 'string',\n value: typeof v === 'string' ? v : v.value,\n })),\n }\n }\n return {\n type: 'string',\n }\n}\n\nfunction createNumberNodeDefintion(\n numberSchemaType: NumberSchemaType,\n): SchemaNumberNode | SchemaUnionNode<SchemaNumberNode> {\n const listOptions = numberSchemaType.options?.list\n if (listOptions && Array.isArray(listOptions)) {\n return {\n type: 'union',\n of: listOptions.map((v) => ({\n type: 'number',\n value: typeof v === 'number' ? v : v.value,\n })),\n }\n }\n return {\n type: 'number',\n }\n}\n\nfunction createReferenceNode(name: string, inArray: boolean = false): SchemaObjectNode {\n const fields: Record<string, SchemaObjectField> = {\n _ref: {\n type: 'objectField',\n name: '_ref',\n value: {\n type: 'string',\n },\n },\n _type: {\n type: 'objectField',\n name: '_type',\n value: {\n type: 'string',\n value: 'reference',\n },\n },\n _weak: {\n type: 'objectField',\n name: '_weak',\n value: {\n type: 'boolean',\n },\n optional: true,\n },\n }\n\n if (inArray) {\n fields._key = {\n type: 'objectField',\n name: '_key',\n value: {\n type: 'string',\n },\n } satisfies SchemaObjectField\n }\n\n return {\n type: 'object',\n fields,\n dereferencesTo: name,\n } satisfies SchemaObjectNode\n}\n\nfunction createReferenceNodeDefintion(\n reference: ReferenceSchemaType,\n): SchemaObjectNode | SchemaUnionNode<SchemaObjectNode> {\n const references = gatherReferenceNames(reference)\n if (references.length === 1) {\n return createReferenceNode(references[0])\n }\n\n return {\n type: 'union',\n of: references.map((name) => ({\n type: 'unionOption',\n name,\n value: createReferenceNode(name),\n })),\n }\n}\n\n// Traverse the reference type tree and gather all the reference names\nfunction gatherReferenceNames(type: ReferenceSchemaType): string[] {\n const allReferences = gatherReferenceTypes(type)\n // Remove duplicates\n return [...new Set(allReferences.map((ref) => ref.name))]\n}\n\nfunction gatherReferenceTypes(type: ReferenceSchemaType): ObjectSchemaType[] {\n const refTo = 'to' in type ? type.to : []\n if ('type' in type && isReferenceType(type.type!)) {\n return [...gatherReferenceTypes(type.type), ...refTo]\n }\n\n return refTo\n}\n\nconst typesMap = new Map<string, Omit<SchemaStringNode, 'name'> | Omit<SchemaBooleanNode, 'name'>>([\n ['text', {type: 'string'}],\n ['url', {type: 'string'}],\n ['datetime', {type: 'string'}],\n ['date', {type: 'string'}],\n ['boolean', {type: 'boolean'}],\n ['email', {type: 'string'}],\n])\n\nexport function extractSchema(workspace: Workspace): SchemaType[] {\n const inlineFields = new Set<SanitySchemaType>()\n const {schema: schemaDef, basePath} = workspace\n\n const sortedSchemaTypeNames = sortByDependencies(schemaDef)\n return sortedSchemaTypeNames\n .map((typeName) => {\n const schemaType = schemaDef.get(typeName)\n if (schemaType === undefined) {\n return undefined\n }\n const base = convertBaseType(schemaType)\n\n if (base === null) {\n return undefined\n }\n\n if (base.type === 'type') {\n inlineFields.add(schemaType)\n }\n\n return base\n })\n .filter((type: SchemaType | undefined): type is SchemaType => type !== undefined)\n\n function extractIcon(schemaType: SanitySchemaType): string | undefined {\n if (!schemaType.icon) return undefined\n return renderToString(<SchemaIcon schemaType={schemaType} />)\n }\n\n function convertBaseType(schemaType: SanitySchemaType): SchemaType | null {\n let typeName: string | undefined\n if (schemaType.type) {\n typeName = schemaType.type.name\n } else if ('jsonType' in schemaType) {\n typeName = schemaType.jsonType\n }\n\n if (typeName === 'document') {\n const object = createObject(schemaType)\n if (object.type === 'unknown') {\n return null\n }\n\n return {\n type: 'document',\n name: schemaType.name,\n title: typeof schemaType.title === 'string' ? schemaType.title : undefined,\n icon: extractIcon(schemaType),\n fields: {\n ...documentDefaultFields(schemaType.name),\n ...object.fields,\n },\n }\n }\n\n const value = convertSchemaType(schemaType)\n if (value.type === 'unknown') {\n return null\n }\n\n if (value.type === 'object') {\n return {\n name: schemaType.name,\n type: 'type',\n value: {\n type: 'object',\n fields: {\n _type: {\n type: 'objectField',\n name: '_type',\n value: {\n type: 'string',\n value: schemaType.name,\n },\n },\n ...value.fields,\n },\n },\n }\n }\n\n return {\n name: schemaType.name,\n title: typeof schemaType.title === 'string' ? schemaType.title : undefined,\n type: 'type',\n value,\n }\n }\n\n function createObject(\n schemaType: ObjectSchemaType | SanitySchemaType,\n ): SchemaObjectNode | SchemaUnknownNode {\n const fields: Record<string, SchemaObjectField> = {}\n\n for (const field of gatherFields(schemaType)) {\n const value = convertSchemaType(field.type)\n if (value === null) {\n continue\n }\n\n fields[field.name] = {\n type: 'objectField',\n name: field.name,\n title: typeof field.type.title === 'string' ? field.type.title : undefined,\n value,\n optional: !isFieldRequired(field),\n }\n }\n\n return {\n type: 'object',\n fields,\n }\n }\n\n function convertSchemaType(schemaType: SanitySchemaType): SchemaNode {\n if (lastType(schemaType)?.name === 'document') {\n return createReferenceNode(schemaType.name)\n }\n\n if (inlineFields.has(schemaType.type!)) {\n return {type: 'inline', name: schemaType.type!.name} satisfies SchemaInlineNode\n }\n\n if (schemaType.type?.type?.name === 'object') {\n return {type: 'inline', name: schemaType.type.name} satisfies SchemaInlineNode\n }\n\n if (isStringType(schemaType)) {\n return createStringNodeDefintion(schemaType)\n }\n\n if (isNumberType(schemaType)) {\n return createNumberNodeDefintion(schemaType)\n }\n\n const mapped = typesMap.get(schemaType.type?.name || '')\n if (mapped) {\n return mapped\n }\n\n if (schemaType.type && typesMap.has(schemaType.type.name)) {\n return typesMap.get(schemaType.type.name)!\n }\n\n // Cross dataset references are not supported\n if (isCrossDatasetReferenceType(schemaType)) {\n return {type: 'unknown'} satisfies SchemaUnknownNode // we don't support cross-dataset references at the moment\n }\n\n if (isReferenceType(schemaType)) {\n return createReferenceNodeDefintion(schemaType)\n }\n\n if (isArrayType(schemaType)) {\n return createArray(schemaType)\n }\n\n if (isObjectType(schemaType)) {\n return createObject(schemaType)\n }\n\n throw new Error(`Type \"${schemaType.name}\" not found`)\n }\n\n function createUnionNodeOptions(\n schemaType: ArraySchemaType,\n of: SchemaUnionOption[],\n ): SchemaUnionNodeOptions | undefined {\n const {options} = schemaType\n if (!options) return undefined\n const opts = {\n ...options,\n }\n if (options.insertMenu) {\n opts.insertMenu = {\n ...options.insertMenu,\n views: (options.insertMenu as InsertMenuOptions).views?.map((view) =>\n view.name === 'grid'\n ? {\n name: 'grid',\n previewImageUrls: view.previewImageUrl\n ? of.reduce(\n (acc, {name}) => {\n const url = view.previewImageUrl?.(name)\n if (!url) return acc\n // If the URL is relative, make it absolute\n try {\n // oxlint-disable-next-line no-new\n new URL(url)\n acc[name] = url\n } catch {\n acc[name] = new URL(\n url,\n `${window.location.origin}${basePath ? `${basePath}/` : ''}`,\n ).toString()\n }\n return acc\n },\n {} as Record<string, string | undefined>,\n )\n : undefined,\n }\n : view,\n ),\n }\n }\n return opts\n }\n\n function createArray(\n arraySchemaType: ArraySchemaType,\n ): SchemaArrayNode | SchemaUnionNode | SchemaNullNode {\n const of: SchemaUnionOption[] = []\n for (const item of arraySchemaType.of) {\n let field = convertSchemaType(item)\n const option = {\n type: 'unionOption',\n icon: extractIcon(item),\n name: item.name,\n title: typeof item.title === 'string' ? item.title : undefined,\n value: field,\n } satisfies SchemaUnionOption\n if (field.type === 'inline') {\n field = {\n type: 'object',\n fields: {\n _key: createKeyField(),\n },\n rest: field,\n } satisfies SchemaObjectNode\n } else if (field.type === 'object') {\n field.rest = {\n type: 'object',\n fields: {\n _key: createKeyField(),\n },\n }\n }\n option.value = field\n of.push(option)\n }\n\n if (of.length === 0) {\n return {type: 'null'}\n }\n\n if (of.length > 1) {\n return {\n type: 'union',\n of,\n options: createUnionNodeOptions(arraySchemaType, of),\n }\n }\n\n const {name, title, value} = of[0]\n return {\n type: 'array',\n of: {\n type: 'arrayItem',\n name,\n title: typeof title === 'string' ? title : undefined,\n value,\n },\n }\n }\n}\n\nfunction createKeyField(): SchemaObjectField<SchemaStringNode> {\n return {\n type: 'objectField',\n name: '_key',\n value: {\n type: 'string',\n },\n }\n}\n","/* eslint-disable max-nested-callbacks */\nimport {type ClientPerspective} from '@sanity/client'\nimport {type ResolvedSchemaTypeMap, type UnresolvedPath} from '@sanity/presentation-comlink'\nimport {memo, useEffect} from 'react'\nimport {\n getPublishedId,\n isReleasePerspective,\n RELEASES_STUDIO_CLIENT_OPTIONS,\n useClient,\n useWorkspace,\n} from 'sanity'\n\nimport {API_VERSION} from '../../constants'\nimport {type VisualEditingConnection} from '../../types'\nimport {extractSchema} from './extract'\n\nexport interface PostMessageSchemaProps {\n comlink: VisualEditingConnection\n perspective: ClientPerspective\n}\n\nfunction getDocumentPathArray(paths: UnresolvedPath[]) {\n const documentPathMap = paths.reduce(\n (acc, {id, path}) => {\n if (acc[id]) {\n acc[id].add(path)\n } else {\n acc[id] = new Set<string>([path])\n }\n return acc\n },\n {} as Record<string, Set<string>>,\n )\n\n return Object.entries(documentPathMap)\n}\n\n/**\n * Experimental approach for sending a representation of the workspace schema\n * over postMessage so it can be used to enrich the Visual Editing experience\n */\nfunction PostMessageSchema(props: PostMessageSchemaProps): React.JSX.Element | null {\n const {comlink, perspective} = props\n\n const workspace = useWorkspace()\n\n // Send a representation of the schema to the visual editing context\n useEffect(() => {\n try {\n const schema = extractSchema(workspace)\n /**\n * @deprecated switch to explict schema fetching (using\n * 'visual-editing/schema') at next major\n */\n comlink.post('presentation/schema', {schema})\n\n return comlink.on('visual-editing/schema', () => ({schema}))\n } catch {\n return undefined\n }\n }, [comlink, workspace])\n\n const client = useClient(\n isReleasePerspective(perspective) ? RELEASES_STUDIO_CLIENT_OPTIONS : {apiVersion: API_VERSION},\n )\n\n // Resolve union types from an array of unresolved paths\n useEffect(() => {\n return comlink.on('visual-editing/schema-union-types', async (data) => {\n const documentPathArray = getDocumentPathArray(data.paths)\n const unionTypes = await Promise.all(\n documentPathArray.map(async ([id, paths]) => {\n const arr = Array.from(paths)\n const projection = arr.map((path, i) => `\"${i}\": ${path}[0]._type`).join(',')\n const query = `*[_id == $id][0]{${projection}}`\n // Should implement max 25 concurrent queries here\n const result = await client.fetch<Record<number, string | null> | null>(\n query,\n {id: getPublishedId(id)},\n {\n tag: 'presentation-schema',\n perspective,\n },\n )\n // `client.fetch` returns `null` when no document matches the active perspective,\n // and individual projection entries are `null` when the document exists but the\n // path doesn't resolve. Drop those entries so we only emit fully resolved types.\n const mapped = arr\n .map((path, i) =>\n typeof result?.[i] === 'string' ? {path: path, type: result[i]} : null,\n )\n .filter((item) => item !== null)\n return {id, paths: mapped}\n }),\n )\n\n const newState: ResolvedSchemaTypeMap = new Map()\n unionTypes.forEach((action) => {\n newState.set(action.id, new Map(action.paths.map(({path, type}) => [path, type])))\n })\n return {types: newState}\n })\n }, [comlink, client, perspective])\n\n return null\n}\n\nexport default memo(PostMessageSchema)\n"],"names":["isFieldRequired","field","validation","type","rules","Array","isArray","rule","required","proxy","Proxy","get","target","methodName","_required","isType","typeDef","typeName","name","isObjectType","jsonType","isArrayType","isReferenceType","isCrossDatasetReferenceType","isStringType","isNumberType","lastType","gatherFields","concat","fields","sortByDependencies","compiledSchema","seen","Set","walkDependencies","schemaType","dependencies","has","add","last","schemaTypeName","to","forEach","ref","item","of","dependencyMap","Map","getTypeNames","undefined","set","clear","typeNames","currentlyVisiting","visited","visit","deps","dep","delete","includes","unshift","SchemaIcon","t0","$","_c","Icon","icon","t1","isValidElement","documentDefaultFields","_id","value","_type","_createdAt","_updatedAt","_rev","createStringNodeDefintion","stringSchemaType","listOptions","options","list","map","v","createNumberNodeDefintion","numberSchemaType","createReferenceNode","inArray","_ref","_weak","optional","_key","dereferencesTo","createReferenceNodeDefintion","reference","references","gatherReferenceNames","length","allReferences","gatherReferenceTypes","refTo","typesMap","extractSchema","workspace","inlineFields","schema","schemaDef","basePath","base","convertBaseType","filter","extractIcon","renderToString","object","createObject","title","convertSchemaType","mapped","createArray","Error","createUnionNodeOptions","opts","insertMenu","views","view","previewImageUrls","previewImageUrl","reduce","acc","url","URL","window","location","origin","toString","arraySchemaType","option","createKeyField","rest","push","getDocumentPathArray","paths","documentPathMap","id","path","Object","entries","PostMessageSchema","props","comlink","perspective","useWorkspace","post","on","useEffect","t2","isReleasePerspective","RELEASES_STUDIO_CLIENT_OPTIONS","apiVersion","API_VERSION","client","useClient","t3","t4","data","documentPathArray","unionTypes","Promise","all","t5","arr","from","query","_temp","join","result","fetch","getPublishedId","tag","path_0","i_0","i","_temp2","newState","action","_temp3","types","path_1","memo"],"mappings":";;;;;;AAcO,SAASA,gBAAgBC,OAA6B;AAC3D,QAAM;AAAA,IAACC;AAAAA,EAAAA,IAAcD,MAAME;AAC3B,MAAI,CAACD;AACH,WAAO;AAET,QAAME,QAAQC,MAAMC,QAAQJ,UAAU,IAAI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,QAAAC,QACH,OAAOL,SAASM,GAAC,KAAM,WAAvB;AAAA,QAAArC,MAAyCA;AAAAA,QAAI5I,MAAQ2K,OAAOM,GAAC;AAAA,MAAA,IAA7D,IACF,EAACvE,OACOwE,MAAuB;AAAC,aAC3B;AAAA,QAAAvC;AAAAA,QAAAF,OAAYxB;AAAAA,MAAAA;AAAAA,IAAO,CAC3B,CACH,GAEAkE,+BAA4CvI,IAAAA;AAC5CsH,WAAAA,WAAU3H,QAAS6I,CAAAA,WAAA;AACjBD,eAAQpI,IAAKqI,OAAMzC,IAAK,IAAI/F,IAAIwI,OAAM3C,MAAM3D,IAAKuG,MAA8B,CAAC,CAAC;AAAA,IAAC,CACnF,GACM;AAAA,MAAAC,OAAQH;AAAAA,IAAAA;AAAAA,EAAS,CACzB,GACApB,MAACd,SAASW,QAAQV,WAAW,GAACtF,OAAAgG,QAAAhG,OAAAqF,SAAArF,OAAAsF,aAAAtF,OAAAkG,IAAAlG,QAAAmG,OAAAD,KAAAlG,EAAA,CAAA,GAAAmG,KAAAnG,EAAA,EAAA,IAnCjC0F,UAAUQ,IAmCPC,EAA8B,GAE1B;AAAI;AA/Db,SAAAsB,OAAA1H,IAAA;AAyD0D,QAAA;AAAA,IAAAiF,MAAA2C;AAAAA,IAAAvL;AAAAA,EAAAA,IAAA2D;AAAY,SAAK,CAACiF,QAAM5I,IAAI;AAAC;AAzDvF,SAAAkL,OAAAzI,MAAA;AAAA,SAkD8BA,SAAS;AAAI;AAlD3C,SAAAgI,MAAA7B,MAAAqC,GAAA;AAAA,SAgCkD,IAAIA,CAAC,MAAMrC,IAAI;AAAW;AAkC5E,IAAA,4BAAe4C,KAAKzC,iBAAiB;"}
|
|
@@ -29,6 +29,7 @@ import { disablePreviewAccessSharing, enablePreviewAccessSharing } from "@sanity
|
|
|
29
29
|
import { validateApiPerspective } from "@sanity/client";
|
|
30
30
|
import isEqual from "fast-deep-equal";
|
|
31
31
|
import { match } from "path-to-regexp";
|
|
32
|
+
import { isAgentBundleName } from "./createAgentBundlesStore.js";
|
|
32
33
|
import { createPreviewSecret } from "@sanity/preview-url-secret/create-secret";
|
|
33
34
|
import { uuid } from "@sanity/uuid";
|
|
34
35
|
import { throwError } from "rxjs";
|
|
@@ -1840,14 +1841,15 @@ const MotionFlex = motion.create(Flex), Preview = memo(forwardRef(function(props
|
|
|
1840
1841
|
viewport,
|
|
1841
1842
|
vercelProtectionBypass,
|
|
1842
1843
|
presentationRef,
|
|
1843
|
-
previewUrlRef
|
|
1844
|
+
previewUrlRef,
|
|
1845
|
+
handlesPerspectiveChange
|
|
1844
1846
|
} = props, [stablePerspective, setStablePerspective] = useState(null), urlPerspective = encodeStudioPerspective(stablePerspective === null ? perspective : stablePerspective), previewUrl = useMemo(() => {
|
|
1845
1847
|
const url = new URL(initialUrl);
|
|
1846
1848
|
return url.searchParams.set(urlSearchParamPreviewPerspective, urlPerspective), (vercelProtectionBypass || url.searchParams.get(urlSearchParamVercelProtectionBypass)) && url.searchParams.set(urlSearchParamVercelSetBypassCookie, "samesitenone"), vercelProtectionBypass && !url.searchParams.get(urlSearchParamVercelProtectionBypass) && url.searchParams.set(urlSearchParamVercelProtectionBypass, vercelProtectionBypass), url;
|
|
1847
1849
|
}, [initialUrl, urlPerspective, vercelProtectionBypass]);
|
|
1848
1850
|
useEffect(() => {
|
|
1849
|
-
|
|
1850
|
-
}, [
|
|
1851
|
+
handlesPerspectiveChange && setStablePerspective((prev) => prev === null ? perspective : prev);
|
|
1852
|
+
}, [handlesPerspectiveChange, perspective]);
|
|
1851
1853
|
const {
|
|
1852
1854
|
t
|
|
1853
1855
|
} = useTranslation(presentationLocaleNamespace), {
|
|
@@ -2517,15 +2519,21 @@ function _temp2$4(unsub) {
|
|
|
2517
2519
|
return unsub();
|
|
2518
2520
|
}
|
|
2519
2521
|
function usePresentationPerspective(t0) {
|
|
2520
|
-
const $ = c(
|
|
2522
|
+
const $ = c(3), {
|
|
2521
2523
|
scheduledDraft
|
|
2522
2524
|
} = t0, {
|
|
2523
2525
|
selectedPerspectiveName: t1,
|
|
2524
2526
|
selectedReleaseId,
|
|
2525
2527
|
perspectiveStack
|
|
2526
2528
|
} = usePerspective(), selectedPerspectiveName = t1 === void 0 ? "drafts" : t1;
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
+
if (selectedReleaseId || scheduledDraft || isAgentBundleName(selectedPerspectiveName)) {
|
|
2530
|
+
if (scheduledDraft) {
|
|
2531
|
+
let t2;
|
|
2532
|
+
return $[0] !== perspectiveStack || $[1] !== scheduledDraft ? (t2 = [scheduledDraft, ...perspectiveStack], $[0] = perspectiveStack, $[1] = scheduledDraft, $[2] = t2) : t2 = $[2], t2;
|
|
2533
|
+
}
|
|
2534
|
+
return perspectiveStack;
|
|
2535
|
+
}
|
|
2536
|
+
return selectedPerspectiveName === "published" ? "published" : "drafts";
|
|
2529
2537
|
}
|
|
2530
2538
|
function useStatus() {
|
|
2531
2539
|
const $ = c(4);
|
|
@@ -2590,7 +2598,7 @@ const LiveQueries = lazy(() => import("./LiveQueries.js")), PostMessageDocuments
|
|
|
2590
2598
|
componentId: "sc-1f7om43-0"
|
|
2591
2599
|
})`overflow-x:auto;`;
|
|
2592
2600
|
function PresentationTool(props) {
|
|
2593
|
-
const $ = c(
|
|
2601
|
+
const $ = c(197), {
|
|
2594
2602
|
canToggleSharePreviewAccess,
|
|
2595
2603
|
canUseSharedPreviewAccess,
|
|
2596
2604
|
tool,
|
|
@@ -2652,7 +2660,7 @@ function PresentationTool(props) {
|
|
|
2652
2660
|
resolvers: t6,
|
|
2653
2661
|
perspective
|
|
2654
2662
|
}, $[14] = navigate, $[15] = navigationHistory, $[16] = params.preview, $[17] = perspective, $[18] = t6, $[19] = targetOrigin, $[20] = t7) : t7 = $[20];
|
|
2655
|
-
const mainDocumentState = useMainDocument(t7), [overlaysConnection, setOverlaysConnection] = useStatus(), [loadersConnection, setLoadersConnection] = useStatus(), [previewKitConnection, setPreviewKitConnection] = useStatus(), {
|
|
2663
|
+
const mainDocumentState = useMainDocument(t7), [overlaysConnection, setOverlaysConnection] = useStatus(), [loadersConnection, setLoadersConnection] = useStatus(), [previewKitConnection, setPreviewKitConnection] = useStatus(), [_handlesPerspectiveChange, setHandlesPerspectiveChange] = useState(!1), handlesPerspectiveChange = _handlesPerspectiveChange || loadersConnection === "connected", {
|
|
2656
2664
|
open: handleOpenPopup
|
|
2657
2665
|
} = usePopups(controller), isLoading = useSelector(presentationRef, _temp2$2);
|
|
2658
2666
|
let t8, t9;
|
|
@@ -2905,45 +2913,45 @@ function PresentationTool(props) {
|
|
|
2905
2913
|
$[93] !== PresentationNavigator ? (t31 = /* @__PURE__ */ jsx(PresentationNavigator, {}), $[93] = PresentationNavigator, $[94] = t31) : t31 = $[94];
|
|
2906
2914
|
const t32 = navigatorEnabled ? 50 : 75;
|
|
2907
2915
|
let t33;
|
|
2908
|
-
$[95] !== canSharePreviewAccess || $[96] !== canToggleSharePreviewAccess || $[97] !== canUseSharedPreviewAccess || $[98] !== handleOpenPopup || $[99] !== handlePreviewPath || $[100] !== handleRefresh || $[101] !==
|
|
2916
|
+
$[95] !== canSharePreviewAccess || $[96] !== canToggleSharePreviewAccess || $[97] !== canUseSharedPreviewAccess || $[98] !== handleOpenPopup || $[99] !== handlePreviewPath || $[100] !== handleRefresh || $[101] !== handlesPerspectiveChange || $[102] !== initialPreviewUrl || $[103] !== loadersConnection || $[104] !== navigatorEnabled || $[105] !== overlaysConnection || $[106] !== params.preview || $[107] !== perspective || $[108] !== presentationRef || $[109] !== previewUrlRef || $[110] !== setViewport || $[111] !== targetOrigin || $[112] !== toggleNavigator || $[113] !== toggleOverlay || $[114] !== unstable_header || $[115] !== vercelProtectionBypass || $[116] !== viewport ? (t33 = /* @__PURE__ */ jsx(Preview, { canSharePreviewAccess, canToggleSharePreviewAccess, canUseSharedPreviewAccess, header: unstable_header, initialUrl: initialPreviewUrl, loadersConnection, navigatorEnabled, onPathChange: handlePreviewPath, onRefresh: handleRefresh, openPopup: handleOpenPopup, overlaysConnection, previewUrl: params.preview, perspective, ref: iframeRef, setViewport, targetOrigin, toggleNavigator, toggleOverlay, viewport, vercelProtectionBypass, presentationRef, previewUrlRef, handlesPerspectiveChange }, targetOrigin), $[95] = canSharePreviewAccess, $[96] = canToggleSharePreviewAccess, $[97] = canUseSharedPreviewAccess, $[98] = handleOpenPopup, $[99] = handlePreviewPath, $[100] = handleRefresh, $[101] = handlesPerspectiveChange, $[102] = initialPreviewUrl, $[103] = loadersConnection, $[104] = navigatorEnabled, $[105] = overlaysConnection, $[106] = params.preview, $[107] = perspective, $[108] = presentationRef, $[109] = previewUrlRef, $[110] = setViewport, $[111] = targetOrigin, $[112] = toggleNavigator, $[113] = toggleOverlay, $[114] = unstable_header, $[115] = vercelProtectionBypass, $[116] = viewport, $[117] = t33) : t33 = $[117];
|
|
2909
2917
|
let t34;
|
|
2910
|
-
$[
|
|
2918
|
+
$[118] !== boundaryElement || $[119] !== t33 ? (t34 = /* @__PURE__ */ jsx(Flex, { direction: "column", flex: 1, height: "fill", ref: setBoundaryElement, children: /* @__PURE__ */ jsx(BoundaryElementProvider, { element: boundaryElement, children: t33 }) }), $[118] = boundaryElement, $[119] = t33, $[120] = t34) : t34 = $[120];
|
|
2911
2919
|
let t35;
|
|
2912
|
-
$[
|
|
2920
|
+
$[121] !== t32 || $[122] !== t34 ? (t35 = /* @__PURE__ */ jsx(Panel, { id: "preview", minWidth: 325, defaultSize: t32, order: 3, children: t34 }), $[121] = t32, $[122] = t34, $[123] = t35) : t35 = $[123];
|
|
2913
2921
|
let t36;
|
|
2914
|
-
$[
|
|
2922
|
+
$[124] !== documentsOnPage || $[125] !== getCommentIntent || $[126] !== handleEditReference || $[127] !== handleFocusPath || $[128] !== handleStructureParams || $[129] !== mainDocumentState || $[130] !== params.id || $[131] !== params.type || $[132] !== searchParams || $[133] !== structureParams ? (t36 = /* @__PURE__ */ jsx(PresentationContent, { documentId: params.id, documentsOnPage, documentType: params.type, getCommentIntent, mainDocumentState, onEditReference: handleEditReference, onFocusPath: handleFocusPath, onStructureParams: handleStructureParams, searchParams, setDisplayedDocument, structureParams }), $[124] = documentsOnPage, $[125] = getCommentIntent, $[126] = handleEditReference, $[127] = handleFocusPath, $[128] = handleStructureParams, $[129] = mainDocumentState, $[130] = params.id, $[131] = params.type, $[132] = searchParams, $[133] = structureParams, $[134] = t36) : t36 = $[134];
|
|
2915
2923
|
let t37;
|
|
2916
|
-
$[
|
|
2924
|
+
$[135] !== t31 || $[136] !== t35 || $[137] !== t36 ? (t37 = /* @__PURE__ */ jsx(Container, { "data-testid": "presentation-root", height: "fill", children: /* @__PURE__ */ jsxs(Panels, { children: [
|
|
2917
2925
|
t31,
|
|
2918
2926
|
t35,
|
|
2919
2927
|
t36
|
|
2920
|
-
] }) }), $[
|
|
2928
|
+
] }) }), $[135] = t31, $[136] = t35, $[137] = t36, $[138] = t37) : t37 = $[138];
|
|
2921
2929
|
let t38;
|
|
2922
|
-
$[
|
|
2930
|
+
$[139] !== t37 || $[140] !== visualEditingComlink ? (t38 = /* @__PURE__ */ jsx(SharedStateProvider, { comlink: visualEditingComlink, children: t37 }), $[139] = t37, $[140] = visualEditingComlink, $[141] = t38) : t38 = $[141];
|
|
2923
2931
|
let t39;
|
|
2924
|
-
$[
|
|
2932
|
+
$[142] !== params || $[143] !== t38 ? (t39 = /* @__PURE__ */ jsx(PresentationParamsProvider, { params, children: t38 }), $[142] = params, $[143] = t38, $[144] = t39) : t39 = $[144];
|
|
2925
2933
|
let t40;
|
|
2926
|
-
$[
|
|
2934
|
+
$[145] !== navigate || $[146] !== t39 ? (t40 = /* @__PURE__ */ jsx(PresentationNavigateProvider, { navigate, children: t39 }), $[145] = navigate, $[146] = t39, $[147] = t40) : t40 = $[147];
|
|
2927
2935
|
let t41;
|
|
2928
|
-
$[
|
|
2936
|
+
$[148] !== devMode || $[149] !== name || $[150] !== navigate || $[151] !== params || $[152] !== searchParams || $[153] !== structureParams || $[154] !== t40 ? (t41 = /* @__PURE__ */ jsx(PresentationProvider, { devMode, name, navigate, params, searchParams, structureParams, children: t40 }), $[148] = devMode, $[149] = name, $[150] = navigate, $[151] = params, $[152] = searchParams, $[153] = structureParams, $[154] = t40, $[155] = t41) : t41 = $[155];
|
|
2929
2937
|
let t42;
|
|
2930
|
-
$[
|
|
2938
|
+
$[156] !== controller || $[157] !== displayedDocument || $[158] !== perspective || $[159] !== setDocumentsOnPage || $[160] !== setLoadersConnection ? (t42 = controller && /* @__PURE__ */ jsx(LiveQueries, { controller, perspective, liveDocument: displayedDocument, onDocumentsOnPage: setDocumentsOnPage, onLoadersConnection: setLoadersConnection }), $[156] = controller, $[157] = displayedDocument, $[158] = perspective, $[159] = setDocumentsOnPage, $[160] = setLoadersConnection, $[161] = t42) : t42 = $[161];
|
|
2931
2939
|
let t43;
|
|
2932
|
-
$[
|
|
2940
|
+
$[162] !== loadersConnection || $[163] !== params.id || $[164] !== params.type || $[165] !== previewKitConnection || $[166] !== visualEditingComlink ? (t43 = visualEditingComlink && params.id && params.type && /* @__PURE__ */ jsx(PostMessageRefreshMutations, { comlink: visualEditingComlink, id: params.id, type: params.type, loadersConnection, previewKitConnection }), $[162] = loadersConnection, $[163] = params.id, $[164] = params.type, $[165] = previewKitConnection, $[166] = visualEditingComlink, $[167] = t43) : t43 = $[167];
|
|
2933
2941
|
let t44;
|
|
2934
|
-
$[
|
|
2942
|
+
$[168] !== perspective || $[169] !== visualEditingComlink ? (t44 = visualEditingComlink && /* @__PURE__ */ jsx(PostMessageSchema, { comlink: visualEditingComlink, perspective }), $[168] = perspective, $[169] = visualEditingComlink, $[170] = t44) : t44 = $[170];
|
|
2935
2943
|
let t45;
|
|
2936
|
-
$[
|
|
2944
|
+
$[171] !== documentsOnPage || $[172] !== perspective || $[173] !== visualEditingComlink ? (t45 = visualEditingComlink && documentsOnPage.length > 0 && /* @__PURE__ */ jsx(PostMessagePreviewSnapshots, { comlink: visualEditingComlink, perspective, refs: documentsOnPage }), $[171] = documentsOnPage, $[172] = perspective, $[173] = visualEditingComlink, $[174] = t45) : t45 = $[174];
|
|
2937
2945
|
let t46;
|
|
2938
|
-
$[
|
|
2946
|
+
$[175] !== perspective || $[176] !== visualEditingComlink ? (t46 = visualEditingComlink && /* @__PURE__ */ jsx(PostMessageDocuments, { comlink: visualEditingComlink, perspective }), $[175] = perspective, $[176] = visualEditingComlink, $[177] = t46) : t46 = $[177];
|
|
2939
2947
|
let t47;
|
|
2940
|
-
$[
|
|
2948
|
+
$[178] !== visualEditingComlink ? (t47 = visualEditingComlink && /* @__PURE__ */ jsx(PostMessageFeatures, { comlink: visualEditingComlink }), $[178] = visualEditingComlink, $[179] = t47) : t47 = $[179];
|
|
2941
2949
|
let t48;
|
|
2942
|
-
$[
|
|
2950
|
+
$[180] !== perspective || $[181] !== visualEditingComlink ? (t48 = visualEditingComlink && /* @__PURE__ */ jsx(PostMessagePerspective, { comlink: visualEditingComlink, perspective, setHandlesPerspectiveChange }), $[180] = perspective, $[181] = visualEditingComlink, $[182] = t48) : t48 = $[182];
|
|
2943
2951
|
let t49;
|
|
2944
|
-
$[
|
|
2952
|
+
$[183] !== visualEditingComlink ? (t49 = visualEditingComlink && /* @__PURE__ */ jsx(PostMessageTelemetry, { comlink: visualEditingComlink }), $[183] = visualEditingComlink, $[184] = t49) : t49 = $[184];
|
|
2945
2953
|
let t50;
|
|
2946
|
-
$[
|
|
2954
|
+
$[185] !== t42 || $[186] !== t43 || $[187] !== t44 || $[188] !== t45 || $[189] !== t46 || $[190] !== t47 || $[191] !== t48 || $[192] !== t49 ? (t50 = /* @__PURE__ */ jsxs(Suspense, { children: [
|
|
2947
2955
|
t42,
|
|
2948
2956
|
t43,
|
|
2949
2957
|
t44,
|
|
@@ -2952,12 +2960,12 @@ function PresentationTool(props) {
|
|
|
2952
2960
|
t47,
|
|
2953
2961
|
t48,
|
|
2954
2962
|
t49
|
|
2955
|
-
] }), $[
|
|
2963
|
+
] }), $[185] = t42, $[186] = t43, $[187] = t44, $[188] = t45, $[189] = t46, $[190] = t47, $[191] = t48, $[192] = t49, $[193] = t50) : t50 = $[193];
|
|
2956
2964
|
let t51;
|
|
2957
|
-
return $[
|
|
2965
|
+
return $[194] !== t41 || $[195] !== t50 ? (t51 = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2958
2966
|
t41,
|
|
2959
2967
|
t50
|
|
2960
|
-
] }), $[
|
|
2968
|
+
] }), $[194] = t41, $[195] = t50, $[196] = t51) : t51 = $[196], t51;
|
|
2961
2969
|
}
|
|
2962
2970
|
function _temp2$2(state_0) {
|
|
2963
2971
|
return state_0.matches("loading");
|