@sanity/assist 1.2.14 → 1.2.15-lang.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +392 -6
  2. package/dist/index.d.ts +170 -3
  3. package/dist/index.esm.js +2019 -125
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +2013 -119
  6. package/dist/index.js.map +1 -1
  7. package/package.json +12 -11
  8. package/src/_lib/form/DocumentForm.tsx +1 -1
  9. package/src/assistDocument/RequestRunInstructionProvider.tsx +37 -21
  10. package/src/assistDocument/components/instruction/InstructionInput.tsx +5 -4
  11. package/src/assistDocument/components/instruction/InstructionOutputField.tsx +45 -0
  12. package/src/assistDocument/components/instruction/InstructionOutputInput.tsx +205 -0
  13. package/src/assistDocument/hooks/useStudioAssistDocument.ts +5 -32
  14. package/src/assistFormComponents/AssistField.tsx +5 -4
  15. package/src/assistFormComponents/AssistFormBlock.tsx +2 -3
  16. package/src/assistFormComponents/validation/listItem.tsx +2 -2
  17. package/src/assistInspector/FieldAutocomplete.tsx +1 -0
  18. package/src/assistInspector/InstructionTaskHistoryButton.tsx +2 -3
  19. package/src/assistInspector/helpers.ts +7 -9
  20. package/src/assistLayout/AssistLayout.tsx +9 -6
  21. package/src/fieldActions/assistFieldActions.tsx +21 -8
  22. package/src/fieldActions/translateActions.tsx +141 -0
  23. package/src/helpers/assistSupported.ts +1 -1
  24. package/src/node_modules/.vitest/results.json +1 -0
  25. package/src/plugin.tsx +6 -0
  26. package/src/presence/AssistAvatar.tsx +1 -1
  27. package/src/schemas/assistDocumentSchema.tsx +39 -0
  28. package/src/schemas/serialize/serializeSchema.ts +6 -6
  29. package/src/schemas/typeDefExtensions.ts +12 -1
  30. package/src/translate/FieldTranslationProvider.tsx +267 -0
  31. package/src/translate/getLanguageParams.ts +26 -0
  32. package/src/translate/paths.test.ts +87 -0
  33. package/src/translate/paths.ts +151 -0
  34. package/src/translate/types.ts +159 -0
  35. package/src/types.ts +21 -2
  36. package/src/useApiClient.ts +63 -0
package/dist/index.js CHANGED
@@ -41,6 +41,8 @@ const instructionTaskTypeName = "sanity.assist.instructionTask";
41
41
  const fieldPresenceTypeName = "sanity.assist.instructionTask.presence";
42
42
  const assistSerializedTypeName = "sanity.assist.serialized.type";
43
43
  const assistSerializedFieldTypeName = "sanity.assist.serialized.field";
44
+ const outputFieldTypeName = "sanity.assist.output.field";
45
+ const outputTypeTypeName = "sanity.assist.output.type";
44
46
  const fieldPathParam = "pathKey";
45
47
  const instructionParam = "instruction";
46
48
  const documentRootKey = "<document>";
@@ -175,7 +177,8 @@ function isDisabled(type, allowReadonlyHidden) {
175
177
  return !isSchemaAssistEnabled(type) || isUnsupportedType(type) || !allowReadonlyHidden && readonlyHidden;
176
178
  }
177
179
  function isUnsupportedType(type) {
178
- return type.jsonType === "number" || type.name === "sanity.imageCrop" || type.name === "sanity.imageHotspot" || isType(type, "reference") || isType(type, "crossDatasetReference") || isType(type, "slug") || isType(type, "url") || isType(type, "date") || isType(type, "datetime") || isType(type, "file");
180
+ var _a, _b;
181
+ return type.jsonType === "number" || type.name === "sanity.imageCrop" || type.name === "sanity.imageHotspot" || isType(type, "reference") && !((_b = (_a = type == null ? void 0 : type.options) == null ? void 0 : _a.aiWritingAssistance) == null ? void 0 : _b.embeddingsIndex) || isType(type, "crossDatasetReference") || isType(type, "slug") || isType(type, "url") || isType(type, "date") || isType(type, "datetime") || isType(type, "file");
179
182
  }
180
183
  const inlineTypes = ["document", "object", "image", "file"];
181
184
  function serializeSchema(schema, options) {
@@ -217,13 +220,14 @@ function getSchemaStub(schemaType, schema, options) {
217
220
  return removeUndef(baseSchema);
218
221
  }
219
222
  function getBaseFields(schema, type, typeName, options) {
220
- var _a, _b, _c;
221
- const imagePromptField = (_a = type.options) == null ? void 0 : _a.imagePromptField;
223
+ var _a, _b, _c, _d, _e;
224
+ const schemaOptions = removeUndef({
225
+ imagePromptField: (_a = type.options) == null ? void 0 : _a.imagePromptField,
226
+ embeddingsIndex: (_c = (_b = type.options) == null ? void 0 : _b.aiWritingAssistance) == null ? void 0 : _c.embeddingsIndex
227
+ });
222
228
  return removeUndef({
223
- options: imagePromptField ? {
224
- imagePromptField
225
- } : void 0,
226
- values: Array.isArray((_b = type == null ? void 0 : type.options) == null ? void 0 : _b.list) ? (_c = type == null ? void 0 : type.options) == null ? void 0 : _c.list.map(v => {
229
+ options: Object.keys(schemaOptions).length ? schemaOptions : void 0,
230
+ values: Array.isArray((_d = type == null ? void 0 : type.options) == null ? void 0 : _d.list) ? (_e = type == null ? void 0 : type.options) == null ? void 0 : _e.list.map(v => {
227
231
  var _a2;
228
232
  return typeof v === "string" ? v : (_a2 = v.value) != null ? _a2 : "".concat(v.title);
229
233
  }) : void 0,
@@ -680,7 +684,6 @@ function useStudioAssistDocument(_ref2) {
680
684
  } = _ref2;
681
685
  const documentTypeName = schemaType.name;
682
686
  const currentUser = sanity.useCurrentUser();
683
- const validation = sanity.useValidationStatus(publicId(documentId), schemaType.name).validation;
684
687
  const assistDocument = useDocumentState(assistDocumentId(documentTypeName), assistDocumentTypeName);
685
688
  const assistTasksStatus = useDocumentState(assistTasksStatusId(documentId != null ? documentId : ""), assistTasksStatusTypeName);
686
689
  const client = sanity.useClient({
@@ -705,7 +708,7 @@ function useStudioAssistDocument(_ref2) {
705
708
  return {
706
709
  ...assistField,
707
710
  tasks: tasks.filter(task => task.path === assistField.path),
708
- instructions: (_a2 = assistField.instructions) == null ? void 0 : _a2.filter(p => !p.userId || p.userId === (currentUser == null ? void 0 : currentUser.id)).map(instruction => asStudioInstruction(instruction, tasks, validation))
711
+ instructions: (_a2 = assistField.instructions) == null ? void 0 : _a2.filter(p => !p.userId || p.userId === (currentUser == null ? void 0 : currentUser.id)).map(instruction => asStudioInstruction(instruction, tasks))
709
712
  };
710
713
  });
711
714
  return sanity.typed({
@@ -720,21 +723,12 @@ function useStudioAssistDocument(_ref2) {
720
723
  }),
721
724
  fields
722
725
  });
723
- }, [assistDocument, assistTasksStatus, currentUser, validation]);
726
+ }, [assistDocument, assistTasksStatus, currentUser]);
724
727
  }
725
- function asStudioInstruction(instruction, run, validation) {
726
- var _a;
727
- const errors = validation.filter(marker => marker.level === "error");
728
- const fieldRefs = ((_a = instruction == null ? void 0 : instruction.prompt) != null ? _a : []).flatMap(block => {
729
- if (block._type === "block") {
730
- return block.children.filter(c => c._type === fieldReferenceTypeName);
731
- }
732
- return [];
733
- });
728
+ function asStudioInstruction(instruction, run) {
734
729
  return {
735
730
  ...instruction,
736
- tasks: run.filter(task => task.instructionKey === instruction._key).filter(task => task.started && /* @__PURE__ */new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs),
737
- validation: errors.filter(marker => fieldRefs.map(r => r.path).filter(p => !!p).find(path => sanity.pathToString(marker.path) === path))
731
+ tasks: run.filter(task => task.instructionKey === instruction._key).filter(task => task.started && ( /* @__PURE__ */new Date()).getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs)
738
732
  };
739
733
  }
740
734
  function useInterval(ms) {
@@ -815,13 +809,13 @@ function InstructionTaskHistoryButton(props) {
815
809
  const statusDocId = assistTasksStatusId(documentId);
816
810
  const basePath = "".concat(sanity.typed("tasks"), '[_key=="').concat(taskKey, '"]');
817
811
  client.patch(statusDocId).set({
818
- ["".concat(basePath, ".").concat(sanity.typed("ended"))]: /* @__PURE__ */new Date().toISOString(),
812
+ ["".concat(basePath, ".").concat(sanity.typed("ended"))]: ( /* @__PURE__ */new Date()).toISOString(),
819
813
  ["".concat(basePath, ".").concat(sanity.typed("reason"))]: sanity.typed("aborted")
820
814
  }).commit().catch(console.error);
821
815
  }, [client, documentId]);
822
816
  const titledTasks = react.useMemo(() => {
823
817
  var _a2;
824
- const t = (_a2 = tasks == null ? void 0 : tasks.filter(task => task.started && /* @__PURE__ */new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs).map(task => {
818
+ const t = (_a2 = tasks == null ? void 0 : tasks.filter(task => task.started && ( /* @__PURE__ */new Date()).getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs).map(task => {
825
819
  var _a3;
826
820
  const instruction = instructions == null ? void 0 : instructions.find(i => i._key === task.instructionKey);
827
821
  return {
@@ -888,11 +882,10 @@ const TaskStatusButton = react.forwardRef(function TaskStatusButton2(props, ref)
888
882
  mode: "bleed",
889
883
  onClick,
890
884
  tone: hasErrors ? "critical" : void 0,
891
- fontSize: 1,
892
885
  disabled,
893
886
  ref,
894
887
  selected,
895
- tooltip: TASK_STATUS_BUTTON_TOOLTIP_PROPS
888
+ tooltipProps: TASK_STATUS_BUTTON_TOOLTIP_PROPS
896
889
  });
897
890
  });
898
891
  function TaskList(props) {
@@ -979,6 +972,50 @@ function useApiClient(customApiClient) {
979
972
  });
980
973
  return react.useMemo(() => customApiClient ? customApiClient(client) : client, [client, customApiClient]);
981
974
  }
975
+ function useTranslate(apiClient) {
976
+ const [loading, setLoading] = react.useState(false);
977
+ const user = sanity.useCurrentUser();
978
+ const schema = sanity.useSchema();
979
+ const types = react.useMemo(() => serializeSchema(schema, {
980
+ leanFormat: true
981
+ }), [schema]);
982
+ const toast = ui.useToast();
983
+ const translate = react.useCallback(_ref4 => {
984
+ let {
985
+ documentId,
986
+ languagePath,
987
+ fieldLanguageMap
988
+ } = _ref4;
989
+ setLoading(true);
990
+ return apiClient.request({
991
+ method: "POST",
992
+ url: "/assist/tasks/translate/".concat(apiClient.config().dataset, "?projectId=").concat(apiClient.config().projectId),
993
+ body: {
994
+ documentId,
995
+ types,
996
+ languagePath,
997
+ fieldLanguageMap,
998
+ userId: user == null ? void 0 : user.id
999
+ }
1000
+ }).catch(e => {
1001
+ toast.push({
1002
+ status: "error",
1003
+ title: "Translate failed",
1004
+ description: e.message
1005
+ });
1006
+ setLoading(false);
1007
+ throw e;
1008
+ }).finally(() => {
1009
+ setTimeout(() => {
1010
+ setLoading(false);
1011
+ }, 2e3);
1012
+ });
1013
+ }, [setLoading, apiClient, toast, user, types]);
1014
+ return react.useMemo(() => ({
1015
+ translate,
1016
+ loading
1017
+ }), [translate, loading]);
1018
+ }
982
1019
  function useGenerateCaption(apiClient) {
983
1020
  const [loading, setLoading] = react.useState(false);
984
1021
  const user = sanity.useCurrentUser();
@@ -987,11 +1024,11 @@ function useGenerateCaption(apiClient) {
987
1024
  leanFormat: true
988
1025
  }), [schema]);
989
1026
  const toast = ui.useToast();
990
- const generateCaption = react.useCallback(_ref4 => {
1027
+ const generateCaption = react.useCallback(_ref5 => {
991
1028
  let {
992
1029
  path,
993
1030
  documentId
994
- } = _ref4;
1031
+ } = _ref5;
995
1032
  setLoading(true);
996
1033
  return apiClient.request({
997
1034
  method: "POST",
@@ -1210,8 +1247,8 @@ function RunInstructionProvider(props) {
1210
1247
  runInstructionRequest({
1211
1248
  ...request,
1212
1249
  instructionKey: instruction._key,
1213
- userTexts: Object.entries(inputs).map(_ref5 => {
1214
- let [key, value] = _ref5;
1250
+ userTexts: Object.entries(inputs).map(_ref6 => {
1251
+ let [key, value] = _ref6;
1215
1252
  return {
1216
1253
  blockKey: key,
1217
1254
  userInput: value
@@ -1224,8 +1261,8 @@ function RunInstructionProvider(props) {
1224
1261
  const open = !!runRequest;
1225
1262
  const runDisabled = react.useMemo(() => {
1226
1263
  var _a2, _b;
1227
- return ((_b = (_a2 = runRequest == null ? void 0 : runRequest.userInputBlocks) == null ? void 0 : _a2.length) != null ? _b : 0) > Object.entries(inputs).filter(_ref6 => {
1228
- let [, value] = _ref6;
1264
+ return ((_b = (_a2 = runRequest == null ? void 0 : runRequest.userInputBlocks) == null ? void 0 : _a2.length) != null ? _b : 0) > Object.entries(inputs).filter(_ref7 => {
1265
+ let [, value] = _ref7;
1229
1266
  return !!value;
1230
1267
  }).length;
1231
1268
  }, [runRequest == null ? void 0 : runRequest.userInputBlocks, inputs]);
@@ -1336,29 +1373,37 @@ function getAssistableDocId(documentSchemaType, documentId) {
1336
1373
  return documentSchemaType.liveEdit ? baseId : "drafts.".concat(baseId);
1337
1374
  }
1338
1375
  function useRequestRunInstruction(args) {
1339
- const {
1340
- documentOnChange,
1341
- isDocAssistable: isDocAssistable2
1342
- } = args;
1343
1376
  const {
1344
1377
  runInstruction,
1345
1378
  instructionLoading
1346
1379
  } = useRunInstruction();
1347
- const [queuedTask, setQueuedTask] = react.useState(void 0);
1348
- react.useEffect(() => {
1349
- if (queuedTask && isDocAssistable2) {
1350
- runInstruction(queuedTask);
1351
- setQueuedTask(void 0);
1352
- }
1353
- }, [queuedTask, isDocAssistable2, runInstruction]);
1380
+ const requestRunInstruction = useDraftDelayedTask({
1381
+ ...args,
1382
+ task: runInstruction
1383
+ });
1354
1384
  return {
1355
1385
  instructionLoading,
1356
- requestRunInstruction: react.useCallback(task => {
1357
- documentOnChange(sanity.PatchEvent.from([sanity.unset(["_force_document_creation"])]));
1358
- setQueuedTask(task);
1359
- }, [setQueuedTask, documentOnChange])
1386
+ requestRunInstruction
1360
1387
  };
1361
1388
  }
1389
+ function useDraftDelayedTask(args) {
1390
+ const {
1391
+ documentOnChange,
1392
+ isDocAssistable: isDocAssistable2,
1393
+ task
1394
+ } = args;
1395
+ const [queuedArgs, setQueuedArgs] = react.useState(void 0);
1396
+ react.useEffect(() => {
1397
+ if (queuedArgs && isDocAssistable2) {
1398
+ task(queuedArgs);
1399
+ setQueuedArgs(void 0);
1400
+ }
1401
+ }, [queuedArgs, isDocAssistable2, task]);
1402
+ return react.useCallback(taskArgs => {
1403
+ documentOnChange(sanity.PatchEvent.from([sanity.unset(["_force_document_creation"])]));
1404
+ setQueuedArgs(taskArgs);
1405
+ }, [setQueuedArgs, documentOnChange]);
1406
+ }
1362
1407
  const SparklesIllustration = styled__default.default(icons.SparklesIcon)({
1363
1408
  fontSize: "3.125em",
1364
1409
  "& path": {
@@ -1609,13 +1654,13 @@ function useSelectedSchema(fieldPath, documentSchema) {
1609
1654
  return currentSchema;
1610
1655
  }, [documentSchema, fieldPath]);
1611
1656
  }
1612
- function FieldsInitializer(_ref7) {
1657
+ function FieldsInitializer(_ref8) {
1613
1658
  let {
1614
1659
  pathKey,
1615
1660
  activePath,
1616
1661
  fieldExists,
1617
1662
  onChange
1618
- } = _ref7;
1663
+ } = _ref8;
1619
1664
  const initialized = react.useRef(false);
1620
1665
  react.useEffect(() => {
1621
1666
  if (initialized.current || fieldExists || activePath || !pathKey) {
@@ -1646,7 +1691,7 @@ function FieldAutocomplete(props) {
1646
1691
  return getFieldRefs(schemaType);
1647
1692
  }, [schemaType, includeDocument]);
1648
1693
  const currentField = react.useMemo(() => fieldRefs.find(f => f.key === fieldPath), [fieldPath, fieldRefs]);
1649
- const autocompleteOptions = react.useMemo(() => fieldRefs.filter(field => filter ? filter(field) : true).map(field => ({
1694
+ const autocompleteOptions = react.useMemo(() => fieldRefs.filter(field => filter ? filter(field) : true).filter(f => !isType(f.schemaType, "reference")).map(field => ({
1650
1695
  value: field.key,
1651
1696
  field
1652
1697
  })), [fieldRefs, filter]);
@@ -2143,10 +2188,10 @@ const assistInspector = {
2143
2188
  showAsAction: false
2144
2189
  }),
2145
2190
  component: AssistInspectorWrapper,
2146
- onClose(_ref8) {
2191
+ onClose(_ref9) {
2147
2192
  let {
2148
2193
  params
2149
- } = _ref8;
2194
+ } = _ref9;
2150
2195
  return {
2151
2196
  params: sanity.typed({
2152
2197
  ...params,
@@ -2174,7 +2219,7 @@ function useAssistPresence(path, showFocusWithin) {
2174
2219
  const activePresence = (_b = (_a = tasks == null ? void 0 : tasks.filter(task => !task.ended)) == null ? void 0 : _a.flatMap(task => {
2175
2220
  var _a2;
2176
2221
  return (_a2 = task.presence) != null ? _a2 : [];
2177
- })) == null ? void 0 : _b.filter(p => p.started && /* @__PURE__ */new Date().getTime() - new Date(p.started).getTime() < maxHistoryVisibilityMs).filter(presence => {
2222
+ })) == null ? void 0 : _b.filter(p => p.started && ( /* @__PURE__ */new Date()).getTime() - new Date(p.started).getTime() < maxHistoryVisibilityMs).filter(presence => {
2178
2223
  if (!presence.path || !path.length) {
2179
2224
  return false;
2180
2225
  }
@@ -2208,7 +2253,7 @@ function aiPresence(presence, path, title) {
2208
2253
  },
2209
2254
  path,
2210
2255
  sessionId: "not-available",
2211
- lastActiveAt: (_a = presence == null ? void 0 : presence.started) != null ? _a : /* @__PURE__ */new Date().toISOString()
2256
+ lastActiveAt: (_a = presence == null ? void 0 : presence.started) != null ? _a : ( /* @__PURE__ */new Date()).toISOString()
2212
2257
  };
2213
2258
  }
2214
2259
  var __freeze$3 = Object.freeze;
@@ -2219,11 +2264,11 @@ var __template$3 = (cooked, raw) => __freeze$3(__defProp$3(cooked, "raw", {
2219
2264
  var _a$3, _b$1;
2220
2265
  const fadeIn = styled.keyframes(_a$3 || (_a$3 = __template$3(["\n 0% {\n opacity: 0;\n transform: scale(0.75);\n }\n 40% {\n opacity: 0;\n transform: scale(0.75);\n }\n 100% {\n opacity: 1;\n transform: scale(1);\n }\n"])));
2221
2266
  const FadeInDiv = styled__default.default.div(_b$1 || (_b$1 = __template$3(["\n animation-name: ", ";\n animation-timing-function: ease-in-out;\n"])), fadeIn);
2222
- const FadeInContent = react.forwardRef(function FadeInContent2(_ref9, ref) {
2267
+ const FadeInContent = react.forwardRef(function FadeInContent2(_ref10, ref) {
2223
2268
  let {
2224
2269
  children,
2225
2270
  durationMs = 250
2226
- } = _ref9;
2271
+ } = _ref10;
2227
2272
  return /* @__PURE__ */jsxRuntime.jsx(FadeInDiv, {
2228
2273
  ref,
2229
2274
  style: {
@@ -2235,47 +2280,47 @@ const FadeInContent = react.forwardRef(function FadeInContent2(_ref9, ref) {
2235
2280
  const purple = {
2236
2281
  "50": {
2237
2282
  title: "Purple 50",
2238
- hex: "#f8e9fe"
2283
+ hex: "#f8f5ff"
2239
2284
  },
2240
2285
  "100": {
2241
2286
  title: "Purple 100",
2242
- hex: "#f2d3fe"
2287
+ hex: "#f1ebff"
2243
2288
  },
2244
2289
  "200": {
2245
2290
  title: "Purple 200",
2246
- hex: "#e6a7fd"
2291
+ hex: "#ece1fe"
2247
2292
  },
2248
2293
  "300": {
2249
2294
  title: "Purple 300",
2250
- hex: "#d97bfd"
2295
+ hex: "#ccb1fc"
2251
2296
  },
2252
2297
  "400": {
2253
2298
  title: "Purple 400",
2254
- hex: "#cd4efc"
2299
+ hex: "#b087f7"
2255
2300
  },
2256
2301
  "500": {
2257
2302
  title: "Purple 500",
2258
- hex: "#c123fc"
2303
+ hex: "#8f57ef"
2259
2304
  },
2260
2305
  "600": {
2261
2306
  title: "Purple 600",
2262
- hex: "#9d1fcd"
2307
+ hex: "#721fe5"
2263
2308
  },
2264
2309
  "700": {
2265
2310
  title: "Purple 700",
2266
- hex: "#7a1b9e"
2311
+ hex: "#4c1a9e"
2267
2312
  },
2268
2313
  "800": {
2269
2314
  title: "Purple 800",
2270
- hex: "#56186f"
2315
+ hex: "#2f1862"
2271
2316
  },
2272
2317
  "900": {
2273
2318
  title: "Purple 900",
2274
- hex: "#331440"
2319
+ hex: "#23173f"
2275
2320
  },
2276
2321
  "950": {
2277
2322
  title: "Purple 950",
2278
- hex: "#211229"
2323
+ hex: "#181128"
2279
2324
  }
2280
2325
  };
2281
2326
  var __freeze$2 = Object.freeze;
@@ -2326,7 +2371,11 @@ function AssistAvatar(props) {
2326
2371
  style: {
2327
2372
  color: "inherit"
2328
2373
  },
2329
- children: /* @__PURE__ */jsxRuntime.jsx(icons.SparklesIcon, {})
2374
+ children: /* @__PURE__ */jsxRuntime.jsx(icons.SparklesIcon, {
2375
+ style: {
2376
+ color: "inherit"
2377
+ }
2378
+ })
2330
2379
  })
2331
2380
  })]
2332
2381
  });
@@ -2492,15 +2541,16 @@ function AssistField(props) {
2492
2541
  showOnboarding,
2493
2542
  dismissOnboarding
2494
2543
  } = useOnboardingFeature(fieldOnboardingKey);
2544
+ const singlePresence = presence[0];
2495
2545
  const actions = /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2496
2546
  gap: 2,
2497
2547
  align: "center",
2498
2548
  justify: "space-between",
2499
- children: [presence.map(pre => /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2549
+ children: [singlePresence && /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2500
2550
  children: /* @__PURE__ */jsxRuntime.jsx(AiFieldPresence, {
2501
- presence: pre
2502
- }, pre.lastActiveAt)
2503
- }, pre.user.id)), isFirstAssisted && showOnboarding && /* @__PURE__ */jsxRuntime.jsx(AssistOnboardingPopover, {
2551
+ presence: singlePresence
2552
+ })
2553
+ }), isFirstAssisted && showOnboarding && /* @__PURE__ */jsxRuntime.jsx(AssistOnboardingPopover, {
2504
2554
  dismiss: dismissOnboarding
2505
2555
  })]
2506
2556
  });
@@ -2972,7 +3022,6 @@ function AssistConnectorsOverlay(props) {
2972
3022
  zIndex: 150
2973
3023
  // zIndex,
2974
3024
  },
2975
-
2976
3025
  children: connectors.map(connector => /* @__PURE__ */jsxRuntime.jsx(ConnectorPath, {
2977
3026
  from: connector.from,
2978
3027
  options,
@@ -3211,6 +3260,1508 @@ function mapBlock(block, migratedContexts) {
3211
3260
  children: ((_d = textBlock.children) != null ? _d : []).map(child => mapBlock(child, migratedContexts))
3212
3261
  };
3213
3262
  }
3263
+ const MAX_DEPTH = 6;
3264
+ function getDocumentMembersFlat(doc, schemaType) {
3265
+ if (!sanity.isDocumentSchemaType(schemaType)) {
3266
+ console.error("Schema type is not a document");
3267
+ return [];
3268
+ }
3269
+ return extractPaths(doc, schemaType, [], MAX_DEPTH);
3270
+ }
3271
+ function extractPaths(doc, schemaType, path, maxDepth) {
3272
+ if (path.length >= maxDepth) {
3273
+ return [];
3274
+ }
3275
+ return schemaType.fields.reduce((acc, field) => {
3276
+ var _a;
3277
+ const fieldPath = [...path, field.name];
3278
+ const fieldSchema = field.type;
3279
+ const thisFieldWithPath = {
3280
+ path: fieldPath,
3281
+ name: field.name,
3282
+ schemaType: fieldSchema
3283
+ };
3284
+ if (fieldSchema.jsonType === "object") {
3285
+ const innerFields = extractPaths(doc, fieldSchema, fieldPath, maxDepth);
3286
+ return [...acc, thisFieldWithPath, ...innerFields];
3287
+ } else if (fieldSchema.jsonType === "array" && fieldSchema.of.length && fieldSchema.of.some(item => "fields" in item)) {
3288
+ const {
3289
+ value: arrayValue
3290
+ } = (_a = mutator.extractWithPath(sanity.pathToString(fieldPath), doc)[0]) != null ? _a : {};
3291
+ let arrayPaths = [];
3292
+ if (arrayValue == null ? void 0 : arrayValue.length) {
3293
+ for (const item of arrayValue) {
3294
+ const arrayItemSchema = fieldSchema.of.find(t => t.name === item._type);
3295
+ if (item._key && arrayItemSchema) {
3296
+ const itemPath = [...fieldPath, {
3297
+ _key: item._key
3298
+ }];
3299
+ const innerFields = extractPaths(doc, arrayItemSchema, itemPath, maxDepth);
3300
+ arrayPaths = [...arrayPaths, {
3301
+ path: itemPath,
3302
+ name: item._key,
3303
+ schemaType: arrayItemSchema
3304
+ }, ...innerFields];
3305
+ }
3306
+ }
3307
+ }
3308
+ return [...acc, thisFieldWithPath, ...arrayPaths];
3309
+ }
3310
+ return [...acc, thisFieldWithPath];
3311
+ }, []);
3312
+ }
3313
+ const defaultLanguageOutputs = function (member, enclosingType, translateFromLanguageId, translateToLanguageIds) {
3314
+ if (member.schemaType.jsonType === "object" && member.schemaType.name.startsWith("internationalizedArray")) {
3315
+ const pathEnd = member.path.slice(-1);
3316
+ const language = sanity.isKeySegment(pathEnd[0]) ? pathEnd[0]._key : null;
3317
+ return language === translateFromLanguageId ? translateToLanguageIds.map(translateToId => ({
3318
+ id: translateToId,
3319
+ outputPath: [...member.path.slice(0, -1), {
3320
+ _key: translateToId
3321
+ }]
3322
+ })) : void 0;
3323
+ }
3324
+ if (enclosingType.jsonType === "object" && enclosingType.name.startsWith("locale")) {
3325
+ return translateFromLanguageId === member.name ? translateToLanguageIds.map(translateToId => ({
3326
+ id: translateToId,
3327
+ outputPath: [...member.path.slice(0, -1), translateToId]
3328
+ })) : void 0;
3329
+ }
3330
+ return void 0;
3331
+ };
3332
+ function getTranslationMap(documentSchema, documentMembers, translateFromLanguageId, outputLanguageIds, langFn) {
3333
+ var _a, _b, _c;
3334
+ const translationMaps = [];
3335
+ for (const member of documentMembers) {
3336
+ const parentPath = member.path.slice(0, -1);
3337
+ const enclosingType = (_b = (_a = documentMembers.find(m => sanity.pathToString(m.path) === sanity.pathToString(parentPath))) == null ? void 0 : _a.schemaType) != null ? _b : documentSchema;
3338
+ const translations = (_c = langFn(member, enclosingType, translateFromLanguageId, outputLanguageIds)) == null ? void 0 : _c.filter(translation => translation.id !== translateFromLanguageId);
3339
+ if (translations) {
3340
+ translationMaps.push({
3341
+ inputLanguageId: translateFromLanguageId,
3342
+ inputPath: member.path,
3343
+ outputs: translations
3344
+ });
3345
+ }
3346
+ }
3347
+ return translationMaps;
3348
+ }
3349
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3350
+ function getDefaultExportFromCjs(x) {
3351
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3352
+ }
3353
+
3354
+ /**
3355
+ * Checks if `value` is classified as an `Array` object.
3356
+ *
3357
+ * @static
3358
+ * @memberOf _
3359
+ * @since 0.1.0
3360
+ * @category Lang
3361
+ * @param {*} value The value to check.
3362
+ * @returns {boolean} Returns `true` if `value` is an array, else `false`.
3363
+ * @example
3364
+ *
3365
+ * _.isArray([1, 2, 3]);
3366
+ * // => true
3367
+ *
3368
+ * _.isArray(document.body.children);
3369
+ * // => false
3370
+ *
3371
+ * _.isArray('abc');
3372
+ * // => false
3373
+ *
3374
+ * _.isArray(_.noop);
3375
+ * // => false
3376
+ */
3377
+
3378
+ var isArray$3 = Array.isArray;
3379
+ var isArray_1 = isArray$3;
3380
+
3381
+ /** Detect free variable `global` from Node.js. */
3382
+
3383
+ var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
3384
+ var _freeGlobal = freeGlobal$1;
3385
+ var freeGlobal = _freeGlobal;
3386
+
3387
+ /** Detect free variable `self`. */
3388
+ var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
3389
+
3390
+ /** Used as a reference to the global object. */
3391
+ var root$3 = freeGlobal || freeSelf || Function('return this')();
3392
+ var _root = root$3;
3393
+ var root$2 = _root;
3394
+
3395
+ /** Built-in value references. */
3396
+ var Symbol$3 = root$2.Symbol;
3397
+ var _Symbol = Symbol$3;
3398
+ var Symbol$2 = _Symbol;
3399
+
3400
+ /** Used for built-in method references. */
3401
+ var objectProto$4 = Object.prototype;
3402
+
3403
+ /** Used to check objects for own properties. */
3404
+ var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
3405
+
3406
+ /**
3407
+ * Used to resolve the
3408
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
3409
+ * of values.
3410
+ */
3411
+ var nativeObjectToString$1 = objectProto$4.toString;
3412
+
3413
+ /** Built-in value references. */
3414
+ var symToStringTag$1 = Symbol$2 ? Symbol$2.toStringTag : undefined;
3415
+
3416
+ /**
3417
+ * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
3418
+ *
3419
+ * @private
3420
+ * @param {*} value The value to query.
3421
+ * @returns {string} Returns the raw `toStringTag`.
3422
+ */
3423
+ function getRawTag$1(value) {
3424
+ var isOwn = hasOwnProperty$3.call(value, symToStringTag$1),
3425
+ tag = value[symToStringTag$1];
3426
+ try {
3427
+ value[symToStringTag$1] = undefined;
3428
+ var unmasked = true;
3429
+ } catch (e) {}
3430
+ var result = nativeObjectToString$1.call(value);
3431
+ if (unmasked) {
3432
+ if (isOwn) {
3433
+ value[symToStringTag$1] = tag;
3434
+ } else {
3435
+ delete value[symToStringTag$1];
3436
+ }
3437
+ }
3438
+ return result;
3439
+ }
3440
+ var _getRawTag = getRawTag$1;
3441
+
3442
+ /** Used for built-in method references. */
3443
+
3444
+ var objectProto$3 = Object.prototype;
3445
+
3446
+ /**
3447
+ * Used to resolve the
3448
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
3449
+ * of values.
3450
+ */
3451
+ var nativeObjectToString = objectProto$3.toString;
3452
+
3453
+ /**
3454
+ * Converts `value` to a string using `Object.prototype.toString`.
3455
+ *
3456
+ * @private
3457
+ * @param {*} value The value to convert.
3458
+ * @returns {string} Returns the converted string.
3459
+ */
3460
+ function objectToString$1(value) {
3461
+ return nativeObjectToString.call(value);
3462
+ }
3463
+ var _objectToString = objectToString$1;
3464
+ var Symbol$1 = _Symbol,
3465
+ getRawTag = _getRawTag,
3466
+ objectToString = _objectToString;
3467
+
3468
+ /** `Object#toString` result references. */
3469
+ var nullTag = '[object Null]',
3470
+ undefinedTag = '[object Undefined]';
3471
+
3472
+ /** Built-in value references. */
3473
+ var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
3474
+
3475
+ /**
3476
+ * The base implementation of `getTag` without fallbacks for buggy environments.
3477
+ *
3478
+ * @private
3479
+ * @param {*} value The value to query.
3480
+ * @returns {string} Returns the `toStringTag`.
3481
+ */
3482
+ function baseGetTag$2(value) {
3483
+ if (value == null) {
3484
+ return value === undefined ? undefinedTag : nullTag;
3485
+ }
3486
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
3487
+ }
3488
+ var _baseGetTag = baseGetTag$2;
3489
+
3490
+ /**
3491
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
3492
+ * and has a `typeof` result of "object".
3493
+ *
3494
+ * @static
3495
+ * @memberOf _
3496
+ * @since 4.0.0
3497
+ * @category Lang
3498
+ * @param {*} value The value to check.
3499
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
3500
+ * @example
3501
+ *
3502
+ * _.isObjectLike({});
3503
+ * // => true
3504
+ *
3505
+ * _.isObjectLike([1, 2, 3]);
3506
+ * // => true
3507
+ *
3508
+ * _.isObjectLike(_.noop);
3509
+ * // => false
3510
+ *
3511
+ * _.isObjectLike(null);
3512
+ * // => false
3513
+ */
3514
+
3515
+ function isObjectLike$1(value) {
3516
+ return value != null && typeof value == 'object';
3517
+ }
3518
+ var isObjectLike_1 = isObjectLike$1;
3519
+ var baseGetTag$1 = _baseGetTag,
3520
+ isObjectLike = isObjectLike_1;
3521
+
3522
+ /** `Object#toString` result references. */
3523
+ var symbolTag = '[object Symbol]';
3524
+
3525
+ /**
3526
+ * Checks if `value` is classified as a `Symbol` primitive or object.
3527
+ *
3528
+ * @static
3529
+ * @memberOf _
3530
+ * @since 4.0.0
3531
+ * @category Lang
3532
+ * @param {*} value The value to check.
3533
+ * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
3534
+ * @example
3535
+ *
3536
+ * _.isSymbol(Symbol.iterator);
3537
+ * // => true
3538
+ *
3539
+ * _.isSymbol('abc');
3540
+ * // => false
3541
+ */
3542
+ function isSymbol$3(value) {
3543
+ return typeof value == 'symbol' || isObjectLike(value) && baseGetTag$1(value) == symbolTag;
3544
+ }
3545
+ var isSymbol_1 = isSymbol$3;
3546
+ var isArray$2 = isArray_1,
3547
+ isSymbol$2 = isSymbol_1;
3548
+
3549
+ /** Used to match property names within property paths. */
3550
+ var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
3551
+ reIsPlainProp = /^\w*$/;
3552
+
3553
+ /**
3554
+ * Checks if `value` is a property name and not a property path.
3555
+ *
3556
+ * @private
3557
+ * @param {*} value The value to check.
3558
+ * @param {Object} [object] The object to query keys on.
3559
+ * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
3560
+ */
3561
+ function isKey$1(value, object) {
3562
+ if (isArray$2(value)) {
3563
+ return false;
3564
+ }
3565
+ var type = typeof value;
3566
+ if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol$2(value)) {
3567
+ return true;
3568
+ }
3569
+ return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
3570
+ }
3571
+ var _isKey = isKey$1;
3572
+
3573
+ /**
3574
+ * Checks if `value` is the
3575
+ * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
3576
+ * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
3577
+ *
3578
+ * @static
3579
+ * @memberOf _
3580
+ * @since 0.1.0
3581
+ * @category Lang
3582
+ * @param {*} value The value to check.
3583
+ * @returns {boolean} Returns `true` if `value` is an object, else `false`.
3584
+ * @example
3585
+ *
3586
+ * _.isObject({});
3587
+ * // => true
3588
+ *
3589
+ * _.isObject([1, 2, 3]);
3590
+ * // => true
3591
+ *
3592
+ * _.isObject(_.noop);
3593
+ * // => true
3594
+ *
3595
+ * _.isObject(null);
3596
+ * // => false
3597
+ */
3598
+
3599
+ function isObject$2(value) {
3600
+ var type = typeof value;
3601
+ return value != null && (type == 'object' || type == 'function');
3602
+ }
3603
+ var isObject_1 = isObject$2;
3604
+ var baseGetTag = _baseGetTag,
3605
+ isObject$1 = isObject_1;
3606
+
3607
+ /** `Object#toString` result references. */
3608
+ var asyncTag = '[object AsyncFunction]',
3609
+ funcTag = '[object Function]',
3610
+ genTag = '[object GeneratorFunction]',
3611
+ proxyTag = '[object Proxy]';
3612
+
3613
+ /**
3614
+ * Checks if `value` is classified as a `Function` object.
3615
+ *
3616
+ * @static
3617
+ * @memberOf _
3618
+ * @since 0.1.0
3619
+ * @category Lang
3620
+ * @param {*} value The value to check.
3621
+ * @returns {boolean} Returns `true` if `value` is a function, else `false`.
3622
+ * @example
3623
+ *
3624
+ * _.isFunction(_);
3625
+ * // => true
3626
+ *
3627
+ * _.isFunction(/abc/);
3628
+ * // => false
3629
+ */
3630
+ function isFunction$1(value) {
3631
+ if (!isObject$1(value)) {
3632
+ return false;
3633
+ }
3634
+ // The use of `Object#toString` avoids issues with the `typeof` operator
3635
+ // in Safari 9 which returns 'object' for typed arrays and other constructors.
3636
+ var tag = baseGetTag(value);
3637
+ return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
3638
+ }
3639
+ var isFunction_1 = isFunction$1;
3640
+ var root$1 = _root;
3641
+
3642
+ /** Used to detect overreaching core-js shims. */
3643
+ var coreJsData$1 = root$1['__core-js_shared__'];
3644
+ var _coreJsData = coreJsData$1;
3645
+ var coreJsData = _coreJsData;
3646
+
3647
+ /** Used to detect methods masquerading as native. */
3648
+ var maskSrcKey = function () {
3649
+ var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
3650
+ return uid ? 'Symbol(src)_1.' + uid : '';
3651
+ }();
3652
+
3653
+ /**
3654
+ * Checks if `func` has its source masked.
3655
+ *
3656
+ * @private
3657
+ * @param {Function} func The function to check.
3658
+ * @returns {boolean} Returns `true` if `func` is masked, else `false`.
3659
+ */
3660
+ function isMasked$1(func) {
3661
+ return !!maskSrcKey && maskSrcKey in func;
3662
+ }
3663
+ var _isMasked = isMasked$1;
3664
+
3665
+ /** Used for built-in method references. */
3666
+
3667
+ var funcProto$1 = Function.prototype;
3668
+
3669
+ /** Used to resolve the decompiled source of functions. */
3670
+ var funcToString$1 = funcProto$1.toString;
3671
+
3672
+ /**
3673
+ * Converts `func` to its source code.
3674
+ *
3675
+ * @private
3676
+ * @param {Function} func The function to convert.
3677
+ * @returns {string} Returns the source code.
3678
+ */
3679
+ function toSource$1(func) {
3680
+ if (func != null) {
3681
+ try {
3682
+ return funcToString$1.call(func);
3683
+ } catch (e) {}
3684
+ try {
3685
+ return func + '';
3686
+ } catch (e) {}
3687
+ }
3688
+ return '';
3689
+ }
3690
+ var _toSource = toSource$1;
3691
+ var isFunction = isFunction_1,
3692
+ isMasked = _isMasked,
3693
+ isObject = isObject_1,
3694
+ toSource = _toSource;
3695
+
3696
+ /**
3697
+ * Used to match `RegExp`
3698
+ * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
3699
+ */
3700
+ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
3701
+
3702
+ /** Used to detect host constructors (Safari). */
3703
+ var reIsHostCtor = /^\[object .+?Constructor\]$/;
3704
+
3705
+ /** Used for built-in method references. */
3706
+ var funcProto = Function.prototype,
3707
+ objectProto$2 = Object.prototype;
3708
+
3709
+ /** Used to resolve the decompiled source of functions. */
3710
+ var funcToString = funcProto.toString;
3711
+
3712
+ /** Used to check objects for own properties. */
3713
+ var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
3714
+
3715
+ /** Used to detect if a method is native. */
3716
+ var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty$2).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
3717
+
3718
+ /**
3719
+ * The base implementation of `_.isNative` without bad shim checks.
3720
+ *
3721
+ * @private
3722
+ * @param {*} value The value to check.
3723
+ * @returns {boolean} Returns `true` if `value` is a native function,
3724
+ * else `false`.
3725
+ */
3726
+ function baseIsNative$1(value) {
3727
+ if (!isObject(value) || isMasked(value)) {
3728
+ return false;
3729
+ }
3730
+ var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
3731
+ return pattern.test(toSource(value));
3732
+ }
3733
+ var _baseIsNative = baseIsNative$1;
3734
+
3735
+ /**
3736
+ * Gets the value at `key` of `object`.
3737
+ *
3738
+ * @private
3739
+ * @param {Object} [object] The object to query.
3740
+ * @param {string} key The key of the property to get.
3741
+ * @returns {*} Returns the property value.
3742
+ */
3743
+
3744
+ function getValue$1(object, key) {
3745
+ return object == null ? undefined : object[key];
3746
+ }
3747
+ var _getValue = getValue$1;
3748
+ var baseIsNative = _baseIsNative,
3749
+ getValue = _getValue;
3750
+
3751
+ /**
3752
+ * Gets the native function at `key` of `object`.
3753
+ *
3754
+ * @private
3755
+ * @param {Object} object The object to query.
3756
+ * @param {string} key The key of the method to get.
3757
+ * @returns {*} Returns the function if it's native, else `undefined`.
3758
+ */
3759
+ function getNative$2(object, key) {
3760
+ var value = getValue(object, key);
3761
+ return baseIsNative(value) ? value : undefined;
3762
+ }
3763
+ var _getNative = getNative$2;
3764
+ var getNative$1 = _getNative;
3765
+
3766
+ /* Built-in method references that are verified to be native. */
3767
+ var nativeCreate$4 = getNative$1(Object, 'create');
3768
+ var _nativeCreate = nativeCreate$4;
3769
+ var nativeCreate$3 = _nativeCreate;
3770
+
3771
+ /**
3772
+ * Removes all key-value entries from the hash.
3773
+ *
3774
+ * @private
3775
+ * @name clear
3776
+ * @memberOf Hash
3777
+ */
3778
+ function hashClear$1() {
3779
+ this.__data__ = nativeCreate$3 ? nativeCreate$3(null) : {};
3780
+ this.size = 0;
3781
+ }
3782
+ var _hashClear = hashClear$1;
3783
+
3784
+ /**
3785
+ * Removes `key` and its value from the hash.
3786
+ *
3787
+ * @private
3788
+ * @name delete
3789
+ * @memberOf Hash
3790
+ * @param {Object} hash The hash to modify.
3791
+ * @param {string} key The key of the value to remove.
3792
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
3793
+ */
3794
+
3795
+ function hashDelete$1(key) {
3796
+ var result = this.has(key) && delete this.__data__[key];
3797
+ this.size -= result ? 1 : 0;
3798
+ return result;
3799
+ }
3800
+ var _hashDelete = hashDelete$1;
3801
+ var nativeCreate$2 = _nativeCreate;
3802
+
3803
+ /** Used to stand-in for `undefined` hash values. */
3804
+ var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
3805
+
3806
+ /** Used for built-in method references. */
3807
+ var objectProto$1 = Object.prototype;
3808
+
3809
+ /** Used to check objects for own properties. */
3810
+ var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
3811
+
3812
+ /**
3813
+ * Gets the hash value for `key`.
3814
+ *
3815
+ * @private
3816
+ * @name get
3817
+ * @memberOf Hash
3818
+ * @param {string} key The key of the value to get.
3819
+ * @returns {*} Returns the entry value.
3820
+ */
3821
+ function hashGet$1(key) {
3822
+ var data = this.__data__;
3823
+ if (nativeCreate$2) {
3824
+ var result = data[key];
3825
+ return result === HASH_UNDEFINED$1 ? undefined : result;
3826
+ }
3827
+ return hasOwnProperty$1.call(data, key) ? data[key] : undefined;
3828
+ }
3829
+ var _hashGet = hashGet$1;
3830
+ var nativeCreate$1 = _nativeCreate;
3831
+
3832
+ /** Used for built-in method references. */
3833
+ var objectProto = Object.prototype;
3834
+
3835
+ /** Used to check objects for own properties. */
3836
+ var hasOwnProperty = objectProto.hasOwnProperty;
3837
+
3838
+ /**
3839
+ * Checks if a hash value for `key` exists.
3840
+ *
3841
+ * @private
3842
+ * @name has
3843
+ * @memberOf Hash
3844
+ * @param {string} key The key of the entry to check.
3845
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
3846
+ */
3847
+ function hashHas$1(key) {
3848
+ var data = this.__data__;
3849
+ return nativeCreate$1 ? data[key] !== undefined : hasOwnProperty.call(data, key);
3850
+ }
3851
+ var _hashHas = hashHas$1;
3852
+ var nativeCreate = _nativeCreate;
3853
+
3854
+ /** Used to stand-in for `undefined` hash values. */
3855
+ var HASH_UNDEFINED = '__lodash_hash_undefined__';
3856
+
3857
+ /**
3858
+ * Sets the hash `key` to `value`.
3859
+ *
3860
+ * @private
3861
+ * @name set
3862
+ * @memberOf Hash
3863
+ * @param {string} key The key of the value to set.
3864
+ * @param {*} value The value to set.
3865
+ * @returns {Object} Returns the hash instance.
3866
+ */
3867
+ function hashSet$1(key, value) {
3868
+ var data = this.__data__;
3869
+ this.size += this.has(key) ? 0 : 1;
3870
+ data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
3871
+ return this;
3872
+ }
3873
+ var _hashSet = hashSet$1;
3874
+ var hashClear = _hashClear,
3875
+ hashDelete = _hashDelete,
3876
+ hashGet = _hashGet,
3877
+ hashHas = _hashHas,
3878
+ hashSet = _hashSet;
3879
+
3880
+ /**
3881
+ * Creates a hash object.
3882
+ *
3883
+ * @private
3884
+ * @constructor
3885
+ * @param {Array} [entries] The key-value pairs to cache.
3886
+ */
3887
+ function Hash$1(entries) {
3888
+ var index = -1,
3889
+ length = entries == null ? 0 : entries.length;
3890
+ this.clear();
3891
+ while (++index < length) {
3892
+ var entry = entries[index];
3893
+ this.set(entry[0], entry[1]);
3894
+ }
3895
+ }
3896
+
3897
+ // Add methods to `Hash`.
3898
+ Hash$1.prototype.clear = hashClear;
3899
+ Hash$1.prototype['delete'] = hashDelete;
3900
+ Hash$1.prototype.get = hashGet;
3901
+ Hash$1.prototype.has = hashHas;
3902
+ Hash$1.prototype.set = hashSet;
3903
+ var _Hash = Hash$1;
3904
+
3905
+ /**
3906
+ * Removes all key-value entries from the list cache.
3907
+ *
3908
+ * @private
3909
+ * @name clear
3910
+ * @memberOf ListCache
3911
+ */
3912
+
3913
+ function listCacheClear$1() {
3914
+ this.__data__ = [];
3915
+ this.size = 0;
3916
+ }
3917
+ var _listCacheClear = listCacheClear$1;
3918
+
3919
+ /**
3920
+ * Performs a
3921
+ * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
3922
+ * comparison between two values to determine if they are equivalent.
3923
+ *
3924
+ * @static
3925
+ * @memberOf _
3926
+ * @since 4.0.0
3927
+ * @category Lang
3928
+ * @param {*} value The value to compare.
3929
+ * @param {*} other The other value to compare.
3930
+ * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
3931
+ * @example
3932
+ *
3933
+ * var object = { 'a': 1 };
3934
+ * var other = { 'a': 1 };
3935
+ *
3936
+ * _.eq(object, object);
3937
+ * // => true
3938
+ *
3939
+ * _.eq(object, other);
3940
+ * // => false
3941
+ *
3942
+ * _.eq('a', 'a');
3943
+ * // => true
3944
+ *
3945
+ * _.eq('a', Object('a'));
3946
+ * // => false
3947
+ *
3948
+ * _.eq(NaN, NaN);
3949
+ * // => true
3950
+ */
3951
+
3952
+ function eq$1(value, other) {
3953
+ return value === other || value !== value && other !== other;
3954
+ }
3955
+ var eq_1 = eq$1;
3956
+ var eq = eq_1;
3957
+
3958
+ /**
3959
+ * Gets the index at which the `key` is found in `array` of key-value pairs.
3960
+ *
3961
+ * @private
3962
+ * @param {Array} array The array to inspect.
3963
+ * @param {*} key The key to search for.
3964
+ * @returns {number} Returns the index of the matched value, else `-1`.
3965
+ */
3966
+ function assocIndexOf$4(array, key) {
3967
+ var length = array.length;
3968
+ while (length--) {
3969
+ if (eq(array[length][0], key)) {
3970
+ return length;
3971
+ }
3972
+ }
3973
+ return -1;
3974
+ }
3975
+ var _assocIndexOf = assocIndexOf$4;
3976
+ var assocIndexOf$3 = _assocIndexOf;
3977
+
3978
+ /** Used for built-in method references. */
3979
+ var arrayProto = Array.prototype;
3980
+
3981
+ /** Built-in value references. */
3982
+ var splice = arrayProto.splice;
3983
+
3984
+ /**
3985
+ * Removes `key` and its value from the list cache.
3986
+ *
3987
+ * @private
3988
+ * @name delete
3989
+ * @memberOf ListCache
3990
+ * @param {string} key The key of the value to remove.
3991
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
3992
+ */
3993
+ function listCacheDelete$1(key) {
3994
+ var data = this.__data__,
3995
+ index = assocIndexOf$3(data, key);
3996
+ if (index < 0) {
3997
+ return false;
3998
+ }
3999
+ var lastIndex = data.length - 1;
4000
+ if (index == lastIndex) {
4001
+ data.pop();
4002
+ } else {
4003
+ splice.call(data, index, 1);
4004
+ }
4005
+ --this.size;
4006
+ return true;
4007
+ }
4008
+ var _listCacheDelete = listCacheDelete$1;
4009
+ var assocIndexOf$2 = _assocIndexOf;
4010
+
4011
+ /**
4012
+ * Gets the list cache value for `key`.
4013
+ *
4014
+ * @private
4015
+ * @name get
4016
+ * @memberOf ListCache
4017
+ * @param {string} key The key of the value to get.
4018
+ * @returns {*} Returns the entry value.
4019
+ */
4020
+ function listCacheGet$1(key) {
4021
+ var data = this.__data__,
4022
+ index = assocIndexOf$2(data, key);
4023
+ return index < 0 ? undefined : data[index][1];
4024
+ }
4025
+ var _listCacheGet = listCacheGet$1;
4026
+ var assocIndexOf$1 = _assocIndexOf;
4027
+
4028
+ /**
4029
+ * Checks if a list cache value for `key` exists.
4030
+ *
4031
+ * @private
4032
+ * @name has
4033
+ * @memberOf ListCache
4034
+ * @param {string} key The key of the entry to check.
4035
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
4036
+ */
4037
+ function listCacheHas$1(key) {
4038
+ return assocIndexOf$1(this.__data__, key) > -1;
4039
+ }
4040
+ var _listCacheHas = listCacheHas$1;
4041
+ var assocIndexOf = _assocIndexOf;
4042
+
4043
+ /**
4044
+ * Sets the list cache `key` to `value`.
4045
+ *
4046
+ * @private
4047
+ * @name set
4048
+ * @memberOf ListCache
4049
+ * @param {string} key The key of the value to set.
4050
+ * @param {*} value The value to set.
4051
+ * @returns {Object} Returns the list cache instance.
4052
+ */
4053
+ function listCacheSet$1(key, value) {
4054
+ var data = this.__data__,
4055
+ index = assocIndexOf(data, key);
4056
+ if (index < 0) {
4057
+ ++this.size;
4058
+ data.push([key, value]);
4059
+ } else {
4060
+ data[index][1] = value;
4061
+ }
4062
+ return this;
4063
+ }
4064
+ var _listCacheSet = listCacheSet$1;
4065
+ var listCacheClear = _listCacheClear,
4066
+ listCacheDelete = _listCacheDelete,
4067
+ listCacheGet = _listCacheGet,
4068
+ listCacheHas = _listCacheHas,
4069
+ listCacheSet = _listCacheSet;
4070
+
4071
+ /**
4072
+ * Creates an list cache object.
4073
+ *
4074
+ * @private
4075
+ * @constructor
4076
+ * @param {Array} [entries] The key-value pairs to cache.
4077
+ */
4078
+ function ListCache$1(entries) {
4079
+ var index = -1,
4080
+ length = entries == null ? 0 : entries.length;
4081
+ this.clear();
4082
+ while (++index < length) {
4083
+ var entry = entries[index];
4084
+ this.set(entry[0], entry[1]);
4085
+ }
4086
+ }
4087
+
4088
+ // Add methods to `ListCache`.
4089
+ ListCache$1.prototype.clear = listCacheClear;
4090
+ ListCache$1.prototype['delete'] = listCacheDelete;
4091
+ ListCache$1.prototype.get = listCacheGet;
4092
+ ListCache$1.prototype.has = listCacheHas;
4093
+ ListCache$1.prototype.set = listCacheSet;
4094
+ var _ListCache = ListCache$1;
4095
+ var getNative = _getNative,
4096
+ root = _root;
4097
+
4098
+ /* Built-in method references that are verified to be native. */
4099
+ var Map$2 = getNative(root, 'Map');
4100
+ var _Map = Map$2;
4101
+ var Hash = _Hash,
4102
+ ListCache = _ListCache,
4103
+ Map$1 = _Map;
4104
+
4105
+ /**
4106
+ * Removes all key-value entries from the map.
4107
+ *
4108
+ * @private
4109
+ * @name clear
4110
+ * @memberOf MapCache
4111
+ */
4112
+ function mapCacheClear$1() {
4113
+ this.size = 0;
4114
+ this.__data__ = {
4115
+ 'hash': new Hash(),
4116
+ 'map': new (Map$1 || ListCache)(),
4117
+ 'string': new Hash()
4118
+ };
4119
+ }
4120
+ var _mapCacheClear = mapCacheClear$1;
4121
+
4122
+ /**
4123
+ * Checks if `value` is suitable for use as unique object key.
4124
+ *
4125
+ * @private
4126
+ * @param {*} value The value to check.
4127
+ * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
4128
+ */
4129
+
4130
+ function isKeyable$1(value) {
4131
+ var type = typeof value;
4132
+ return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
4133
+ }
4134
+ var _isKeyable = isKeyable$1;
4135
+ var isKeyable = _isKeyable;
4136
+
4137
+ /**
4138
+ * Gets the data for `map`.
4139
+ *
4140
+ * @private
4141
+ * @param {Object} map The map to query.
4142
+ * @param {string} key The reference key.
4143
+ * @returns {*} Returns the map data.
4144
+ */
4145
+ function getMapData$4(map, key) {
4146
+ var data = map.__data__;
4147
+ return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
4148
+ }
4149
+ var _getMapData = getMapData$4;
4150
+ var getMapData$3 = _getMapData;
4151
+
4152
+ /**
4153
+ * Removes `key` and its value from the map.
4154
+ *
4155
+ * @private
4156
+ * @name delete
4157
+ * @memberOf MapCache
4158
+ * @param {string} key The key of the value to remove.
4159
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
4160
+ */
4161
+ function mapCacheDelete$1(key) {
4162
+ var result = getMapData$3(this, key)['delete'](key);
4163
+ this.size -= result ? 1 : 0;
4164
+ return result;
4165
+ }
4166
+ var _mapCacheDelete = mapCacheDelete$1;
4167
+ var getMapData$2 = _getMapData;
4168
+
4169
+ /**
4170
+ * Gets the map value for `key`.
4171
+ *
4172
+ * @private
4173
+ * @name get
4174
+ * @memberOf MapCache
4175
+ * @param {string} key The key of the value to get.
4176
+ * @returns {*} Returns the entry value.
4177
+ */
4178
+ function mapCacheGet$1(key) {
4179
+ return getMapData$2(this, key).get(key);
4180
+ }
4181
+ var _mapCacheGet = mapCacheGet$1;
4182
+ var getMapData$1 = _getMapData;
4183
+
4184
+ /**
4185
+ * Checks if a map value for `key` exists.
4186
+ *
4187
+ * @private
4188
+ * @name has
4189
+ * @memberOf MapCache
4190
+ * @param {string} key The key of the entry to check.
4191
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
4192
+ */
4193
+ function mapCacheHas$1(key) {
4194
+ return getMapData$1(this, key).has(key);
4195
+ }
4196
+ var _mapCacheHas = mapCacheHas$1;
4197
+ var getMapData = _getMapData;
4198
+
4199
+ /**
4200
+ * Sets the map `key` to `value`.
4201
+ *
4202
+ * @private
4203
+ * @name set
4204
+ * @memberOf MapCache
4205
+ * @param {string} key The key of the value to set.
4206
+ * @param {*} value The value to set.
4207
+ * @returns {Object} Returns the map cache instance.
4208
+ */
4209
+ function mapCacheSet$1(key, value) {
4210
+ var data = getMapData(this, key),
4211
+ size = data.size;
4212
+ data.set(key, value);
4213
+ this.size += data.size == size ? 0 : 1;
4214
+ return this;
4215
+ }
4216
+ var _mapCacheSet = mapCacheSet$1;
4217
+ var mapCacheClear = _mapCacheClear,
4218
+ mapCacheDelete = _mapCacheDelete,
4219
+ mapCacheGet = _mapCacheGet,
4220
+ mapCacheHas = _mapCacheHas,
4221
+ mapCacheSet = _mapCacheSet;
4222
+
4223
+ /**
4224
+ * Creates a map cache object to store key-value pairs.
4225
+ *
4226
+ * @private
4227
+ * @constructor
4228
+ * @param {Array} [entries] The key-value pairs to cache.
4229
+ */
4230
+ function MapCache$1(entries) {
4231
+ var index = -1,
4232
+ length = entries == null ? 0 : entries.length;
4233
+ this.clear();
4234
+ while (++index < length) {
4235
+ var entry = entries[index];
4236
+ this.set(entry[0], entry[1]);
4237
+ }
4238
+ }
4239
+
4240
+ // Add methods to `MapCache`.
4241
+ MapCache$1.prototype.clear = mapCacheClear;
4242
+ MapCache$1.prototype['delete'] = mapCacheDelete;
4243
+ MapCache$1.prototype.get = mapCacheGet;
4244
+ MapCache$1.prototype.has = mapCacheHas;
4245
+ MapCache$1.prototype.set = mapCacheSet;
4246
+ var _MapCache = MapCache$1;
4247
+ var MapCache = _MapCache;
4248
+
4249
+ /** Error message constants. */
4250
+ var FUNC_ERROR_TEXT = 'Expected a function';
4251
+
4252
+ /**
4253
+ * Creates a function that memoizes the result of `func`. If `resolver` is
4254
+ * provided, it determines the cache key for storing the result based on the
4255
+ * arguments provided to the memoized function. By default, the first argument
4256
+ * provided to the memoized function is used as the map cache key. The `func`
4257
+ * is invoked with the `this` binding of the memoized function.
4258
+ *
4259
+ * **Note:** The cache is exposed as the `cache` property on the memoized
4260
+ * function. Its creation may be customized by replacing the `_.memoize.Cache`
4261
+ * constructor with one whose instances implement the
4262
+ * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
4263
+ * method interface of `clear`, `delete`, `get`, `has`, and `set`.
4264
+ *
4265
+ * @static
4266
+ * @memberOf _
4267
+ * @since 0.1.0
4268
+ * @category Function
4269
+ * @param {Function} func The function to have its output memoized.
4270
+ * @param {Function} [resolver] The function to resolve the cache key.
4271
+ * @returns {Function} Returns the new memoized function.
4272
+ * @example
4273
+ *
4274
+ * var object = { 'a': 1, 'b': 2 };
4275
+ * var other = { 'c': 3, 'd': 4 };
4276
+ *
4277
+ * var values = _.memoize(_.values);
4278
+ * values(object);
4279
+ * // => [1, 2]
4280
+ *
4281
+ * values(other);
4282
+ * // => [3, 4]
4283
+ *
4284
+ * object.a = 2;
4285
+ * values(object);
4286
+ * // => [1, 2]
4287
+ *
4288
+ * // Modify the result cache.
4289
+ * values.cache.set(object, ['a', 'b']);
4290
+ * values(object);
4291
+ * // => ['a', 'b']
4292
+ *
4293
+ * // Replace `_.memoize.Cache`.
4294
+ * _.memoize.Cache = WeakMap;
4295
+ */
4296
+ function memoize$1(func, resolver) {
4297
+ if (typeof func != 'function' || resolver != null && typeof resolver != 'function') {
4298
+ throw new TypeError(FUNC_ERROR_TEXT);
4299
+ }
4300
+ var memoized = function () {
4301
+ var args = arguments,
4302
+ key = resolver ? resolver.apply(this, args) : args[0],
4303
+ cache = memoized.cache;
4304
+ if (cache.has(key)) {
4305
+ return cache.get(key);
4306
+ }
4307
+ var result = func.apply(this, args);
4308
+ memoized.cache = cache.set(key, result) || cache;
4309
+ return result;
4310
+ };
4311
+ memoized.cache = new (memoize$1.Cache || MapCache)();
4312
+ return memoized;
4313
+ }
4314
+
4315
+ // Expose `MapCache`.
4316
+ memoize$1.Cache = MapCache;
4317
+ var memoize_1 = memoize$1;
4318
+ var memoize = memoize_1;
4319
+
4320
+ /** Used as the maximum memoize cache size. */
4321
+ var MAX_MEMOIZE_SIZE = 500;
4322
+
4323
+ /**
4324
+ * A specialized version of `_.memoize` which clears the memoized function's
4325
+ * cache when it exceeds `MAX_MEMOIZE_SIZE`.
4326
+ *
4327
+ * @private
4328
+ * @param {Function} func The function to have its output memoized.
4329
+ * @returns {Function} Returns the new memoized function.
4330
+ */
4331
+ function memoizeCapped$1(func) {
4332
+ var result = memoize(func, function (key) {
4333
+ if (cache.size === MAX_MEMOIZE_SIZE) {
4334
+ cache.clear();
4335
+ }
4336
+ return key;
4337
+ });
4338
+ var cache = result.cache;
4339
+ return result;
4340
+ }
4341
+ var _memoizeCapped = memoizeCapped$1;
4342
+ var memoizeCapped = _memoizeCapped;
4343
+
4344
+ /** Used to match property names within property paths. */
4345
+ var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
4346
+
4347
+ /** Used to match backslashes in property paths. */
4348
+ var reEscapeChar = /\\(\\)?/g;
4349
+
4350
+ /**
4351
+ * Converts `string` to a property path array.
4352
+ *
4353
+ * @private
4354
+ * @param {string} string The string to convert.
4355
+ * @returns {Array} Returns the property path array.
4356
+ */
4357
+ var stringToPath$1 = memoizeCapped(function (string) {
4358
+ var result = [];
4359
+ if (string.charCodeAt(0) === 46 /* . */) {
4360
+ result.push('');
4361
+ }
4362
+ string.replace(rePropName, function (match, number, quote, subString) {
4363
+ result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match);
4364
+ });
4365
+ return result;
4366
+ });
4367
+ var _stringToPath = stringToPath$1;
4368
+
4369
+ /**
4370
+ * A specialized version of `_.map` for arrays without support for iteratee
4371
+ * shorthands.
4372
+ *
4373
+ * @private
4374
+ * @param {Array} [array] The array to iterate over.
4375
+ * @param {Function} iteratee The function invoked per iteration.
4376
+ * @returns {Array} Returns the new mapped array.
4377
+ */
4378
+
4379
+ function arrayMap$1(array, iteratee) {
4380
+ var index = -1,
4381
+ length = array == null ? 0 : array.length,
4382
+ result = Array(length);
4383
+ while (++index < length) {
4384
+ result[index] = iteratee(array[index], index, array);
4385
+ }
4386
+ return result;
4387
+ }
4388
+ var _arrayMap = arrayMap$1;
4389
+ var Symbol = _Symbol,
4390
+ arrayMap = _arrayMap,
4391
+ isArray$1 = isArray_1,
4392
+ isSymbol$1 = isSymbol_1;
4393
+
4394
+ /** Used as references for various `Number` constants. */
4395
+ var INFINITY$1 = 1 / 0;
4396
+
4397
+ /** Used to convert symbols to primitives and strings. */
4398
+ var symbolProto = Symbol ? Symbol.prototype : undefined,
4399
+ symbolToString = symbolProto ? symbolProto.toString : undefined;
4400
+
4401
+ /**
4402
+ * The base implementation of `_.toString` which doesn't convert nullish
4403
+ * values to empty strings.
4404
+ *
4405
+ * @private
4406
+ * @param {*} value The value to process.
4407
+ * @returns {string} Returns the string.
4408
+ */
4409
+ function baseToString$1(value) {
4410
+ // Exit early for strings to avoid a performance hit in some environments.
4411
+ if (typeof value == 'string') {
4412
+ return value;
4413
+ }
4414
+ if (isArray$1(value)) {
4415
+ // Recursively convert values (susceptible to call stack limits).
4416
+ return arrayMap(value, baseToString$1) + '';
4417
+ }
4418
+ if (isSymbol$1(value)) {
4419
+ return symbolToString ? symbolToString.call(value) : '';
4420
+ }
4421
+ var result = value + '';
4422
+ return result == '0' && 1 / value == -INFINITY$1 ? '-0' : result;
4423
+ }
4424
+ var _baseToString = baseToString$1;
4425
+ var baseToString = _baseToString;
4426
+
4427
+ /**
4428
+ * Converts `value` to a string. An empty string is returned for `null`
4429
+ * and `undefined` values. The sign of `-0` is preserved.
4430
+ *
4431
+ * @static
4432
+ * @memberOf _
4433
+ * @since 4.0.0
4434
+ * @category Lang
4435
+ * @param {*} value The value to convert.
4436
+ * @returns {string} Returns the converted string.
4437
+ * @example
4438
+ *
4439
+ * _.toString(null);
4440
+ * // => ''
4441
+ *
4442
+ * _.toString(-0);
4443
+ * // => '-0'
4444
+ *
4445
+ * _.toString([1, 2, 3]);
4446
+ * // => '1,2,3'
4447
+ */
4448
+ function toString$1(value) {
4449
+ return value == null ? '' : baseToString(value);
4450
+ }
4451
+ var toString_1 = toString$1;
4452
+ var isArray = isArray_1,
4453
+ isKey = _isKey,
4454
+ stringToPath = _stringToPath,
4455
+ toString = toString_1;
4456
+
4457
+ /**
4458
+ * Casts `value` to a path array if it's not one.
4459
+ *
4460
+ * @private
4461
+ * @param {*} value The value to inspect.
4462
+ * @param {Object} [object] The object to query keys on.
4463
+ * @returns {Array} Returns the cast property path array.
4464
+ */
4465
+ function castPath$1(value, object) {
4466
+ if (isArray(value)) {
4467
+ return value;
4468
+ }
4469
+ return isKey(value, object) ? [value] : stringToPath(toString(value));
4470
+ }
4471
+ var _castPath = castPath$1;
4472
+ var isSymbol = isSymbol_1;
4473
+
4474
+ /** Used as references for various `Number` constants. */
4475
+ var INFINITY = 1 / 0;
4476
+
4477
+ /**
4478
+ * Converts `value` to a string key if it's not a string or symbol.
4479
+ *
4480
+ * @private
4481
+ * @param {*} value The value to inspect.
4482
+ * @returns {string|symbol} Returns the key.
4483
+ */
4484
+ function toKey$1(value) {
4485
+ if (typeof value == 'string' || isSymbol(value)) {
4486
+ return value;
4487
+ }
4488
+ var result = value + '';
4489
+ return result == '0' && 1 / value == -INFINITY ? '-0' : result;
4490
+ }
4491
+ var _toKey = toKey$1;
4492
+ var castPath = _castPath,
4493
+ toKey = _toKey;
4494
+
4495
+ /**
4496
+ * The base implementation of `_.get` without support for default values.
4497
+ *
4498
+ * @private
4499
+ * @param {Object} object The object to query.
4500
+ * @param {Array|string} path The path of the property to get.
4501
+ * @returns {*} Returns the resolved value.
4502
+ */
4503
+ function baseGet$1(object, path) {
4504
+ path = castPath(path, object);
4505
+ var index = 0,
4506
+ length = path.length;
4507
+ while (object != null && index < length) {
4508
+ object = object[toKey(path[index++])];
4509
+ }
4510
+ return index && index == length ? object : undefined;
4511
+ }
4512
+ var _baseGet = baseGet$1;
4513
+ var baseGet = _baseGet;
4514
+
4515
+ /**
4516
+ * Gets the value at `path` of `object`. If the resolved value is
4517
+ * `undefined`, the `defaultValue` is returned in its place.
4518
+ *
4519
+ * @static
4520
+ * @memberOf _
4521
+ * @since 3.7.0
4522
+ * @category Object
4523
+ * @param {Object} object The object to query.
4524
+ * @param {Array|string} path The path of the property to get.
4525
+ * @param {*} [defaultValue] The value returned for `undefined` resolved values.
4526
+ * @returns {*} Returns the resolved value.
4527
+ * @example
4528
+ *
4529
+ * var object = { 'a': [{ 'b': { 'c': 3 } }] };
4530
+ *
4531
+ * _.get(object, 'a[0].b.c');
4532
+ * // => 3
4533
+ *
4534
+ * _.get(object, ['a', '0', 'b', 'c']);
4535
+ * // => 3
4536
+ *
4537
+ * _.get(object, 'a.b.c', 'default');
4538
+ * // => 'default'
4539
+ */
4540
+ function get(object, path, defaultValue) {
4541
+ var result = object == null ? undefined : baseGet(object, path);
4542
+ return result === undefined ? defaultValue : result;
4543
+ }
4544
+ var get_1 = get;
4545
+ var get$1 = /*@__PURE__*/getDefaultExportFromCjs(get_1);
4546
+ const getLanguageParams = (select, document) => {
4547
+ if (!select || !document) {
4548
+ return {};
4549
+ }
4550
+ const selection = select || {};
4551
+ const selectedValue = {};
4552
+ for (const [key, path] of Object.entries(selection)) {
4553
+ let value = get$1(document, path);
4554
+ if (Array.isArray(value)) {
4555
+ value = value.filter(item => typeof item === "object" ? (item == null ? void 0 : item._type) !== "reference" || "_ref" in item : true);
4556
+ }
4557
+ selectedValue[key] = value;
4558
+ }
4559
+ return selectedValue;
4560
+ };
4561
+ const FieldTranslationContext = react.createContext({
4562
+ openFieldTranslation: () => {},
4563
+ translationLoading: false
4564
+ //loadLanguages: () => {},
4565
+ });
4566
+ function useFieldTranslation() {
4567
+ return react.useContext(FieldTranslationContext);
4568
+ }
4569
+ function FieldTranslationProvider(props) {
4570
+ var _a, _b;
4571
+ const {
4572
+ config: assistConfig
4573
+ } = useAiAssistanceConfig();
4574
+ const apiClient = useApiClient(assistConfig.__customApiClient);
4575
+ const config = (_a = assistConfig.translate) == null ? void 0 : _a.field;
4576
+ const {
4577
+ translate: runTranslate
4578
+ } = useTranslate(apiClient);
4579
+ const [dialogOpen, setDialogOpen] = react.useState(false);
4580
+ const [document, setDocument] = react.useState();
4581
+ const [documentSchema, setDocumentSchema] = react.useState();
4582
+ const [languages, setLanguages] = react.useState();
4583
+ const [fromLanguage, setFromLanguage] = react.useState(void 0);
4584
+ const [toLanguages, setToLanguages] = react.useState(void 0);
4585
+ const [translationMap, setTranslationMap] = react.useState();
4586
+ const close = react.useCallback(() => {
4587
+ setDialogOpen(false);
4588
+ setLanguages(void 0);
4589
+ setDocument(void 0);
4590
+ setDocument(void 0);
4591
+ }, []);
4592
+ const languageClient = sanity.useClient({
4593
+ apiVersion: (_b = config == null ? void 0 : config.apiVersion) != null ? _b : "2022-11-27"
4594
+ });
4595
+ const documentId = document == null ? void 0 : document._id;
4596
+ const id = react.useId();
4597
+ const selectFromLanguage = react.useCallback((from, languages2, document2, documentSchema2) => {
4598
+ var _a2, _b2;
4599
+ setFromLanguage(from);
4600
+ if (!document2 || !documentSchema2 || !languages2) {
4601
+ setTranslationMap(void 0);
4602
+ return;
4603
+ }
4604
+ const to = languages2.filter(l => l.id !== (from == null ? void 0 : from.id));
4605
+ setToLanguages(to);
4606
+ const fromId = from == null ? void 0 : from.id;
4607
+ const toIds = (_a2 = to == null ? void 0 : to.map(l => l.id)) != null ? _a2 : [];
4608
+ const docMembers = getDocumentMembersFlat(document2, documentSchema2);
4609
+ if (fromId && (toIds == null ? void 0 : toIds.length)) {
4610
+ const transMap = getTranslationMap(documentSchema2, docMembers, fromId, toIds, (_b2 = config == null ? void 0 : config.translationOutputs) != null ? _b2 : defaultLanguageOutputs);
4611
+ setTranslationMap(transMap);
4612
+ } else {
4613
+ setTranslationMap(void 0);
4614
+ }
4615
+ }, [config]);
4616
+ const toggleToLanguage = react.useCallback((toggledLang, toLanguages2, languages2) => {
4617
+ if (!languages2) {
4618
+ return;
4619
+ }
4620
+ const wasSelected = !!(toLanguages2 == null ? void 0 : toLanguages2.find(l => l.id === toggledLang.id));
4621
+ const newToLangs = languages2.filter(anyLang => !!(toLanguages2 == null ? void 0 : toLanguages2.find(selectedLang => toggledLang.id !== selectedLang.id && selectedLang.id === anyLang.id)) || toggledLang.id === anyLang.id && !wasSelected);
4622
+ setToLanguages(newToLangs);
4623
+ }, []);
4624
+ const openFieldTranslation = react.useCallback(async _ref11 => {
4625
+ let {
4626
+ document: document2,
4627
+ documentSchema: documentSchema2
4628
+ } = _ref11;
4629
+ setDialogOpen(true);
4630
+ const languageParams = getLanguageParams(config == null ? void 0 : config.selectLanguageParams, document2);
4631
+ const languages2 = await (typeof (config == null ? void 0 : config.languages) === "function" ? config == null ? void 0 : config.languages(languageClient, languageParams) : Promise.resolve(config == null ? void 0 : config.languages));
4632
+ setLanguages(languages2);
4633
+ setDocument(document2);
4634
+ setDocumentSchema(documentSchema2);
4635
+ const fromLanguage2 = languages2 == null ? void 0 : languages2[0];
4636
+ if (fromLanguage2) {
4637
+ selectFromLanguage(fromLanguage2, languages2, document2, documentSchema2);
4638
+ } else {
4639
+ console.error("No languages available for selected language params", languageParams);
4640
+ }
4641
+ }, [selectFromLanguage, config, languageClient]);
4642
+ const contextValue = react.useMemo(() => {
4643
+ return {
4644
+ openFieldTranslation,
4645
+ translationLoading: false
4646
+ };
4647
+ }, [openFieldTranslation]);
4648
+ const runDisabled = !fromLanguage || !(toLanguages == null ? void 0 : toLanguages.length) || !(translationMap == null ? void 0 : translationMap.length) || !documentId;
4649
+ const onRunTranslation = react.useCallback(() => {
4650
+ if (translationMap && documentId) {
4651
+ runTranslate({
4652
+ documentId,
4653
+ fieldLanguageMap: translationMap.map(map => ({
4654
+ ...map,
4655
+ // eslint-disable-next-line max-nested-callbacks
4656
+ outputs: map.outputs.filter(out => !!(toLanguages == null ? void 0 : toLanguages.find(l => l.id === out.id)))
4657
+ }))
4658
+ });
4659
+ }
4660
+ close();
4661
+ }, [translationMap, documentId, runTranslate, close, toLanguages]);
4662
+ const runButton = /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
4663
+ text: "Translate",
4664
+ tone: "primary",
4665
+ icon: icons.PlayIcon,
4666
+ style: {
4667
+ width: "100%"
4668
+ },
4669
+ disabled: runDisabled,
4670
+ onClick: onRunTranslation
4671
+ });
4672
+ return /* @__PURE__ */jsxRuntime.jsxs(FieldTranslationContext.Provider, {
4673
+ value: contextValue,
4674
+ children: [dialogOpen ? /* @__PURE__ */jsxRuntime.jsx(ui.Dialog, {
4675
+ id,
4676
+ width: 1,
4677
+ open: dialogOpen,
4678
+ onClose: close,
4679
+ header: "Translate fields",
4680
+ footer: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
4681
+ justify: "space-between",
4682
+ padding: 2,
4683
+ flex: 1,
4684
+ children: runDisabled ? /* @__PURE__ */jsxRuntime.jsx(ui.Tooltip, {
4685
+ content: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
4686
+ padding: 2,
4687
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
4688
+ children: "Nothing to translate."
4689
+ })
4690
+ }),
4691
+ placement: "top",
4692
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
4693
+ flex: 1,
4694
+ children: runButton
4695
+ })
4696
+ }) : runButton
4697
+ }),
4698
+ children: languages ? /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
4699
+ padding: 4,
4700
+ gap: 5,
4701
+ align: "flex-start",
4702
+ justify: "center",
4703
+ children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
4704
+ space: 2,
4705
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
4706
+ marginBottom: 2,
4707
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
4708
+ weight: "semibold",
4709
+ children: "From"
4710
+ })
4711
+ }), languages == null ? void 0 : languages.map(l => {
4712
+ var _a2;
4713
+ return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
4714
+ gap: 3,
4715
+ align: "center",
4716
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Radio, {
4717
+ name: "fromLang",
4718
+ value: l.id,
4719
+ checked: l.id === (fromLanguage == null ? void 0 : fromLanguage.id),
4720
+ onClick: () => selectFromLanguage(l, languages, document, documentSchema)
4721
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
4722
+ children: (_a2 = l.title) != null ? _a2 : l.id
4723
+ })]
4724
+ }, l.id);
4725
+ })]
4726
+ }), /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
4727
+ space: 2,
4728
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
4729
+ marginBottom: 2,
4730
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
4731
+ weight: "semibold",
4732
+ children: "To"
4733
+ })
4734
+ }), languages == null ? void 0 : languages.filter(l => l.id !== (fromLanguage == null ? void 0 : fromLanguage.id)).map(l => {
4735
+ var _a2;
4736
+ return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
4737
+ gap: 3,
4738
+ align: "center",
4739
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Checkbox, {
4740
+ name: "toLang",
4741
+ value: l.id,
4742
+ checked: !!(toLanguages == null ? void 0 : toLanguages.find(tl => tl.id === l.id)),
4743
+ onClick: () => toggleToLanguage(l, toLanguages, languages),
4744
+ disabled: !(translationMap == null ? void 0 : translationMap.find(tm => tm.outputs.find(o => o.id === l.id)))
4745
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
4746
+ children: (_a2 = l.title) != null ? _a2 : l.id
4747
+ })]
4748
+ }, l.id);
4749
+ })]
4750
+ })]
4751
+ }) : /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
4752
+ padding: 4,
4753
+ gap: 2,
4754
+ align: "flex-start",
4755
+ justify: "center",
4756
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
4757
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {})
4758
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
4759
+ children: "Loading languages..."
4760
+ })]
4761
+ })
4762
+ }) : null, props.children]
4763
+ });
4764
+ }
3214
4765
  function AssistLayout(props) {
3215
4766
  var _a;
3216
4767
  const [connectors, setConnectors] = react.useState([]);
@@ -3218,14 +4769,16 @@ function AssistLayout(props) {
3218
4769
  return /* @__PURE__ */jsxRuntime.jsxs(AiAssistanceConfigProvider, {
3219
4770
  config: props.config,
3220
4771
  children: [migrate ? /* @__PURE__ */jsxRuntime.jsx(AlphaMigration, {}) : null, /* @__PURE__ */jsxRuntime.jsx(RunInstructionProvider, {
3221
- children: /* @__PURE__ */jsxRuntime.jsxs(ConnectorsProvider, {
3222
- onConnectorsChange: setConnectors,
3223
- children: [props.renderDefault(props), /* @__PURE__ */jsxRuntime.jsx(ui.ThemeProvider, {
3224
- tone: "default",
3225
- children: /* @__PURE__ */jsxRuntime.jsx(AssistConnectorsOverlay, {
3226
- connectors
3227
- })
3228
- })]
4772
+ children: /* @__PURE__ */jsxRuntime.jsx(FieldTranslationProvider, {
4773
+ children: /* @__PURE__ */jsxRuntime.jsxs(ConnectorsProvider, {
4774
+ onConnectorsChange: setConnectors,
4775
+ children: [props.renderDefault(props), /* @__PURE__ */jsxRuntime.jsx(ui.ThemeProvider, {
4776
+ tone: "default",
4777
+ children: /* @__PURE__ */jsxRuntime.jsx(AssistConnectorsOverlay, {
4778
+ connectors
4779
+ })
4780
+ })]
4781
+ })
3229
4782
  })
3230
4783
  })]
3231
4784
  });
@@ -3321,6 +4874,7 @@ function AssistFormBlock(props) {
3321
4874
  _key: key
3322
4875
  }));
3323
4876
  }, [onChange, key]);
4877
+ const singlePresence = presence[0];
3324
4878
  return /* @__PURE__ */jsxRuntime.jsx(ErrorWrapper, {
3325
4879
  onChange: localOnChange,
3326
4880
  children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
@@ -3329,9 +4883,9 @@ function AssistFormBlock(props) {
3329
4883
  children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
3330
4884
  flex: 1,
3331
4885
  children: props.renderDefault(props)
3332
- }), presence.map(pre => /* @__PURE__ */jsxRuntime.jsx(AiFieldPresence, {
3333
- presence: pre
3334
- }, pre.lastActiveAt))]
4886
+ }), singlePresence && /* @__PURE__ */jsxRuntime.jsx(AiFieldPresence, {
4887
+ presence: singlePresence
4888
+ })]
3335
4889
  })
3336
4890
  });
3337
4891
  }
@@ -3375,16 +4929,24 @@ function InstructionInput(props) {
3375
4929
  ...props
3376
4930
  }), /* @__PURE__ */jsxRuntime.jsx(ShareField, {
3377
4931
  ...props
3378
- }), /* @__PURE__ */jsxRuntime.jsx(PromptField, {
4932
+ }), /* @__PURE__ */jsxRuntime.jsx(ObjectMember, {
4933
+ fieldName: "prompt",
4934
+ ...props
4935
+ }), /* @__PURE__ */jsxRuntime.jsx(ObjectMember, {
4936
+ fieldName: "output",
3379
4937
  ...props
3380
4938
  })]
3381
4939
  });
3382
4940
  }
3383
- function PromptField(props) {
3384
- const promptMember = findFieldMember(props.members, "prompt");
3385
- return promptMember ? /* @__PURE__ */jsxRuntime.jsx(sanity.ObjectInputMember, {
4941
+ function ObjectMember(_ref12) {
4942
+ let {
4943
+ fieldName,
4944
+ ...props
4945
+ } = _ref12;
4946
+ const member = findFieldMember(props.members, fieldName);
4947
+ return member ? /* @__PURE__ */jsxRuntime.jsx(sanity.ObjectInputMember, {
3386
4948
  ...props,
3387
- member: promptMember
4949
+ member
3388
4950
  }) : null;
3389
4951
  }
3390
4952
  const NONE = [];
@@ -3519,8 +5081,8 @@ function IconInput(props) {
3519
5081
  onChange
3520
5082
  } = props;
3521
5083
  const id = react.useId();
3522
- const items = react.useMemo(() => Object.entries(icons.icons).map(_ref10 => {
3523
- let [key, icon] = _ref10;
5084
+ const items = react.useMemo(() => Object.entries(icons.icons).map(_ref13 => {
5085
+ let [key, icon] = _ref13;
3524
5086
  return /* @__PURE__ */jsxRuntime.jsx(IconItem, {
3525
5087
  iconKey: key,
3526
5088
  icon,
@@ -3548,12 +5110,12 @@ function IconInput(props) {
3548
5110
  }
3549
5111
  });
3550
5112
  }
3551
- function IconItem(_ref11) {
5113
+ function IconItem(_ref14) {
3552
5114
  let {
3553
5115
  icon,
3554
5116
  iconKey: key,
3555
5117
  onChange
3556
- } = _ref11;
5118
+ } = _ref14;
3557
5119
  const onClick = react.useCallback(() => onChange(sanity.set(key)), [onChange, key]);
3558
5120
  return /* @__PURE__ */jsxRuntime.jsx(ui.MenuItem, {
3559
5121
  icon,
@@ -3564,8 +5126,8 @@ function IconItem(_ref11) {
3564
5126
  }
3565
5127
  function getIcon(iconName) {
3566
5128
  var _a, _b;
3567
- return (_b = (_a = Object.entries(icons.icons).find(_ref12 => {
3568
- let [key] = _ref12;
5129
+ return (_b = (_a = Object.entries(icons.icons).find(_ref15 => {
5130
+ let [key] = _ref15;
3569
5131
  return key === iconName;
3570
5132
  })) == null ? void 0 : _a[1]) != null ? _b : icons.icons.sparkles;
3571
5133
  }
@@ -3724,11 +5286,11 @@ const contextDocumentSchema = sanity.defineType({
3724
5286
  title: "title",
3725
5287
  context: "context"
3726
5288
  },
3727
- prepare(_ref13) {
5289
+ prepare(_ref16) {
3728
5290
  let {
3729
5291
  title,
3730
5292
  context
3731
- } = _ref13;
5293
+ } = _ref16;
3732
5294
  var _a;
3733
5295
  const text = context == null ? void 0 : context.flatMap(block => block == null ? void 0 : block.children).flatMap(child => {
3734
5296
  var _a2;
@@ -3814,6 +5376,200 @@ function InstructionsArrayField(props) {
3814
5376
  title: " "
3815
5377
  });
3816
5378
  }
5379
+ function InstructionOutputField(props) {
5380
+ var _a;
5381
+ const {
5382
+ fieldSchema
5383
+ } = (_a = react.useContext(SelectedFieldContext)) != null ? _a : {};
5384
+ if (!fieldSchema || !(sanity.isObjectSchemaType(fieldSchema) || sanity.isArrayOfObjectsSchemaType(fieldSchema))) {
5385
+ return null;
5386
+ }
5387
+ return /* @__PURE__ */jsxRuntime.jsx(EnabledOutputField, {
5388
+ ...props,
5389
+ fieldSchema,
5390
+ children: props.children
5391
+ });
5392
+ }
5393
+ function EnabledOutputField(_ref17) {
5394
+ let {
5395
+ fieldSchema,
5396
+ ...props
5397
+ } = _ref17;
5398
+ var _a;
5399
+ const [open, setOpen] = react.useState(!!((_a = props.value) == null ? void 0 : _a.length));
5400
+ const onExpand = react.useCallback(() => setOpen(true), []);
5401
+ const onCollapse = react.useCallback(() => setOpen(false), []);
5402
+ return props.renderDefault({
5403
+ ...props,
5404
+ collapsible: true,
5405
+ onExpand,
5406
+ onCollapse,
5407
+ collapsed: !open,
5408
+ level: 1,
5409
+ title: sanity.isObjectSchemaType(fieldSchema) ? "Allowed fields" : "Allowed types"
5410
+ });
5411
+ }
5412
+ function InstructionOutputInput(props) {
5413
+ var _a;
5414
+ const {
5415
+ fieldSchema
5416
+ } = (_a = react.useContext(SelectedFieldContext)) != null ? _a : {};
5417
+ if (!fieldSchema) {
5418
+ return null;
5419
+ }
5420
+ if (sanity.isObjectSchemaType(fieldSchema)) {
5421
+ return /* @__PURE__ */jsxRuntime.jsx(ObjectOutputInput, {
5422
+ ...props,
5423
+ fieldSchema
5424
+ });
5425
+ }
5426
+ if (sanity.isArrayOfObjectsSchemaType(fieldSchema)) {
5427
+ return /* @__PURE__ */jsxRuntime.jsx(ArrayOutputInput, {
5428
+ ...props,
5429
+ fieldSchema
5430
+ });
5431
+ }
5432
+ return null;
5433
+ }
5434
+ function useEmptySelectAllValue(value, allowedValues, onChange) {
5435
+ react.useEffect(() => {
5436
+ var _a, _b;
5437
+ const validValues = value == null ? void 0 : value.filter(v => allowedValues.find(f => f.name === (v._type === outputFieldTypeName ? v.relativePath : v.type)));
5438
+ const valueLength = (_a = value == null ? void 0 : value.length) != null ? _a : 0;
5439
+ const validLength = (_b = validValues == null ? void 0 : validValues.length) != null ? _b : 0;
5440
+ if (!validLength && valueLength || validLength >= allowedValues.length) {
5441
+ onChange(sanity.PatchEvent.from([sanity.unset()]));
5442
+ }
5443
+ }, [allowedValues, value, onChange]);
5444
+ }
5445
+ function ObjectOutputInput(_ref18) {
5446
+ let {
5447
+ fieldSchema,
5448
+ ...props
5449
+ } = _ref18;
5450
+ const {
5451
+ value,
5452
+ onChange
5453
+ } = props;
5454
+ const fields = react.useMemo(() => fieldSchema.fields.filter(field => isAssistSupported(field.type)), [fieldSchema.fields]);
5455
+ useEmptySelectAllValue(value, fields, onChange);
5456
+ const onSelectChange = react.useCallback((checked, selectedValue) => {
5457
+ if (checked) {
5458
+ if (value == null ? void 0 : value.length) {
5459
+ onChange(sanity.PatchEvent.from(sanity.unset([{
5460
+ _key: selectedValue
5461
+ }])));
5462
+ } else {
5463
+ const items = fields.filter(f => f.name !== selectedValue).map(field => sanity.typed({
5464
+ _key: field.name,
5465
+ _type: "sanity.assist.output.field",
5466
+ relativePath: field.name
5467
+ }));
5468
+ onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert(items, "after", [-1])]));
5469
+ }
5470
+ } else {
5471
+ const patchValue = {
5472
+ _key: selectedValue,
5473
+ _type: "sanity.assist.output.field",
5474
+ relativePath: selectedValue
5475
+ };
5476
+ onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert([patchValue], "after", [-1])]));
5477
+ }
5478
+ }, [onChange, value, fields]);
5479
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
5480
+ space: 2,
5481
+ children: fields.map(field => {
5482
+ var _a;
5483
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
5484
+ align: "center",
5485
+ gap: 2,
5486
+ children: /* @__PURE__ */jsxRuntime.jsx(Selectable, {
5487
+ value: field.name,
5488
+ title: (_a = field.type.title) != null ? _a : field.name,
5489
+ arrayValue: value,
5490
+ onChange: onSelectChange
5491
+ })
5492
+ }, field.name);
5493
+ })
5494
+ });
5495
+ }
5496
+ function ArrayOutputInput(_ref19) {
5497
+ let {
5498
+ fieldSchema,
5499
+ ...props
5500
+ } = _ref19;
5501
+ const {
5502
+ value,
5503
+ onChange
5504
+ } = props;
5505
+ const ofItems = react.useMemo(() => fieldSchema.of.filter(itemType => isAssistSupported(itemType)), [fieldSchema.of]);
5506
+ useEmptySelectAllValue(value, ofItems, onChange);
5507
+ const onSelectChange = react.useCallback((checked, selectedValue) => {
5508
+ if (checked) {
5509
+ if (value == null ? void 0 : value.length) {
5510
+ onChange(sanity.PatchEvent.from(sanity.unset([{
5511
+ _key: selectedValue
5512
+ }])));
5513
+ } else {
5514
+ const items = ofItems.filter(f => f.name !== selectedValue).map(field => sanity.typed({
5515
+ _key: field.name,
5516
+ _type: "sanity.assist.output.type",
5517
+ type: field.name
5518
+ }));
5519
+ onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert(items, "after", [-1])]));
5520
+ }
5521
+ } else {
5522
+ const patchValue = {
5523
+ _key: selectedValue,
5524
+ _type: "sanity.assist.output.type",
5525
+ type: selectedValue
5526
+ };
5527
+ onChange(sanity.PatchEvent.from([sanity.setIfMissing([]), sanity.insert([patchValue], "after", [-1])]));
5528
+ }
5529
+ }, [onChange, value, ofItems]);
5530
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
5531
+ space: 2,
5532
+ children: ofItems.map(itemType => {
5533
+ var _a;
5534
+ return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
5535
+ children: /* @__PURE__ */jsxRuntime.jsx(Selectable, {
5536
+ value: itemType.name,
5537
+ title: isType(itemType, "block") ? "Text" : (_a = itemType.title) != null ? _a : itemType.name,
5538
+ arrayValue: value,
5539
+ onChange: onSelectChange
5540
+ })
5541
+ }, itemType.name);
5542
+ })
5543
+ });
5544
+ }
5545
+ function Selectable(_ref20) {
5546
+ let {
5547
+ title,
5548
+ arrayValue,
5549
+ value,
5550
+ onChange
5551
+ } = _ref20;
5552
+ const checked = !(arrayValue == null ? void 0 : arrayValue.length) || !!(arrayValue == null ? void 0 : arrayValue.find(v => v._key === value));
5553
+ const handleChange = react.useCallback(() => onChange(checked, value), [onChange, checked, value]);
5554
+ return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
5555
+ gap: 2,
5556
+ align: "flex-start",
5557
+ children: [/* @__PURE__ */jsxRuntime.jsx(ui.Checkbox, {
5558
+ checked,
5559
+ onChange: handleChange
5560
+ }), /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
5561
+ marginTop: 1,
5562
+ onClick: () => handleChange,
5563
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
5564
+ style: {
5565
+ cursor: "default"
5566
+ },
5567
+ size: 1,
5568
+ children: title
5569
+ })
5570
+ })]
5571
+ });
5572
+ }
3817
5573
  const fieldReference = sanity.defineType({
3818
5574
  type: "object",
3819
5575
  name: fieldReferenceTypeName,
@@ -3857,10 +5613,10 @@ const fieldReference = sanity.defineType({
3857
5613
  select: {
3858
5614
  path: "path"
3859
5615
  },
3860
- prepare(_ref14) {
5616
+ prepare(_ref21) {
3861
5617
  let {
3862
5618
  path
3863
- } = _ref14;
5619
+ } = _ref21;
3864
5620
  return {
3865
5621
  title: path,
3866
5622
  path,
@@ -3987,7 +5743,6 @@ const prompt = sanity.defineType({
3987
5743
  type: userInput.name,
3988
5744
  }),*/]
3989
5745
  });
3990
-
3991
5746
  const instruction = sanity.defineType({
3992
5747
  type: "object",
3993
5748
  name: instructionTypeName,
@@ -4006,12 +5761,12 @@ const instruction = sanity.defineType({
4006
5761
  title: "title",
4007
5762
  userId: "userId"
4008
5763
  },
4009
- prepare: _ref15 => {
5764
+ prepare: _ref22 => {
4010
5765
  let {
4011
5766
  icon,
4012
5767
  title,
4013
5768
  userId
4014
- } = _ref15;
5769
+ } = _ref22;
4015
5770
  return {
4016
5771
  title,
4017
5772
  icon: icon ? icons.icons[icon] : icons.SparklesIcon,
@@ -4116,6 +5871,33 @@ const instruction = sanity.defineType({
4116
5871
  var _a, _b;
4117
5872
  return (_b = (_a = context.currentUser) == null ? void 0 : _a.id) != null ? _b : "";
4118
5873
  }
5874
+ }), sanity.defineField({
5875
+ type: "array",
5876
+ name: "output",
5877
+ title: "Output filter",
5878
+ components: {
5879
+ input: InstructionOutputInput,
5880
+ field: InstructionOutputField
5881
+ },
5882
+ of: [sanity.defineArrayMember({
5883
+ type: "object",
5884
+ name: outputFieldTypeName,
5885
+ title: "Output field",
5886
+ fields: [{
5887
+ type: "string",
5888
+ name: "path",
5889
+ title: "Path"
5890
+ }]
5891
+ }), sanity.defineArrayMember({
5892
+ type: "object",
5893
+ name: outputTypeTypeName,
5894
+ title: "Output type",
5895
+ fields: [{
5896
+ type: "string",
5897
+ name: "type",
5898
+ title: "Type"
5899
+ }]
5900
+ })]
4119
5901
  })]
4120
5902
  });
4121
5903
  const fieldInstructions = sanity.defineType({
@@ -4378,7 +6160,7 @@ function ImageContextProvider(props) {
4378
6160
  children: props.renderDefault(props)
4379
6161
  });
4380
6162
  }
4381
- function node$1(node2) {
6163
+ function node$2(node2) {
4382
6164
  return node2;
4383
6165
  }
4384
6166
  const generateCaptionsActions = {
@@ -4399,7 +6181,7 @@ const generateCaptionsActions = {
4399
6181
  documentId
4400
6182
  } = useAssistDocumentContext();
4401
6183
  return react.useMemo(() => {
4402
- return node$1({
6184
+ return node$2({
4403
6185
  type: "action",
4404
6186
  icon: loading ? () => /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
4405
6187
  style: {
@@ -4430,6 +6212,109 @@ const generateCaptionsActions = {
4430
6212
  return void 0;
4431
6213
  }
4432
6214
  };
6215
+ function node$1(node2) {
6216
+ return node2;
6217
+ }
6218
+ const translateActions = {
6219
+ name: "sanity-assist-translate",
6220
+ useAction(props) {
6221
+ var _a, _b, _c, _d, _e, _f, _g;
6222
+ const {
6223
+ config
6224
+ } = useAiAssistanceConfig();
6225
+ const apiClient = useApiClient(config == null ? void 0 : config.__customApiClient);
6226
+ const isDocumentLevel = props.path.length === 0;
6227
+ const {
6228
+ schemaType,
6229
+ documentId,
6230
+ documentIsAssistable
6231
+ } = props;
6232
+ const fieldTransEnabled = (_c = (_b = (_a = config.translate) == null ? void 0 : _a.field) == null ? void 0 : _b.documentTypes) == null ? void 0 : _c.includes(schemaType.name);
6233
+ const docTransTypes = (_e = (_d = config.translate) == null ? void 0 : _d.document) == null ? void 0 : _e.documentTypes;
6234
+ const documentTranslationEnabled = isDocumentLevel && (!docTransTypes && isAssistSupported(schemaType) || (docTransTypes == null ? void 0 : docTransTypes.includes(schemaType.name)));
6235
+ if (documentTranslationEnabled || fieldTransEnabled) {
6236
+ const {
6237
+ value: documentValue,
6238
+ onChange: documentOnChange
6239
+ } = desk.useDocumentPane();
6240
+ const docRef = react.useRef(documentValue);
6241
+ const translationApi = useTranslate(apiClient);
6242
+ const translate = useDraftDelayedTask({
6243
+ documentOnChange,
6244
+ isDocAssistable: documentIsAssistable != null ? documentIsAssistable : false,
6245
+ task: translationApi.translate
6246
+ });
6247
+ docRef.current = documentValue;
6248
+ const languagePath = (_g = (_f = config.translate) == null ? void 0 : _f.document) == null ? void 0 : _g.languageField;
6249
+ const translateDocumentAction = react.useMemo(() => languagePath && documentTranslationEnabled ? node$1({
6250
+ type: "action",
6251
+ icon: translationApi.loading ? () => /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
6252
+ style: {
6253
+ height: 17
6254
+ },
6255
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {
6256
+ style: {
6257
+ transform: "translateY(6px)"
6258
+ }
6259
+ })
6260
+ }) : icons.TranslateIcon,
6261
+ title: "Translate document",
6262
+ onAction: () => {
6263
+ if (translationApi.loading || !languagePath || !documentId) {
6264
+ return;
6265
+ }
6266
+ translate({
6267
+ languagePath,
6268
+ documentId: documentId != null ? documentId : ""
6269
+ });
6270
+ },
6271
+ renderAsButton: true,
6272
+ disabled: translationApi.loading
6273
+ }) : void 0, [languagePath, translate, documentId, translationApi.loading, documentTranslationEnabled]);
6274
+ const fieldTranslate = useFieldTranslation();
6275
+ const openFieldTranslation = useDraftDelayedTask({
6276
+ documentOnChange,
6277
+ isDocAssistable: documentIsAssistable != null ? documentIsAssistable : false,
6278
+ task: fieldTranslate.openFieldTranslation
6279
+ });
6280
+ const translateFieldsAction = react.useMemo(() => fieldTransEnabled ? node$1({
6281
+ type: "action",
6282
+ icon: fieldTranslate.translationLoading ? () => /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
6283
+ style: {
6284
+ height: 17
6285
+ },
6286
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {
6287
+ style: {
6288
+ transform: "translateY(6px)"
6289
+ }
6290
+ })
6291
+ }) : icons.TranslateIcon,
6292
+ title: "Translate fields",
6293
+ onAction: () => {
6294
+ if (fieldTranslate.translationLoading || !documentId) {
6295
+ return;
6296
+ }
6297
+ openFieldTranslation({
6298
+ document: docRef.current,
6299
+ documentSchema: schemaType
6300
+ });
6301
+ },
6302
+ renderAsButton: true,
6303
+ disabled: fieldTranslate.translationLoading
6304
+ }) : void 0, [openFieldTranslation, schemaType, documentId, fieldTranslate.translationLoading, fieldTransEnabled]);
6305
+ return react.useMemo(() => {
6306
+ return node$1({
6307
+ type: "group",
6308
+ icon: () => null,
6309
+ title: "Translate",
6310
+ children: [translateDocumentAction, translateFieldsAction].filter(c => !!c),
6311
+ expanded: true
6312
+ });
6313
+ }, [translateDocumentAction, translateFieldsAction]);
6314
+ }
6315
+ return void 0;
6316
+ }
6317
+ };
4433
6318
  function node(node2) {
4434
6319
  return node2;
4435
6320
  }
@@ -4450,7 +6335,8 @@ const assistFieldActions = {
4450
6335
  documentOnChange,
4451
6336
  documentSchemaType,
4452
6337
  documentId,
4453
- selectedPath
6338
+ selectedPath,
6339
+ assistableDocumentId
4454
6340
  } =
4455
6341
  // document field actions do not have access to the document context
4456
6342
  // conditional hook _should_ be safe here since the logical path will be stable
@@ -4485,6 +6371,11 @@ const assistFieldActions = {
4485
6371
  const isPathSelected = pathKey === selectedPath;
4486
6372
  const isSelected = isInspectorOpen && isPathSelected;
4487
6373
  const imageCaptionAction = generateCaptionsActions.useAction(props);
6374
+ const translateAction = translateActions.useAction(sanity.typed({
6375
+ ...props,
6376
+ documentId: assistableDocumentId,
6377
+ documentIsAssistable
6378
+ }));
4488
6379
  const manageInstructions = react.useCallback(() => isSelected ? closeInspector(aiInspectorId) : openInspector(aiInspectorId, {
4489
6380
  [fieldPathParam]: pathKey,
4490
6381
  [instructionParam]: void 0
@@ -4511,7 +6402,7 @@ const assistFieldActions = {
4511
6402
  }, [fieldAssist == null ? void 0 : fieldAssist.instructions]);
4512
6403
  const instructions = react.useMemo(() => [...privateInstructions, ...sharedInstructions], [privateInstructions, sharedInstructions]);
4513
6404
  const runInstructionsGroup = react.useMemo(() => {
4514
- return (instructions == null ? void 0 : instructions.length) || imageCaptionAction ? node({
6405
+ return (instructions == null ? void 0 : instructions.length) || imageCaptionAction || translateAction ? node({
4515
6406
  type: "group",
4516
6407
  icon: () => null,
4517
6408
  title: "Run instructions",
@@ -4522,10 +6413,10 @@ const assistFieldActions = {
4522
6413
  hidden: isHidden,
4523
6414
  documentIsNew: !!documentIsNew,
4524
6415
  assistSupported
4525
- }))), imageCaptionAction].filter(Boolean),
6416
+ }))), imageCaptionAction].filter(a => !!a),
4526
6417
  expanded: true
4527
6418
  }) : void 0;
4528
- }, [instructions, currentUser == null ? void 0 : currentUser.id, onInstructionAction, isHidden, documentIsNew, assistSupported, imageCaptionAction]);
6419
+ }, [instructions, currentUser == null ? void 0 : currentUser.id, onInstructionAction, isHidden, documentIsNew, assistSupported, imageCaptionAction, translateAction]);
4529
6420
  const instructionsLength = (instructions == null ? void 0 : instructions.length) || 0;
4530
6421
  const manageInstructionsItem = react.useMemo(() => node({
4531
6422
  type: "action",
@@ -4538,13 +6429,13 @@ const assistFieldActions = {
4538
6429
  type: "group",
4539
6430
  icon: icons.SparklesIcon,
4540
6431
  title: pluginTitleShort,
4541
- children: [runInstructionsGroup, assistSupported && manageInstructionsItem].filter(c => !!c),
6432
+ children: [runInstructionsGroup, translateAction, assistSupported && manageInstructionsItem].filter(c => !!c),
4542
6433
  expanded: false,
4543
6434
  renderAsButton: true,
4544
- hidden: !assistSupported && !imageCaptionAction
6435
+ hidden: !assistSupported && !imageCaptionAction && !translateAction
4545
6436
  }), [
4546
6437
  //documentIsNew,
4547
- runInstructionsGroup, manageInstructionsItem, assistSupported, imageCaptionAction]);
6438
+ runInstructionsGroup, manageInstructionsItem, assistSupported, imageCaptionAction, translateAction]);
4548
6439
  const emptyAction = react.useMemo(() => node({
4549
6440
  type: "action",
4550
6441
  hidden: !assistSupported,
@@ -4554,7 +6445,7 @@ const assistFieldActions = {
4554
6445
  title: pluginTitleShort,
4555
6446
  selected: isSelected
4556
6447
  }), [assistSupported, manageInstructions, isSelected]);
4557
- if (instructionsLength === 0 && !imageCaptionAction) {
6448
+ if (instructionsLength === 0 && !imageCaptionAction && !translateAction) {
4558
6449
  return emptyAction;
4559
6450
  }
4560
6451
  return group;
@@ -4667,11 +6558,11 @@ function AssistDocumentInputWrapper(props) {
4667
6558
  documentId
4668
6559
  });
4669
6560
  }
4670
- function AssistDocumentInput(_ref16) {
6561
+ function AssistDocumentInput(_ref23) {
4671
6562
  let {
4672
6563
  documentId,
4673
6564
  ...props
4674
- } = _ref16;
6565
+ } = _ref23;
4675
6566
  useInstructionToaster(documentId, props.schemaType);
4676
6567
  return /* @__PURE__ */jsxRuntime.jsx(FirstAssistedPathProvider, {
4677
6568
  members: props.members,
@@ -4716,11 +6607,11 @@ function AssistDocumentPresence(props) {
4716
6607
  const anyPresence2 = (_b = (_a = assistDocument == null ? void 0 : assistDocument.tasks) == null ? void 0 : _a.filter(run => !run.ended && !run.reason)) == null ? void 0 : _b.flatMap(run => {
4717
6608
  var _a2;
4718
6609
  return (_a2 = run.presence) != null ? _a2 : [];
4719
- }).find(f => f.started && /* @__PURE__ */new Date().getTime() - new Date(f.started).getTime() < 3e4);
6610
+ }).find(f => f.started && ( /* @__PURE__ */new Date()).getTime() - new Date(f.started).getTime() < 3e4);
4720
6611
  if (anyPresence2) {
4721
6612
  return aiPresence(anyPresence2, []);
4722
6613
  }
4723
- const anyRun = (_d = (_c = assistDocument == null ? void 0 : assistDocument.tasks) == null ? void 0 : _c.filter(run => !run.ended && !run.reason)) == null ? void 0 : _d.find(f => f.started && /* @__PURE__ */new Date().getTime() - new Date(f.started).getTime() < 3e4);
6614
+ const anyRun = (_d = (_c = assistDocument == null ? void 0 : assistDocument.tasks) == null ? void 0 : _c.filter(run => !run.ended && !run.reason)) == null ? void 0 : _d.find(f => f.started && ( /* @__PURE__ */new Date()).getTime() - new Date(f.started).getTime() < 3e4);
4724
6615
  return anyRun ? aiPresence({
4725
6616
  started: anyRun.started,
4726
6617
  path: documentRootKey,
@@ -4749,6 +6640,9 @@ const assist = sanity.definePlugin(config => {
4749
6640
  schema: {
4750
6641
  types: schemaTypes
4751
6642
  },
6643
+ i18n: {
6644
+ bundles: [{}]
6645
+ },
4752
6646
  document: {
4753
6647
  inspectors: (prev, context) => {
4754
6648
  const docSchema = context.schema.get(context.documentType);
@@ -4757,23 +6651,23 @@ const assist = sanity.definePlugin(config => {
4757
6651
  }
4758
6652
  return prev;
4759
6653
  },
4760
- unstable_fieldActions: (prev, _ref17) => {
6654
+ unstable_fieldActions: (prev, _ref24) => {
4761
6655
  let {
4762
6656
  documentType,
4763
6657
  schema
4764
- } = _ref17;
6658
+ } = _ref24;
4765
6659
  const docSchema = schema.get(documentType);
4766
6660
  if (docSchema && isSchemaAssistEnabled(docSchema)) {
4767
6661
  return [...prev, assistFieldActions];
4768
6662
  }
4769
6663
  return prev;
4770
6664
  },
4771
- unstable_languageFilter: (prev, _ref18) => {
6665
+ unstable_languageFilter: (prev, _ref25) => {
4772
6666
  let {
4773
6667
  documentId,
4774
6668
  schema,
4775
6669
  schemaType
4776
- } = _ref18;
6670
+ } = _ref25;
4777
6671
  const docSchema = schema.get(schemaType);
4778
6672
  if (docSchema && sanity.isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema)) {
4779
6673
  return [...prev, createAssistDocumentPresence(documentId, docSchema)];