@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.esm.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { useClient, typed, useSchema, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, pathToString, isObjectSchemaType, stringToPath, isKeySegment, useEditState, useCurrentUser, useValidationStatus, StatusButton, FormFieldHeaderText, PatchEvent, unset, set, useFormCallbacks, FormCallbacksProvider, FormInput, setIfMissing, insert, PresenceOverlay, VirtualizerScrollInstanceProvider, useColorSchemeValue, isArraySchemaType, ObjectInputMember, defineType, defineField, defineArrayMember, getPublishedId, useSyncState, definePlugin } from 'sanity';
3
- import { Card, Stack, Box, Button, Spinner, Flex, Label, focusFirstDescendant, Text, useClickOutside, Popover, useLayer, useGlobalKeyDown, useToast, Dialog, Tooltip, TextArea, Container, Autocomplete, Breadcrumbs, Badge, useTheme, rgba, ThemeProvider, ErrorBoundary, Switch, MenuButton, Menu, MenuItem } from '@sanity/ui';
2
+ import { useClient, typed, useSchema, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, pathToString, isObjectSchemaType, stringToPath as stringToPath$2, isKeySegment, useEditState, useCurrentUser, StatusButton, FormFieldHeaderText, PatchEvent, unset, set, useFormCallbacks, FormCallbacksProvider, FormInput, setIfMissing, insert, PresenceOverlay, VirtualizerScrollInstanceProvider, useColorSchemeValue, isArraySchemaType, isDocumentSchemaType, ObjectInputMember, defineType, defineField, defineArrayMember, isArrayOfObjectsSchemaType, getPublishedId, useSyncState, definePlugin } from 'sanity';
3
+ import { Card, Stack, Box, Button, Spinner, Flex, Label, focusFirstDescendant, Text, useClickOutside, Popover, useLayer, useGlobalKeyDown, useToast, Dialog, Tooltip, TextArea, Container, Autocomplete, Breadcrumbs, Badge, useTheme, rgba, Radio, Checkbox, ThemeProvider, ErrorBoundary, Switch, MenuButton, Menu, MenuItem } from '@sanity/ui';
4
4
  import { useState, useRef, useEffect, useMemo, useCallback, createContext, useReducer, forwardRef, createElement, useContext, useId } from 'react';
5
- import { SyncIcon, DocumentIcon, LinkIcon, ImageIcon, BlockContentIcon, OlistIcon, BlockquoteIcon, StringIcon, ErrorOutlineIcon, CheckmarkCircleIcon, CloseCircleIcon, ClockIcon, PlayIcon, SparklesIcon, ArrowLeftIcon, SearchIcon, RetryIcon, ArrowRightIcon, CloseIcon, CheckmarkIcon, icons, TokenIcon, DocumentTextIcon, ThListIcon, CodeIcon, ComposeIcon, LockIcon, ControlsIcon } from '@sanity/icons';
5
+ import { SyncIcon, DocumentIcon, LinkIcon, ImageIcon, BlockContentIcon, OlistIcon, BlockquoteIcon, StringIcon, ErrorOutlineIcon, CheckmarkCircleIcon, CloseCircleIcon, ClockIcon, PlayIcon, SparklesIcon, ArrowLeftIcon, SearchIcon, RetryIcon, ArrowRightIcon, CloseIcon, CheckmarkIcon, icons, TokenIcon, DocumentTextIcon, ThListIcon, CodeIcon, ComposeIcon, LockIcon, TranslateIcon, ControlsIcon } from '@sanity/icons';
6
6
  import { mergeMap, share, take, filter, distinctUntilChanged, catchError, tap } from 'rxjs/operators';
7
7
  import isEqual from 'react-fast-compare';
8
8
  import { throwError, of, partition, merge, switchMap, delay, defer } from 'rxjs';
@@ -28,6 +28,8 @@ const instructionTaskTypeName = "sanity.assist.instructionTask";
28
28
  const fieldPresenceTypeName = "sanity.assist.instructionTask.presence";
29
29
  const assistSerializedTypeName = "sanity.assist.serialized.type";
30
30
  const assistSerializedFieldTypeName = "sanity.assist.serialized.field";
31
+ const outputFieldTypeName = "sanity.assist.output.field";
32
+ const outputTypeTypeName = "sanity.assist.output.type";
31
33
  const fieldPathParam = "pathKey";
32
34
  const instructionParam = "instruction";
33
35
  const documentRootKey = "<document>";
@@ -162,7 +164,8 @@ function isDisabled(type, allowReadonlyHidden) {
162
164
  return !isSchemaAssistEnabled(type) || isUnsupportedType(type) || !allowReadonlyHidden && readonlyHidden;
163
165
  }
164
166
  function isUnsupportedType(type) {
165
- 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");
167
+ var _a, _b;
168
+ 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");
166
169
  }
167
170
  const inlineTypes = ["document", "object", "image", "file"];
168
171
  function serializeSchema(schema, options) {
@@ -204,13 +207,14 @@ function getSchemaStub(schemaType, schema, options) {
204
207
  return removeUndef(baseSchema);
205
208
  }
206
209
  function getBaseFields(schema, type, typeName, options) {
207
- var _a, _b, _c;
208
- const imagePromptField = (_a = type.options) == null ? void 0 : _a.imagePromptField;
210
+ var _a, _b, _c, _d, _e;
211
+ const schemaOptions = removeUndef({
212
+ imagePromptField: (_a = type.options) == null ? void 0 : _a.imagePromptField,
213
+ embeddingsIndex: (_c = (_b = type.options) == null ? void 0 : _b.aiWritingAssistance) == null ? void 0 : _c.embeddingsIndex
214
+ });
209
215
  return removeUndef({
210
- options: imagePromptField ? {
211
- imagePromptField
212
- } : void 0,
213
- 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 => {
216
+ options: Object.keys(schemaOptions).length ? schemaOptions : void 0,
217
+ 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 => {
214
218
  var _a2;
215
219
  return typeof v === "string" ? v : (_a2 = v.value) != null ? _a2 : "".concat(v.title);
216
220
  }) : void 0,
@@ -588,7 +592,7 @@ function getTypePath(doc, pathString) {
588
592
  if (!pathString) {
589
593
  return void 0;
590
594
  }
591
- const path = stringToPath(pathString);
595
+ const path = stringToPath$2(pathString);
592
596
  const currentPath = [];
593
597
  let valid = true;
594
598
  const syntheticPath = path.map(segment => {
@@ -667,7 +671,6 @@ function useStudioAssistDocument(_ref2) {
667
671
  } = _ref2;
668
672
  const documentTypeName = schemaType.name;
669
673
  const currentUser = useCurrentUser();
670
- const validation = useValidationStatus(publicId(documentId), schemaType.name).validation;
671
674
  const assistDocument = useDocumentState(assistDocumentId(documentTypeName), assistDocumentTypeName);
672
675
  const assistTasksStatus = useDocumentState(assistTasksStatusId(documentId != null ? documentId : ""), assistTasksStatusTypeName);
673
676
  const client = useClient({
@@ -692,7 +695,7 @@ function useStudioAssistDocument(_ref2) {
692
695
  return {
693
696
  ...assistField,
694
697
  tasks: tasks.filter(task => task.path === assistField.path),
695
- 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))
698
+ 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))
696
699
  };
697
700
  });
698
701
  return typed({
@@ -707,21 +710,12 @@ function useStudioAssistDocument(_ref2) {
707
710
  }),
708
711
  fields
709
712
  });
710
- }, [assistDocument, assistTasksStatus, currentUser, validation]);
713
+ }, [assistDocument, assistTasksStatus, currentUser]);
711
714
  }
712
- function asStudioInstruction(instruction, run, validation) {
713
- var _a;
714
- const errors = validation.filter(marker => marker.level === "error");
715
- const fieldRefs = ((_a = instruction == null ? void 0 : instruction.prompt) != null ? _a : []).flatMap(block => {
716
- if (block._type === "block") {
717
- return block.children.filter(c => c._type === fieldReferenceTypeName);
718
- }
719
- return [];
720
- });
715
+ function asStudioInstruction(instruction, run) {
721
716
  return {
722
717
  ...instruction,
723
- tasks: run.filter(task => task.instructionKey === instruction._key).filter(task => task.started && /* @__PURE__ */new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs),
724
- validation: errors.filter(marker => fieldRefs.map(r => r.path).filter(p => !!p).find(path => pathToString(marker.path) === path))
718
+ tasks: run.filter(task => task.instructionKey === instruction._key).filter(task => task.started && ( /* @__PURE__ */new Date()).getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs)
725
719
  };
726
720
  }
727
721
  function useInterval(ms) {
@@ -802,13 +796,13 @@ function InstructionTaskHistoryButton(props) {
802
796
  const statusDocId = assistTasksStatusId(documentId);
803
797
  const basePath = "".concat(typed("tasks"), '[_key=="').concat(taskKey, '"]');
804
798
  client.patch(statusDocId).set({
805
- ["".concat(basePath, ".").concat(typed("ended"))]: /* @__PURE__ */new Date().toISOString(),
799
+ ["".concat(basePath, ".").concat(typed("ended"))]: ( /* @__PURE__ */new Date()).toISOString(),
806
800
  ["".concat(basePath, ".").concat(typed("reason"))]: typed("aborted")
807
801
  }).commit().catch(console.error);
808
802
  }, [client, documentId]);
809
803
  const titledTasks = useMemo(() => {
810
804
  var _a2;
811
- const t = (_a2 = tasks == null ? void 0 : tasks.filter(task => task.started && /* @__PURE__ */new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs).map(task => {
805
+ const t = (_a2 = tasks == null ? void 0 : tasks.filter(task => task.started && ( /* @__PURE__ */new Date()).getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs).map(task => {
812
806
  var _a3;
813
807
  const instruction = instructions == null ? void 0 : instructions.find(i => i._key === task.instructionKey);
814
808
  return {
@@ -875,11 +869,10 @@ const TaskStatusButton = forwardRef(function TaskStatusButton2(props, ref) {
875
869
  mode: "bleed",
876
870
  onClick,
877
871
  tone: hasErrors ? "critical" : void 0,
878
- fontSize: 1,
879
872
  disabled,
880
873
  ref,
881
874
  selected,
882
- tooltip: TASK_STATUS_BUTTON_TOOLTIP_PROPS
875
+ tooltipProps: TASK_STATUS_BUTTON_TOOLTIP_PROPS
883
876
  });
884
877
  });
885
878
  function TaskList(props) {
@@ -966,6 +959,50 @@ function useApiClient(customApiClient) {
966
959
  });
967
960
  return useMemo(() => customApiClient ? customApiClient(client) : client, [client, customApiClient]);
968
961
  }
962
+ function useTranslate(apiClient) {
963
+ const [loading, setLoading] = useState(false);
964
+ const user = useCurrentUser();
965
+ const schema = useSchema();
966
+ const types = useMemo(() => serializeSchema(schema, {
967
+ leanFormat: true
968
+ }), [schema]);
969
+ const toast = useToast();
970
+ const translate = useCallback(_ref4 => {
971
+ let {
972
+ documentId,
973
+ languagePath,
974
+ fieldLanguageMap
975
+ } = _ref4;
976
+ setLoading(true);
977
+ return apiClient.request({
978
+ method: "POST",
979
+ url: "/assist/tasks/translate/".concat(apiClient.config().dataset, "?projectId=").concat(apiClient.config().projectId),
980
+ body: {
981
+ documentId,
982
+ types,
983
+ languagePath,
984
+ fieldLanguageMap,
985
+ userId: user == null ? void 0 : user.id
986
+ }
987
+ }).catch(e => {
988
+ toast.push({
989
+ status: "error",
990
+ title: "Translate failed",
991
+ description: e.message
992
+ });
993
+ setLoading(false);
994
+ throw e;
995
+ }).finally(() => {
996
+ setTimeout(() => {
997
+ setLoading(false);
998
+ }, 2e3);
999
+ });
1000
+ }, [setLoading, apiClient, toast, user, types]);
1001
+ return useMemo(() => ({
1002
+ translate,
1003
+ loading
1004
+ }), [translate, loading]);
1005
+ }
969
1006
  function useGenerateCaption(apiClient) {
970
1007
  const [loading, setLoading] = useState(false);
971
1008
  const user = useCurrentUser();
@@ -974,11 +1011,11 @@ function useGenerateCaption(apiClient) {
974
1011
  leanFormat: true
975
1012
  }), [schema]);
976
1013
  const toast = useToast();
977
- const generateCaption = useCallback(_ref4 => {
1014
+ const generateCaption = useCallback(_ref5 => {
978
1015
  let {
979
1016
  path,
980
1017
  documentId
981
- } = _ref4;
1018
+ } = _ref5;
982
1019
  setLoading(true);
983
1020
  return apiClient.request({
984
1021
  method: "POST",
@@ -1197,8 +1234,8 @@ function RunInstructionProvider(props) {
1197
1234
  runInstructionRequest({
1198
1235
  ...request,
1199
1236
  instructionKey: instruction._key,
1200
- userTexts: Object.entries(inputs).map(_ref5 => {
1201
- let [key, value] = _ref5;
1237
+ userTexts: Object.entries(inputs).map(_ref6 => {
1238
+ let [key, value] = _ref6;
1202
1239
  return {
1203
1240
  blockKey: key,
1204
1241
  userInput: value
@@ -1211,8 +1248,8 @@ function RunInstructionProvider(props) {
1211
1248
  const open = !!runRequest;
1212
1249
  const runDisabled = useMemo(() => {
1213
1250
  var _a2, _b;
1214
- return ((_b = (_a2 = runRequest == null ? void 0 : runRequest.userInputBlocks) == null ? void 0 : _a2.length) != null ? _b : 0) > Object.entries(inputs).filter(_ref6 => {
1215
- let [, value] = _ref6;
1251
+ return ((_b = (_a2 = runRequest == null ? void 0 : runRequest.userInputBlocks) == null ? void 0 : _a2.length) != null ? _b : 0) > Object.entries(inputs).filter(_ref7 => {
1252
+ let [, value] = _ref7;
1216
1253
  return !!value;
1217
1254
  }).length;
1218
1255
  }, [runRequest == null ? void 0 : runRequest.userInputBlocks, inputs]);
@@ -1323,29 +1360,37 @@ function getAssistableDocId(documentSchemaType, documentId) {
1323
1360
  return documentSchemaType.liveEdit ? baseId : "drafts.".concat(baseId);
1324
1361
  }
1325
1362
  function useRequestRunInstruction(args) {
1326
- const {
1327
- documentOnChange,
1328
- isDocAssistable: isDocAssistable2
1329
- } = args;
1330
1363
  const {
1331
1364
  runInstruction,
1332
1365
  instructionLoading
1333
1366
  } = useRunInstruction();
1334
- const [queuedTask, setQueuedTask] = useState(void 0);
1335
- useEffect(() => {
1336
- if (queuedTask && isDocAssistable2) {
1337
- runInstruction(queuedTask);
1338
- setQueuedTask(void 0);
1339
- }
1340
- }, [queuedTask, isDocAssistable2, runInstruction]);
1367
+ const requestRunInstruction = useDraftDelayedTask({
1368
+ ...args,
1369
+ task: runInstruction
1370
+ });
1341
1371
  return {
1342
1372
  instructionLoading,
1343
- requestRunInstruction: useCallback(task => {
1344
- documentOnChange(PatchEvent.from([unset(["_force_document_creation"])]));
1345
- setQueuedTask(task);
1346
- }, [setQueuedTask, documentOnChange])
1373
+ requestRunInstruction
1347
1374
  };
1348
1375
  }
1376
+ function useDraftDelayedTask(args) {
1377
+ const {
1378
+ documentOnChange,
1379
+ isDocAssistable: isDocAssistable2,
1380
+ task
1381
+ } = args;
1382
+ const [queuedArgs, setQueuedArgs] = useState(void 0);
1383
+ useEffect(() => {
1384
+ if (queuedArgs && isDocAssistable2) {
1385
+ task(queuedArgs);
1386
+ setQueuedArgs(void 0);
1387
+ }
1388
+ }, [queuedArgs, isDocAssistable2, task]);
1389
+ return useCallback(taskArgs => {
1390
+ documentOnChange(PatchEvent.from([unset(["_force_document_creation"])]));
1391
+ setQueuedArgs(taskArgs);
1392
+ }, [setQueuedArgs, documentOnChange]);
1393
+ }
1349
1394
  const SparklesIllustration = styled(SparklesIcon)({
1350
1395
  fontSize: "3.125em",
1351
1396
  "& path": {
@@ -1577,7 +1622,7 @@ function useSelectedSchema(fieldPath, documentSchema) {
1577
1622
  if (fieldPath === documentRootKey) {
1578
1623
  return documentSchema;
1579
1624
  }
1580
- const path = stringToPath(fieldPath);
1625
+ const path = stringToPath$2(fieldPath);
1581
1626
  let currentSchema = documentSchema;
1582
1627
  for (let i = 0; i < path.length; i++) {
1583
1628
  const segment = path[i];
@@ -1596,13 +1641,13 @@ function useSelectedSchema(fieldPath, documentSchema) {
1596
1641
  return currentSchema;
1597
1642
  }, [documentSchema, fieldPath]);
1598
1643
  }
1599
- function FieldsInitializer(_ref7) {
1644
+ function FieldsInitializer(_ref8) {
1600
1645
  let {
1601
1646
  pathKey,
1602
1647
  activePath,
1603
1648
  fieldExists,
1604
1649
  onChange
1605
- } = _ref7;
1650
+ } = _ref8;
1606
1651
  const initialized = useRef(false);
1607
1652
  useEffect(() => {
1608
1653
  if (initialized.current || fieldExists || activePath || !pathKey) {
@@ -1633,7 +1678,7 @@ function FieldAutocomplete(props) {
1633
1678
  return getFieldRefs(schemaType);
1634
1679
  }, [schemaType, includeDocument]);
1635
1680
  const currentField = useMemo(() => fieldRefs.find(f => f.key === fieldPath), [fieldPath, fieldRefs]);
1636
- const autocompleteOptions = useMemo(() => fieldRefs.filter(field => filter ? filter(field) : true).map(field => ({
1681
+ const autocompleteOptions = useMemo(() => fieldRefs.filter(field => filter ? filter(field) : true).filter(f => !isType(f.schemaType, "reference")).map(field => ({
1637
1682
  value: field.key,
1638
1683
  field
1639
1684
  })), [fieldRefs, filter]);
@@ -2130,10 +2175,10 @@ const assistInspector = {
2130
2175
  showAsAction: false
2131
2176
  }),
2132
2177
  component: AssistInspectorWrapper,
2133
- onClose(_ref8) {
2178
+ onClose(_ref9) {
2134
2179
  let {
2135
2180
  params
2136
- } = _ref8;
2181
+ } = _ref9;
2137
2182
  return {
2138
2183
  params: typed({
2139
2184
  ...params,
@@ -2161,11 +2206,11 @@ function useAssistPresence(path, showFocusWithin) {
2161
2206
  const activePresence = (_b = (_a = tasks == null ? void 0 : tasks.filter(task => !task.ended)) == null ? void 0 : _a.flatMap(task => {
2162
2207
  var _a2;
2163
2208
  return (_a2 = task.presence) != null ? _a2 : [];
2164
- })) == null ? void 0 : _b.filter(p => p.started && /* @__PURE__ */new Date().getTime() - new Date(p.started).getTime() < maxHistoryVisibilityMs).filter(presence => {
2209
+ })) == null ? void 0 : _b.filter(p => p.started && ( /* @__PURE__ */new Date()).getTime() - new Date(p.started).getTime() < maxHistoryVisibilityMs).filter(presence => {
2165
2210
  if (!presence.path || !path.length) {
2166
2211
  return false;
2167
2212
  }
2168
- const statusPath = stringToPath(presence.path);
2213
+ const statusPath = stringToPath$2(presence.path);
2169
2214
  if (!showFocusWithin && statusPath.length !== path.length) {
2170
2215
  return false;
2171
2216
  }
@@ -2195,7 +2240,7 @@ function aiPresence(presence, path, title) {
2195
2240
  },
2196
2241
  path,
2197
2242
  sessionId: "not-available",
2198
- lastActiveAt: (_a = presence == null ? void 0 : presence.started) != null ? _a : /* @__PURE__ */new Date().toISOString()
2243
+ lastActiveAt: (_a = presence == null ? void 0 : presence.started) != null ? _a : ( /* @__PURE__ */new Date()).toISOString()
2199
2244
  };
2200
2245
  }
2201
2246
  var __freeze$3 = Object.freeze;
@@ -2206,11 +2251,11 @@ var __template$3 = (cooked, raw) => __freeze$3(__defProp$3(cooked, "raw", {
2206
2251
  var _a$3, _b$1;
2207
2252
  const fadeIn = 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"])));
2208
2253
  const FadeInDiv = styled.div(_b$1 || (_b$1 = __template$3(["\n animation-name: ", ";\n animation-timing-function: ease-in-out;\n"])), fadeIn);
2209
- const FadeInContent = forwardRef(function FadeInContent2(_ref9, ref) {
2254
+ const FadeInContent = forwardRef(function FadeInContent2(_ref10, ref) {
2210
2255
  let {
2211
2256
  children,
2212
2257
  durationMs = 250
2213
- } = _ref9;
2258
+ } = _ref10;
2214
2259
  return /* @__PURE__ */jsx(FadeInDiv, {
2215
2260
  ref,
2216
2261
  style: {
@@ -2222,47 +2267,47 @@ const FadeInContent = forwardRef(function FadeInContent2(_ref9, ref) {
2222
2267
  const purple = {
2223
2268
  "50": {
2224
2269
  title: "Purple 50",
2225
- hex: "#f8e9fe"
2270
+ hex: "#f8f5ff"
2226
2271
  },
2227
2272
  "100": {
2228
2273
  title: "Purple 100",
2229
- hex: "#f2d3fe"
2274
+ hex: "#f1ebff"
2230
2275
  },
2231
2276
  "200": {
2232
2277
  title: "Purple 200",
2233
- hex: "#e6a7fd"
2278
+ hex: "#ece1fe"
2234
2279
  },
2235
2280
  "300": {
2236
2281
  title: "Purple 300",
2237
- hex: "#d97bfd"
2282
+ hex: "#ccb1fc"
2238
2283
  },
2239
2284
  "400": {
2240
2285
  title: "Purple 400",
2241
- hex: "#cd4efc"
2286
+ hex: "#b087f7"
2242
2287
  },
2243
2288
  "500": {
2244
2289
  title: "Purple 500",
2245
- hex: "#c123fc"
2290
+ hex: "#8f57ef"
2246
2291
  },
2247
2292
  "600": {
2248
2293
  title: "Purple 600",
2249
- hex: "#9d1fcd"
2294
+ hex: "#721fe5"
2250
2295
  },
2251
2296
  "700": {
2252
2297
  title: "Purple 700",
2253
- hex: "#7a1b9e"
2298
+ hex: "#4c1a9e"
2254
2299
  },
2255
2300
  "800": {
2256
2301
  title: "Purple 800",
2257
- hex: "#56186f"
2302
+ hex: "#2f1862"
2258
2303
  },
2259
2304
  "900": {
2260
2305
  title: "Purple 900",
2261
- hex: "#331440"
2306
+ hex: "#23173f"
2262
2307
  },
2263
2308
  "950": {
2264
2309
  title: "Purple 950",
2265
- hex: "#211229"
2310
+ hex: "#181128"
2266
2311
  }
2267
2312
  };
2268
2313
  var __freeze$2 = Object.freeze;
@@ -2313,7 +2358,11 @@ function AssistAvatar(props) {
2313
2358
  style: {
2314
2359
  color: "inherit"
2315
2360
  },
2316
- children: /* @__PURE__ */jsx(SparklesIcon, {})
2361
+ children: /* @__PURE__ */jsx(SparklesIcon, {
2362
+ style: {
2363
+ color: "inherit"
2364
+ }
2365
+ })
2317
2366
  })
2318
2367
  })]
2319
2368
  });
@@ -2479,15 +2528,16 @@ function AssistField(props) {
2479
2528
  showOnboarding,
2480
2529
  dismissOnboarding
2481
2530
  } = useOnboardingFeature(fieldOnboardingKey);
2531
+ const singlePresence = presence[0];
2482
2532
  const actions = /* @__PURE__ */jsxs(Flex, {
2483
2533
  gap: 2,
2484
2534
  align: "center",
2485
2535
  justify: "space-between",
2486
- children: [presence.map(pre => /* @__PURE__ */jsx(Box, {
2536
+ children: [singlePresence && /* @__PURE__ */jsx(Box, {
2487
2537
  children: /* @__PURE__ */jsx(AiFieldPresence, {
2488
- presence: pre
2489
- }, pre.lastActiveAt)
2490
- }, pre.user.id)), isFirstAssisted && showOnboarding && /* @__PURE__ */jsx(AssistOnboardingPopover, {
2538
+ presence: singlePresence
2539
+ })
2540
+ }), isFirstAssisted && showOnboarding && /* @__PURE__ */jsx(AssistOnboardingPopover, {
2491
2541
  dismiss: dismissOnboarding
2492
2542
  })]
2493
2543
  });
@@ -2959,7 +3009,6 @@ function AssistConnectorsOverlay(props) {
2959
3009
  zIndex: 150
2960
3010
  // zIndex,
2961
3011
  },
2962
-
2963
3012
  children: connectors.map(connector => /* @__PURE__ */jsx(ConnectorPath, {
2964
3013
  from: connector.from,
2965
3014
  options,
@@ -3198,6 +3247,1508 @@ function mapBlock(block, migratedContexts) {
3198
3247
  children: ((_d = textBlock.children) != null ? _d : []).map(child => mapBlock(child, migratedContexts))
3199
3248
  };
3200
3249
  }
3250
+ const MAX_DEPTH = 6;
3251
+ function getDocumentMembersFlat(doc, schemaType) {
3252
+ if (!isDocumentSchemaType(schemaType)) {
3253
+ console.error("Schema type is not a document");
3254
+ return [];
3255
+ }
3256
+ return extractPaths(doc, schemaType, [], MAX_DEPTH);
3257
+ }
3258
+ function extractPaths(doc, schemaType, path, maxDepth) {
3259
+ if (path.length >= maxDepth) {
3260
+ return [];
3261
+ }
3262
+ return schemaType.fields.reduce((acc, field) => {
3263
+ var _a;
3264
+ const fieldPath = [...path, field.name];
3265
+ const fieldSchema = field.type;
3266
+ const thisFieldWithPath = {
3267
+ path: fieldPath,
3268
+ name: field.name,
3269
+ schemaType: fieldSchema
3270
+ };
3271
+ if (fieldSchema.jsonType === "object") {
3272
+ const innerFields = extractPaths(doc, fieldSchema, fieldPath, maxDepth);
3273
+ return [...acc, thisFieldWithPath, ...innerFields];
3274
+ } else if (fieldSchema.jsonType === "array" && fieldSchema.of.length && fieldSchema.of.some(item => "fields" in item)) {
3275
+ const {
3276
+ value: arrayValue
3277
+ } = (_a = extractWithPath(pathToString(fieldPath), doc)[0]) != null ? _a : {};
3278
+ let arrayPaths = [];
3279
+ if (arrayValue == null ? void 0 : arrayValue.length) {
3280
+ for (const item of arrayValue) {
3281
+ const arrayItemSchema = fieldSchema.of.find(t => t.name === item._type);
3282
+ if (item._key && arrayItemSchema) {
3283
+ const itemPath = [...fieldPath, {
3284
+ _key: item._key
3285
+ }];
3286
+ const innerFields = extractPaths(doc, arrayItemSchema, itemPath, maxDepth);
3287
+ arrayPaths = [...arrayPaths, {
3288
+ path: itemPath,
3289
+ name: item._key,
3290
+ schemaType: arrayItemSchema
3291
+ }, ...innerFields];
3292
+ }
3293
+ }
3294
+ }
3295
+ return [...acc, thisFieldWithPath, ...arrayPaths];
3296
+ }
3297
+ return [...acc, thisFieldWithPath];
3298
+ }, []);
3299
+ }
3300
+ const defaultLanguageOutputs = function (member, enclosingType, translateFromLanguageId, translateToLanguageIds) {
3301
+ if (member.schemaType.jsonType === "object" && member.schemaType.name.startsWith("internationalizedArray")) {
3302
+ const pathEnd = member.path.slice(-1);
3303
+ const language = isKeySegment(pathEnd[0]) ? pathEnd[0]._key : null;
3304
+ return language === translateFromLanguageId ? translateToLanguageIds.map(translateToId => ({
3305
+ id: translateToId,
3306
+ outputPath: [...member.path.slice(0, -1), {
3307
+ _key: translateToId
3308
+ }]
3309
+ })) : void 0;
3310
+ }
3311
+ if (enclosingType.jsonType === "object" && enclosingType.name.startsWith("locale")) {
3312
+ return translateFromLanguageId === member.name ? translateToLanguageIds.map(translateToId => ({
3313
+ id: translateToId,
3314
+ outputPath: [...member.path.slice(0, -1), translateToId]
3315
+ })) : void 0;
3316
+ }
3317
+ return void 0;
3318
+ };
3319
+ function getTranslationMap(documentSchema, documentMembers, translateFromLanguageId, outputLanguageIds, langFn) {
3320
+ var _a, _b, _c;
3321
+ const translationMaps = [];
3322
+ for (const member of documentMembers) {
3323
+ const parentPath = member.path.slice(0, -1);
3324
+ const enclosingType = (_b = (_a = documentMembers.find(m => pathToString(m.path) === pathToString(parentPath))) == null ? void 0 : _a.schemaType) != null ? _b : documentSchema;
3325
+ const translations = (_c = langFn(member, enclosingType, translateFromLanguageId, outputLanguageIds)) == null ? void 0 : _c.filter(translation => translation.id !== translateFromLanguageId);
3326
+ if (translations) {
3327
+ translationMaps.push({
3328
+ inputLanguageId: translateFromLanguageId,
3329
+ inputPath: member.path,
3330
+ outputs: translations
3331
+ });
3332
+ }
3333
+ }
3334
+ return translationMaps;
3335
+ }
3336
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3337
+ function getDefaultExportFromCjs(x) {
3338
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3339
+ }
3340
+
3341
+ /**
3342
+ * Checks if `value` is classified as an `Array` object.
3343
+ *
3344
+ * @static
3345
+ * @memberOf _
3346
+ * @since 0.1.0
3347
+ * @category Lang
3348
+ * @param {*} value The value to check.
3349
+ * @returns {boolean} Returns `true` if `value` is an array, else `false`.
3350
+ * @example
3351
+ *
3352
+ * _.isArray([1, 2, 3]);
3353
+ * // => true
3354
+ *
3355
+ * _.isArray(document.body.children);
3356
+ * // => false
3357
+ *
3358
+ * _.isArray('abc');
3359
+ * // => false
3360
+ *
3361
+ * _.isArray(_.noop);
3362
+ * // => false
3363
+ */
3364
+
3365
+ var isArray$3 = Array.isArray;
3366
+ var isArray_1 = isArray$3;
3367
+
3368
+ /** Detect free variable `global` from Node.js. */
3369
+
3370
+ var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
3371
+ var _freeGlobal = freeGlobal$1;
3372
+ var freeGlobal = _freeGlobal;
3373
+
3374
+ /** Detect free variable `self`. */
3375
+ var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
3376
+
3377
+ /** Used as a reference to the global object. */
3378
+ var root$3 = freeGlobal || freeSelf || Function('return this')();
3379
+ var _root = root$3;
3380
+ var root$2 = _root;
3381
+
3382
+ /** Built-in value references. */
3383
+ var Symbol$3 = root$2.Symbol;
3384
+ var _Symbol = Symbol$3;
3385
+ var Symbol$2 = _Symbol;
3386
+
3387
+ /** Used for built-in method references. */
3388
+ var objectProto$4 = Object.prototype;
3389
+
3390
+ /** Used to check objects for own properties. */
3391
+ var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
3392
+
3393
+ /**
3394
+ * Used to resolve the
3395
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
3396
+ * of values.
3397
+ */
3398
+ var nativeObjectToString$1 = objectProto$4.toString;
3399
+
3400
+ /** Built-in value references. */
3401
+ var symToStringTag$1 = Symbol$2 ? Symbol$2.toStringTag : undefined;
3402
+
3403
+ /**
3404
+ * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
3405
+ *
3406
+ * @private
3407
+ * @param {*} value The value to query.
3408
+ * @returns {string} Returns the raw `toStringTag`.
3409
+ */
3410
+ function getRawTag$1(value) {
3411
+ var isOwn = hasOwnProperty$3.call(value, symToStringTag$1),
3412
+ tag = value[symToStringTag$1];
3413
+ try {
3414
+ value[symToStringTag$1] = undefined;
3415
+ var unmasked = true;
3416
+ } catch (e) {}
3417
+ var result = nativeObjectToString$1.call(value);
3418
+ if (unmasked) {
3419
+ if (isOwn) {
3420
+ value[symToStringTag$1] = tag;
3421
+ } else {
3422
+ delete value[symToStringTag$1];
3423
+ }
3424
+ }
3425
+ return result;
3426
+ }
3427
+ var _getRawTag = getRawTag$1;
3428
+
3429
+ /** Used for built-in method references. */
3430
+
3431
+ var objectProto$3 = Object.prototype;
3432
+
3433
+ /**
3434
+ * Used to resolve the
3435
+ * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
3436
+ * of values.
3437
+ */
3438
+ var nativeObjectToString = objectProto$3.toString;
3439
+
3440
+ /**
3441
+ * Converts `value` to a string using `Object.prototype.toString`.
3442
+ *
3443
+ * @private
3444
+ * @param {*} value The value to convert.
3445
+ * @returns {string} Returns the converted string.
3446
+ */
3447
+ function objectToString$1(value) {
3448
+ return nativeObjectToString.call(value);
3449
+ }
3450
+ var _objectToString = objectToString$1;
3451
+ var Symbol$1 = _Symbol,
3452
+ getRawTag = _getRawTag,
3453
+ objectToString = _objectToString;
3454
+
3455
+ /** `Object#toString` result references. */
3456
+ var nullTag = '[object Null]',
3457
+ undefinedTag = '[object Undefined]';
3458
+
3459
+ /** Built-in value references. */
3460
+ var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
3461
+
3462
+ /**
3463
+ * The base implementation of `getTag` without fallbacks for buggy environments.
3464
+ *
3465
+ * @private
3466
+ * @param {*} value The value to query.
3467
+ * @returns {string} Returns the `toStringTag`.
3468
+ */
3469
+ function baseGetTag$2(value) {
3470
+ if (value == null) {
3471
+ return value === undefined ? undefinedTag : nullTag;
3472
+ }
3473
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
3474
+ }
3475
+ var _baseGetTag = baseGetTag$2;
3476
+
3477
+ /**
3478
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
3479
+ * and has a `typeof` result of "object".
3480
+ *
3481
+ * @static
3482
+ * @memberOf _
3483
+ * @since 4.0.0
3484
+ * @category Lang
3485
+ * @param {*} value The value to check.
3486
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
3487
+ * @example
3488
+ *
3489
+ * _.isObjectLike({});
3490
+ * // => true
3491
+ *
3492
+ * _.isObjectLike([1, 2, 3]);
3493
+ * // => true
3494
+ *
3495
+ * _.isObjectLike(_.noop);
3496
+ * // => false
3497
+ *
3498
+ * _.isObjectLike(null);
3499
+ * // => false
3500
+ */
3501
+
3502
+ function isObjectLike$1(value) {
3503
+ return value != null && typeof value == 'object';
3504
+ }
3505
+ var isObjectLike_1 = isObjectLike$1;
3506
+ var baseGetTag$1 = _baseGetTag,
3507
+ isObjectLike = isObjectLike_1;
3508
+
3509
+ /** `Object#toString` result references. */
3510
+ var symbolTag = '[object Symbol]';
3511
+
3512
+ /**
3513
+ * Checks if `value` is classified as a `Symbol` primitive or object.
3514
+ *
3515
+ * @static
3516
+ * @memberOf _
3517
+ * @since 4.0.0
3518
+ * @category Lang
3519
+ * @param {*} value The value to check.
3520
+ * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
3521
+ * @example
3522
+ *
3523
+ * _.isSymbol(Symbol.iterator);
3524
+ * // => true
3525
+ *
3526
+ * _.isSymbol('abc');
3527
+ * // => false
3528
+ */
3529
+ function isSymbol$3(value) {
3530
+ return typeof value == 'symbol' || isObjectLike(value) && baseGetTag$1(value) == symbolTag;
3531
+ }
3532
+ var isSymbol_1 = isSymbol$3;
3533
+ var isArray$2 = isArray_1,
3534
+ isSymbol$2 = isSymbol_1;
3535
+
3536
+ /** Used to match property names within property paths. */
3537
+ var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
3538
+ reIsPlainProp = /^\w*$/;
3539
+
3540
+ /**
3541
+ * Checks if `value` is a property name and not a property path.
3542
+ *
3543
+ * @private
3544
+ * @param {*} value The value to check.
3545
+ * @param {Object} [object] The object to query keys on.
3546
+ * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
3547
+ */
3548
+ function isKey$1(value, object) {
3549
+ if (isArray$2(value)) {
3550
+ return false;
3551
+ }
3552
+ var type = typeof value;
3553
+ if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol$2(value)) {
3554
+ return true;
3555
+ }
3556
+ return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
3557
+ }
3558
+ var _isKey = isKey$1;
3559
+
3560
+ /**
3561
+ * Checks if `value` is the
3562
+ * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
3563
+ * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
3564
+ *
3565
+ * @static
3566
+ * @memberOf _
3567
+ * @since 0.1.0
3568
+ * @category Lang
3569
+ * @param {*} value The value to check.
3570
+ * @returns {boolean} Returns `true` if `value` is an object, else `false`.
3571
+ * @example
3572
+ *
3573
+ * _.isObject({});
3574
+ * // => true
3575
+ *
3576
+ * _.isObject([1, 2, 3]);
3577
+ * // => true
3578
+ *
3579
+ * _.isObject(_.noop);
3580
+ * // => true
3581
+ *
3582
+ * _.isObject(null);
3583
+ * // => false
3584
+ */
3585
+
3586
+ function isObject$2(value) {
3587
+ var type = typeof value;
3588
+ return value != null && (type == 'object' || type == 'function');
3589
+ }
3590
+ var isObject_1 = isObject$2;
3591
+ var baseGetTag = _baseGetTag,
3592
+ isObject$1 = isObject_1;
3593
+
3594
+ /** `Object#toString` result references. */
3595
+ var asyncTag = '[object AsyncFunction]',
3596
+ funcTag = '[object Function]',
3597
+ genTag = '[object GeneratorFunction]',
3598
+ proxyTag = '[object Proxy]';
3599
+
3600
+ /**
3601
+ * Checks if `value` is classified as a `Function` object.
3602
+ *
3603
+ * @static
3604
+ * @memberOf _
3605
+ * @since 0.1.0
3606
+ * @category Lang
3607
+ * @param {*} value The value to check.
3608
+ * @returns {boolean} Returns `true` if `value` is a function, else `false`.
3609
+ * @example
3610
+ *
3611
+ * _.isFunction(_);
3612
+ * // => true
3613
+ *
3614
+ * _.isFunction(/abc/);
3615
+ * // => false
3616
+ */
3617
+ function isFunction$1(value) {
3618
+ if (!isObject$1(value)) {
3619
+ return false;
3620
+ }
3621
+ // The use of `Object#toString` avoids issues with the `typeof` operator
3622
+ // in Safari 9 which returns 'object' for typed arrays and other constructors.
3623
+ var tag = baseGetTag(value);
3624
+ return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
3625
+ }
3626
+ var isFunction_1 = isFunction$1;
3627
+ var root$1 = _root;
3628
+
3629
+ /** Used to detect overreaching core-js shims. */
3630
+ var coreJsData$1 = root$1['__core-js_shared__'];
3631
+ var _coreJsData = coreJsData$1;
3632
+ var coreJsData = _coreJsData;
3633
+
3634
+ /** Used to detect methods masquerading as native. */
3635
+ var maskSrcKey = function () {
3636
+ var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
3637
+ return uid ? 'Symbol(src)_1.' + uid : '';
3638
+ }();
3639
+
3640
+ /**
3641
+ * Checks if `func` has its source masked.
3642
+ *
3643
+ * @private
3644
+ * @param {Function} func The function to check.
3645
+ * @returns {boolean} Returns `true` if `func` is masked, else `false`.
3646
+ */
3647
+ function isMasked$1(func) {
3648
+ return !!maskSrcKey && maskSrcKey in func;
3649
+ }
3650
+ var _isMasked = isMasked$1;
3651
+
3652
+ /** Used for built-in method references. */
3653
+
3654
+ var funcProto$1 = Function.prototype;
3655
+
3656
+ /** Used to resolve the decompiled source of functions. */
3657
+ var funcToString$1 = funcProto$1.toString;
3658
+
3659
+ /**
3660
+ * Converts `func` to its source code.
3661
+ *
3662
+ * @private
3663
+ * @param {Function} func The function to convert.
3664
+ * @returns {string} Returns the source code.
3665
+ */
3666
+ function toSource$1(func) {
3667
+ if (func != null) {
3668
+ try {
3669
+ return funcToString$1.call(func);
3670
+ } catch (e) {}
3671
+ try {
3672
+ return func + '';
3673
+ } catch (e) {}
3674
+ }
3675
+ return '';
3676
+ }
3677
+ var _toSource = toSource$1;
3678
+ var isFunction = isFunction_1,
3679
+ isMasked = _isMasked,
3680
+ isObject = isObject_1,
3681
+ toSource = _toSource;
3682
+
3683
+ /**
3684
+ * Used to match `RegExp`
3685
+ * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
3686
+ */
3687
+ var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
3688
+
3689
+ /** Used to detect host constructors (Safari). */
3690
+ var reIsHostCtor = /^\[object .+?Constructor\]$/;
3691
+
3692
+ /** Used for built-in method references. */
3693
+ var funcProto = Function.prototype,
3694
+ objectProto$2 = Object.prototype;
3695
+
3696
+ /** Used to resolve the decompiled source of functions. */
3697
+ var funcToString = funcProto.toString;
3698
+
3699
+ /** Used to check objects for own properties. */
3700
+ var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
3701
+
3702
+ /** Used to detect if a method is native. */
3703
+ var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty$2).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
3704
+
3705
+ /**
3706
+ * The base implementation of `_.isNative` without bad shim checks.
3707
+ *
3708
+ * @private
3709
+ * @param {*} value The value to check.
3710
+ * @returns {boolean} Returns `true` if `value` is a native function,
3711
+ * else `false`.
3712
+ */
3713
+ function baseIsNative$1(value) {
3714
+ if (!isObject(value) || isMasked(value)) {
3715
+ return false;
3716
+ }
3717
+ var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
3718
+ return pattern.test(toSource(value));
3719
+ }
3720
+ var _baseIsNative = baseIsNative$1;
3721
+
3722
+ /**
3723
+ * Gets the value at `key` of `object`.
3724
+ *
3725
+ * @private
3726
+ * @param {Object} [object] The object to query.
3727
+ * @param {string} key The key of the property to get.
3728
+ * @returns {*} Returns the property value.
3729
+ */
3730
+
3731
+ function getValue$1(object, key) {
3732
+ return object == null ? undefined : object[key];
3733
+ }
3734
+ var _getValue = getValue$1;
3735
+ var baseIsNative = _baseIsNative,
3736
+ getValue = _getValue;
3737
+
3738
+ /**
3739
+ * Gets the native function at `key` of `object`.
3740
+ *
3741
+ * @private
3742
+ * @param {Object} object The object to query.
3743
+ * @param {string} key The key of the method to get.
3744
+ * @returns {*} Returns the function if it's native, else `undefined`.
3745
+ */
3746
+ function getNative$2(object, key) {
3747
+ var value = getValue(object, key);
3748
+ return baseIsNative(value) ? value : undefined;
3749
+ }
3750
+ var _getNative = getNative$2;
3751
+ var getNative$1 = _getNative;
3752
+
3753
+ /* Built-in method references that are verified to be native. */
3754
+ var nativeCreate$4 = getNative$1(Object, 'create');
3755
+ var _nativeCreate = nativeCreate$4;
3756
+ var nativeCreate$3 = _nativeCreate;
3757
+
3758
+ /**
3759
+ * Removes all key-value entries from the hash.
3760
+ *
3761
+ * @private
3762
+ * @name clear
3763
+ * @memberOf Hash
3764
+ */
3765
+ function hashClear$1() {
3766
+ this.__data__ = nativeCreate$3 ? nativeCreate$3(null) : {};
3767
+ this.size = 0;
3768
+ }
3769
+ var _hashClear = hashClear$1;
3770
+
3771
+ /**
3772
+ * Removes `key` and its value from the hash.
3773
+ *
3774
+ * @private
3775
+ * @name delete
3776
+ * @memberOf Hash
3777
+ * @param {Object} hash The hash to modify.
3778
+ * @param {string} key The key of the value to remove.
3779
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
3780
+ */
3781
+
3782
+ function hashDelete$1(key) {
3783
+ var result = this.has(key) && delete this.__data__[key];
3784
+ this.size -= result ? 1 : 0;
3785
+ return result;
3786
+ }
3787
+ var _hashDelete = hashDelete$1;
3788
+ var nativeCreate$2 = _nativeCreate;
3789
+
3790
+ /** Used to stand-in for `undefined` hash values. */
3791
+ var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
3792
+
3793
+ /** Used for built-in method references. */
3794
+ var objectProto$1 = Object.prototype;
3795
+
3796
+ /** Used to check objects for own properties. */
3797
+ var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
3798
+
3799
+ /**
3800
+ * Gets the hash value for `key`.
3801
+ *
3802
+ * @private
3803
+ * @name get
3804
+ * @memberOf Hash
3805
+ * @param {string} key The key of the value to get.
3806
+ * @returns {*} Returns the entry value.
3807
+ */
3808
+ function hashGet$1(key) {
3809
+ var data = this.__data__;
3810
+ if (nativeCreate$2) {
3811
+ var result = data[key];
3812
+ return result === HASH_UNDEFINED$1 ? undefined : result;
3813
+ }
3814
+ return hasOwnProperty$1.call(data, key) ? data[key] : undefined;
3815
+ }
3816
+ var _hashGet = hashGet$1;
3817
+ var nativeCreate$1 = _nativeCreate;
3818
+
3819
+ /** Used for built-in method references. */
3820
+ var objectProto = Object.prototype;
3821
+
3822
+ /** Used to check objects for own properties. */
3823
+ var hasOwnProperty = objectProto.hasOwnProperty;
3824
+
3825
+ /**
3826
+ * Checks if a hash value for `key` exists.
3827
+ *
3828
+ * @private
3829
+ * @name has
3830
+ * @memberOf Hash
3831
+ * @param {string} key The key of the entry to check.
3832
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
3833
+ */
3834
+ function hashHas$1(key) {
3835
+ var data = this.__data__;
3836
+ return nativeCreate$1 ? data[key] !== undefined : hasOwnProperty.call(data, key);
3837
+ }
3838
+ var _hashHas = hashHas$1;
3839
+ var nativeCreate = _nativeCreate;
3840
+
3841
+ /** Used to stand-in for `undefined` hash values. */
3842
+ var HASH_UNDEFINED = '__lodash_hash_undefined__';
3843
+
3844
+ /**
3845
+ * Sets the hash `key` to `value`.
3846
+ *
3847
+ * @private
3848
+ * @name set
3849
+ * @memberOf Hash
3850
+ * @param {string} key The key of the value to set.
3851
+ * @param {*} value The value to set.
3852
+ * @returns {Object} Returns the hash instance.
3853
+ */
3854
+ function hashSet$1(key, value) {
3855
+ var data = this.__data__;
3856
+ this.size += this.has(key) ? 0 : 1;
3857
+ data[key] = nativeCreate && value === undefined ? HASH_UNDEFINED : value;
3858
+ return this;
3859
+ }
3860
+ var _hashSet = hashSet$1;
3861
+ var hashClear = _hashClear,
3862
+ hashDelete = _hashDelete,
3863
+ hashGet = _hashGet,
3864
+ hashHas = _hashHas,
3865
+ hashSet = _hashSet;
3866
+
3867
+ /**
3868
+ * Creates a hash object.
3869
+ *
3870
+ * @private
3871
+ * @constructor
3872
+ * @param {Array} [entries] The key-value pairs to cache.
3873
+ */
3874
+ function Hash$1(entries) {
3875
+ var index = -1,
3876
+ length = entries == null ? 0 : entries.length;
3877
+ this.clear();
3878
+ while (++index < length) {
3879
+ var entry = entries[index];
3880
+ this.set(entry[0], entry[1]);
3881
+ }
3882
+ }
3883
+
3884
+ // Add methods to `Hash`.
3885
+ Hash$1.prototype.clear = hashClear;
3886
+ Hash$1.prototype['delete'] = hashDelete;
3887
+ Hash$1.prototype.get = hashGet;
3888
+ Hash$1.prototype.has = hashHas;
3889
+ Hash$1.prototype.set = hashSet;
3890
+ var _Hash = Hash$1;
3891
+
3892
+ /**
3893
+ * Removes all key-value entries from the list cache.
3894
+ *
3895
+ * @private
3896
+ * @name clear
3897
+ * @memberOf ListCache
3898
+ */
3899
+
3900
+ function listCacheClear$1() {
3901
+ this.__data__ = [];
3902
+ this.size = 0;
3903
+ }
3904
+ var _listCacheClear = listCacheClear$1;
3905
+
3906
+ /**
3907
+ * Performs a
3908
+ * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
3909
+ * comparison between two values to determine if they are equivalent.
3910
+ *
3911
+ * @static
3912
+ * @memberOf _
3913
+ * @since 4.0.0
3914
+ * @category Lang
3915
+ * @param {*} value The value to compare.
3916
+ * @param {*} other The other value to compare.
3917
+ * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
3918
+ * @example
3919
+ *
3920
+ * var object = { 'a': 1 };
3921
+ * var other = { 'a': 1 };
3922
+ *
3923
+ * _.eq(object, object);
3924
+ * // => true
3925
+ *
3926
+ * _.eq(object, other);
3927
+ * // => false
3928
+ *
3929
+ * _.eq('a', 'a');
3930
+ * // => true
3931
+ *
3932
+ * _.eq('a', Object('a'));
3933
+ * // => false
3934
+ *
3935
+ * _.eq(NaN, NaN);
3936
+ * // => true
3937
+ */
3938
+
3939
+ function eq$1(value, other) {
3940
+ return value === other || value !== value && other !== other;
3941
+ }
3942
+ var eq_1 = eq$1;
3943
+ var eq = eq_1;
3944
+
3945
+ /**
3946
+ * Gets the index at which the `key` is found in `array` of key-value pairs.
3947
+ *
3948
+ * @private
3949
+ * @param {Array} array The array to inspect.
3950
+ * @param {*} key The key to search for.
3951
+ * @returns {number} Returns the index of the matched value, else `-1`.
3952
+ */
3953
+ function assocIndexOf$4(array, key) {
3954
+ var length = array.length;
3955
+ while (length--) {
3956
+ if (eq(array[length][0], key)) {
3957
+ return length;
3958
+ }
3959
+ }
3960
+ return -1;
3961
+ }
3962
+ var _assocIndexOf = assocIndexOf$4;
3963
+ var assocIndexOf$3 = _assocIndexOf;
3964
+
3965
+ /** Used for built-in method references. */
3966
+ var arrayProto = Array.prototype;
3967
+
3968
+ /** Built-in value references. */
3969
+ var splice = arrayProto.splice;
3970
+
3971
+ /**
3972
+ * Removes `key` and its value from the list cache.
3973
+ *
3974
+ * @private
3975
+ * @name delete
3976
+ * @memberOf ListCache
3977
+ * @param {string} key The key of the value to remove.
3978
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
3979
+ */
3980
+ function listCacheDelete$1(key) {
3981
+ var data = this.__data__,
3982
+ index = assocIndexOf$3(data, key);
3983
+ if (index < 0) {
3984
+ return false;
3985
+ }
3986
+ var lastIndex = data.length - 1;
3987
+ if (index == lastIndex) {
3988
+ data.pop();
3989
+ } else {
3990
+ splice.call(data, index, 1);
3991
+ }
3992
+ --this.size;
3993
+ return true;
3994
+ }
3995
+ var _listCacheDelete = listCacheDelete$1;
3996
+ var assocIndexOf$2 = _assocIndexOf;
3997
+
3998
+ /**
3999
+ * Gets the list cache value for `key`.
4000
+ *
4001
+ * @private
4002
+ * @name get
4003
+ * @memberOf ListCache
4004
+ * @param {string} key The key of the value to get.
4005
+ * @returns {*} Returns the entry value.
4006
+ */
4007
+ function listCacheGet$1(key) {
4008
+ var data = this.__data__,
4009
+ index = assocIndexOf$2(data, key);
4010
+ return index < 0 ? undefined : data[index][1];
4011
+ }
4012
+ var _listCacheGet = listCacheGet$1;
4013
+ var assocIndexOf$1 = _assocIndexOf;
4014
+
4015
+ /**
4016
+ * Checks if a list cache value for `key` exists.
4017
+ *
4018
+ * @private
4019
+ * @name has
4020
+ * @memberOf ListCache
4021
+ * @param {string} key The key of the entry to check.
4022
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
4023
+ */
4024
+ function listCacheHas$1(key) {
4025
+ return assocIndexOf$1(this.__data__, key) > -1;
4026
+ }
4027
+ var _listCacheHas = listCacheHas$1;
4028
+ var assocIndexOf = _assocIndexOf;
4029
+
4030
+ /**
4031
+ * Sets the list cache `key` to `value`.
4032
+ *
4033
+ * @private
4034
+ * @name set
4035
+ * @memberOf ListCache
4036
+ * @param {string} key The key of the value to set.
4037
+ * @param {*} value The value to set.
4038
+ * @returns {Object} Returns the list cache instance.
4039
+ */
4040
+ function listCacheSet$1(key, value) {
4041
+ var data = this.__data__,
4042
+ index = assocIndexOf(data, key);
4043
+ if (index < 0) {
4044
+ ++this.size;
4045
+ data.push([key, value]);
4046
+ } else {
4047
+ data[index][1] = value;
4048
+ }
4049
+ return this;
4050
+ }
4051
+ var _listCacheSet = listCacheSet$1;
4052
+ var listCacheClear = _listCacheClear,
4053
+ listCacheDelete = _listCacheDelete,
4054
+ listCacheGet = _listCacheGet,
4055
+ listCacheHas = _listCacheHas,
4056
+ listCacheSet = _listCacheSet;
4057
+
4058
+ /**
4059
+ * Creates an list cache object.
4060
+ *
4061
+ * @private
4062
+ * @constructor
4063
+ * @param {Array} [entries] The key-value pairs to cache.
4064
+ */
4065
+ function ListCache$1(entries) {
4066
+ var index = -1,
4067
+ length = entries == null ? 0 : entries.length;
4068
+ this.clear();
4069
+ while (++index < length) {
4070
+ var entry = entries[index];
4071
+ this.set(entry[0], entry[1]);
4072
+ }
4073
+ }
4074
+
4075
+ // Add methods to `ListCache`.
4076
+ ListCache$1.prototype.clear = listCacheClear;
4077
+ ListCache$1.prototype['delete'] = listCacheDelete;
4078
+ ListCache$1.prototype.get = listCacheGet;
4079
+ ListCache$1.prototype.has = listCacheHas;
4080
+ ListCache$1.prototype.set = listCacheSet;
4081
+ var _ListCache = ListCache$1;
4082
+ var getNative = _getNative,
4083
+ root = _root;
4084
+
4085
+ /* Built-in method references that are verified to be native. */
4086
+ var Map$2 = getNative(root, 'Map');
4087
+ var _Map = Map$2;
4088
+ var Hash = _Hash,
4089
+ ListCache = _ListCache,
4090
+ Map$1 = _Map;
4091
+
4092
+ /**
4093
+ * Removes all key-value entries from the map.
4094
+ *
4095
+ * @private
4096
+ * @name clear
4097
+ * @memberOf MapCache
4098
+ */
4099
+ function mapCacheClear$1() {
4100
+ this.size = 0;
4101
+ this.__data__ = {
4102
+ 'hash': new Hash(),
4103
+ 'map': new (Map$1 || ListCache)(),
4104
+ 'string': new Hash()
4105
+ };
4106
+ }
4107
+ var _mapCacheClear = mapCacheClear$1;
4108
+
4109
+ /**
4110
+ * Checks if `value` is suitable for use as unique object key.
4111
+ *
4112
+ * @private
4113
+ * @param {*} value The value to check.
4114
+ * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
4115
+ */
4116
+
4117
+ function isKeyable$1(value) {
4118
+ var type = typeof value;
4119
+ return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
4120
+ }
4121
+ var _isKeyable = isKeyable$1;
4122
+ var isKeyable = _isKeyable;
4123
+
4124
+ /**
4125
+ * Gets the data for `map`.
4126
+ *
4127
+ * @private
4128
+ * @param {Object} map The map to query.
4129
+ * @param {string} key The reference key.
4130
+ * @returns {*} Returns the map data.
4131
+ */
4132
+ function getMapData$4(map, key) {
4133
+ var data = map.__data__;
4134
+ return isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
4135
+ }
4136
+ var _getMapData = getMapData$4;
4137
+ var getMapData$3 = _getMapData;
4138
+
4139
+ /**
4140
+ * Removes `key` and its value from the map.
4141
+ *
4142
+ * @private
4143
+ * @name delete
4144
+ * @memberOf MapCache
4145
+ * @param {string} key The key of the value to remove.
4146
+ * @returns {boolean} Returns `true` if the entry was removed, else `false`.
4147
+ */
4148
+ function mapCacheDelete$1(key) {
4149
+ var result = getMapData$3(this, key)['delete'](key);
4150
+ this.size -= result ? 1 : 0;
4151
+ return result;
4152
+ }
4153
+ var _mapCacheDelete = mapCacheDelete$1;
4154
+ var getMapData$2 = _getMapData;
4155
+
4156
+ /**
4157
+ * Gets the map value for `key`.
4158
+ *
4159
+ * @private
4160
+ * @name get
4161
+ * @memberOf MapCache
4162
+ * @param {string} key The key of the value to get.
4163
+ * @returns {*} Returns the entry value.
4164
+ */
4165
+ function mapCacheGet$1(key) {
4166
+ return getMapData$2(this, key).get(key);
4167
+ }
4168
+ var _mapCacheGet = mapCacheGet$1;
4169
+ var getMapData$1 = _getMapData;
4170
+
4171
+ /**
4172
+ * Checks if a map value for `key` exists.
4173
+ *
4174
+ * @private
4175
+ * @name has
4176
+ * @memberOf MapCache
4177
+ * @param {string} key The key of the entry to check.
4178
+ * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
4179
+ */
4180
+ function mapCacheHas$1(key) {
4181
+ return getMapData$1(this, key).has(key);
4182
+ }
4183
+ var _mapCacheHas = mapCacheHas$1;
4184
+ var getMapData = _getMapData;
4185
+
4186
+ /**
4187
+ * Sets the map `key` to `value`.
4188
+ *
4189
+ * @private
4190
+ * @name set
4191
+ * @memberOf MapCache
4192
+ * @param {string} key The key of the value to set.
4193
+ * @param {*} value The value to set.
4194
+ * @returns {Object} Returns the map cache instance.
4195
+ */
4196
+ function mapCacheSet$1(key, value) {
4197
+ var data = getMapData(this, key),
4198
+ size = data.size;
4199
+ data.set(key, value);
4200
+ this.size += data.size == size ? 0 : 1;
4201
+ return this;
4202
+ }
4203
+ var _mapCacheSet = mapCacheSet$1;
4204
+ var mapCacheClear = _mapCacheClear,
4205
+ mapCacheDelete = _mapCacheDelete,
4206
+ mapCacheGet = _mapCacheGet,
4207
+ mapCacheHas = _mapCacheHas,
4208
+ mapCacheSet = _mapCacheSet;
4209
+
4210
+ /**
4211
+ * Creates a map cache object to store key-value pairs.
4212
+ *
4213
+ * @private
4214
+ * @constructor
4215
+ * @param {Array} [entries] The key-value pairs to cache.
4216
+ */
4217
+ function MapCache$1(entries) {
4218
+ var index = -1,
4219
+ length = entries == null ? 0 : entries.length;
4220
+ this.clear();
4221
+ while (++index < length) {
4222
+ var entry = entries[index];
4223
+ this.set(entry[0], entry[1]);
4224
+ }
4225
+ }
4226
+
4227
+ // Add methods to `MapCache`.
4228
+ MapCache$1.prototype.clear = mapCacheClear;
4229
+ MapCache$1.prototype['delete'] = mapCacheDelete;
4230
+ MapCache$1.prototype.get = mapCacheGet;
4231
+ MapCache$1.prototype.has = mapCacheHas;
4232
+ MapCache$1.prototype.set = mapCacheSet;
4233
+ var _MapCache = MapCache$1;
4234
+ var MapCache = _MapCache;
4235
+
4236
+ /** Error message constants. */
4237
+ var FUNC_ERROR_TEXT = 'Expected a function';
4238
+
4239
+ /**
4240
+ * Creates a function that memoizes the result of `func`. If `resolver` is
4241
+ * provided, it determines the cache key for storing the result based on the
4242
+ * arguments provided to the memoized function. By default, the first argument
4243
+ * provided to the memoized function is used as the map cache key. The `func`
4244
+ * is invoked with the `this` binding of the memoized function.
4245
+ *
4246
+ * **Note:** The cache is exposed as the `cache` property on the memoized
4247
+ * function. Its creation may be customized by replacing the `_.memoize.Cache`
4248
+ * constructor with one whose instances implement the
4249
+ * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
4250
+ * method interface of `clear`, `delete`, `get`, `has`, and `set`.
4251
+ *
4252
+ * @static
4253
+ * @memberOf _
4254
+ * @since 0.1.0
4255
+ * @category Function
4256
+ * @param {Function} func The function to have its output memoized.
4257
+ * @param {Function} [resolver] The function to resolve the cache key.
4258
+ * @returns {Function} Returns the new memoized function.
4259
+ * @example
4260
+ *
4261
+ * var object = { 'a': 1, 'b': 2 };
4262
+ * var other = { 'c': 3, 'd': 4 };
4263
+ *
4264
+ * var values = _.memoize(_.values);
4265
+ * values(object);
4266
+ * // => [1, 2]
4267
+ *
4268
+ * values(other);
4269
+ * // => [3, 4]
4270
+ *
4271
+ * object.a = 2;
4272
+ * values(object);
4273
+ * // => [1, 2]
4274
+ *
4275
+ * // Modify the result cache.
4276
+ * values.cache.set(object, ['a', 'b']);
4277
+ * values(object);
4278
+ * // => ['a', 'b']
4279
+ *
4280
+ * // Replace `_.memoize.Cache`.
4281
+ * _.memoize.Cache = WeakMap;
4282
+ */
4283
+ function memoize$1(func, resolver) {
4284
+ if (typeof func != 'function' || resolver != null && typeof resolver != 'function') {
4285
+ throw new TypeError(FUNC_ERROR_TEXT);
4286
+ }
4287
+ var memoized = function () {
4288
+ var args = arguments,
4289
+ key = resolver ? resolver.apply(this, args) : args[0],
4290
+ cache = memoized.cache;
4291
+ if (cache.has(key)) {
4292
+ return cache.get(key);
4293
+ }
4294
+ var result = func.apply(this, args);
4295
+ memoized.cache = cache.set(key, result) || cache;
4296
+ return result;
4297
+ };
4298
+ memoized.cache = new (memoize$1.Cache || MapCache)();
4299
+ return memoized;
4300
+ }
4301
+
4302
+ // Expose `MapCache`.
4303
+ memoize$1.Cache = MapCache;
4304
+ var memoize_1 = memoize$1;
4305
+ var memoize = memoize_1;
4306
+
4307
+ /** Used as the maximum memoize cache size. */
4308
+ var MAX_MEMOIZE_SIZE = 500;
4309
+
4310
+ /**
4311
+ * A specialized version of `_.memoize` which clears the memoized function's
4312
+ * cache when it exceeds `MAX_MEMOIZE_SIZE`.
4313
+ *
4314
+ * @private
4315
+ * @param {Function} func The function to have its output memoized.
4316
+ * @returns {Function} Returns the new memoized function.
4317
+ */
4318
+ function memoizeCapped$1(func) {
4319
+ var result = memoize(func, function (key) {
4320
+ if (cache.size === MAX_MEMOIZE_SIZE) {
4321
+ cache.clear();
4322
+ }
4323
+ return key;
4324
+ });
4325
+ var cache = result.cache;
4326
+ return result;
4327
+ }
4328
+ var _memoizeCapped = memoizeCapped$1;
4329
+ var memoizeCapped = _memoizeCapped;
4330
+
4331
+ /** Used to match property names within property paths. */
4332
+ var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
4333
+
4334
+ /** Used to match backslashes in property paths. */
4335
+ var reEscapeChar = /\\(\\)?/g;
4336
+
4337
+ /**
4338
+ * Converts `string` to a property path array.
4339
+ *
4340
+ * @private
4341
+ * @param {string} string The string to convert.
4342
+ * @returns {Array} Returns the property path array.
4343
+ */
4344
+ var stringToPath$1 = memoizeCapped(function (string) {
4345
+ var result = [];
4346
+ if (string.charCodeAt(0) === 46 /* . */) {
4347
+ result.push('');
4348
+ }
4349
+ string.replace(rePropName, function (match, number, quote, subString) {
4350
+ result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match);
4351
+ });
4352
+ return result;
4353
+ });
4354
+ var _stringToPath = stringToPath$1;
4355
+
4356
+ /**
4357
+ * A specialized version of `_.map` for arrays without support for iteratee
4358
+ * shorthands.
4359
+ *
4360
+ * @private
4361
+ * @param {Array} [array] The array to iterate over.
4362
+ * @param {Function} iteratee The function invoked per iteration.
4363
+ * @returns {Array} Returns the new mapped array.
4364
+ */
4365
+
4366
+ function arrayMap$1(array, iteratee) {
4367
+ var index = -1,
4368
+ length = array == null ? 0 : array.length,
4369
+ result = Array(length);
4370
+ while (++index < length) {
4371
+ result[index] = iteratee(array[index], index, array);
4372
+ }
4373
+ return result;
4374
+ }
4375
+ var _arrayMap = arrayMap$1;
4376
+ var Symbol = _Symbol,
4377
+ arrayMap = _arrayMap,
4378
+ isArray$1 = isArray_1,
4379
+ isSymbol$1 = isSymbol_1;
4380
+
4381
+ /** Used as references for various `Number` constants. */
4382
+ var INFINITY$1 = 1 / 0;
4383
+
4384
+ /** Used to convert symbols to primitives and strings. */
4385
+ var symbolProto = Symbol ? Symbol.prototype : undefined,
4386
+ symbolToString = symbolProto ? symbolProto.toString : undefined;
4387
+
4388
+ /**
4389
+ * The base implementation of `_.toString` which doesn't convert nullish
4390
+ * values to empty strings.
4391
+ *
4392
+ * @private
4393
+ * @param {*} value The value to process.
4394
+ * @returns {string} Returns the string.
4395
+ */
4396
+ function baseToString$1(value) {
4397
+ // Exit early for strings to avoid a performance hit in some environments.
4398
+ if (typeof value == 'string') {
4399
+ return value;
4400
+ }
4401
+ if (isArray$1(value)) {
4402
+ // Recursively convert values (susceptible to call stack limits).
4403
+ return arrayMap(value, baseToString$1) + '';
4404
+ }
4405
+ if (isSymbol$1(value)) {
4406
+ return symbolToString ? symbolToString.call(value) : '';
4407
+ }
4408
+ var result = value + '';
4409
+ return result == '0' && 1 / value == -INFINITY$1 ? '-0' : result;
4410
+ }
4411
+ var _baseToString = baseToString$1;
4412
+ var baseToString = _baseToString;
4413
+
4414
+ /**
4415
+ * Converts `value` to a string. An empty string is returned for `null`
4416
+ * and `undefined` values. The sign of `-0` is preserved.
4417
+ *
4418
+ * @static
4419
+ * @memberOf _
4420
+ * @since 4.0.0
4421
+ * @category Lang
4422
+ * @param {*} value The value to convert.
4423
+ * @returns {string} Returns the converted string.
4424
+ * @example
4425
+ *
4426
+ * _.toString(null);
4427
+ * // => ''
4428
+ *
4429
+ * _.toString(-0);
4430
+ * // => '-0'
4431
+ *
4432
+ * _.toString([1, 2, 3]);
4433
+ * // => '1,2,3'
4434
+ */
4435
+ function toString$1(value) {
4436
+ return value == null ? '' : baseToString(value);
4437
+ }
4438
+ var toString_1 = toString$1;
4439
+ var isArray = isArray_1,
4440
+ isKey = _isKey,
4441
+ stringToPath = _stringToPath,
4442
+ toString = toString_1;
4443
+
4444
+ /**
4445
+ * Casts `value` to a path array if it's not one.
4446
+ *
4447
+ * @private
4448
+ * @param {*} value The value to inspect.
4449
+ * @param {Object} [object] The object to query keys on.
4450
+ * @returns {Array} Returns the cast property path array.
4451
+ */
4452
+ function castPath$1(value, object) {
4453
+ if (isArray(value)) {
4454
+ return value;
4455
+ }
4456
+ return isKey(value, object) ? [value] : stringToPath(toString(value));
4457
+ }
4458
+ var _castPath = castPath$1;
4459
+ var isSymbol = isSymbol_1;
4460
+
4461
+ /** Used as references for various `Number` constants. */
4462
+ var INFINITY = 1 / 0;
4463
+
4464
+ /**
4465
+ * Converts `value` to a string key if it's not a string or symbol.
4466
+ *
4467
+ * @private
4468
+ * @param {*} value The value to inspect.
4469
+ * @returns {string|symbol} Returns the key.
4470
+ */
4471
+ function toKey$1(value) {
4472
+ if (typeof value == 'string' || isSymbol(value)) {
4473
+ return value;
4474
+ }
4475
+ var result = value + '';
4476
+ return result == '0' && 1 / value == -INFINITY ? '-0' : result;
4477
+ }
4478
+ var _toKey = toKey$1;
4479
+ var castPath = _castPath,
4480
+ toKey = _toKey;
4481
+
4482
+ /**
4483
+ * The base implementation of `_.get` without support for default values.
4484
+ *
4485
+ * @private
4486
+ * @param {Object} object The object to query.
4487
+ * @param {Array|string} path The path of the property to get.
4488
+ * @returns {*} Returns the resolved value.
4489
+ */
4490
+ function baseGet$1(object, path) {
4491
+ path = castPath(path, object);
4492
+ var index = 0,
4493
+ length = path.length;
4494
+ while (object != null && index < length) {
4495
+ object = object[toKey(path[index++])];
4496
+ }
4497
+ return index && index == length ? object : undefined;
4498
+ }
4499
+ var _baseGet = baseGet$1;
4500
+ var baseGet = _baseGet;
4501
+
4502
+ /**
4503
+ * Gets the value at `path` of `object`. If the resolved value is
4504
+ * `undefined`, the `defaultValue` is returned in its place.
4505
+ *
4506
+ * @static
4507
+ * @memberOf _
4508
+ * @since 3.7.0
4509
+ * @category Object
4510
+ * @param {Object} object The object to query.
4511
+ * @param {Array|string} path The path of the property to get.
4512
+ * @param {*} [defaultValue] The value returned for `undefined` resolved values.
4513
+ * @returns {*} Returns the resolved value.
4514
+ * @example
4515
+ *
4516
+ * var object = { 'a': [{ 'b': { 'c': 3 } }] };
4517
+ *
4518
+ * _.get(object, 'a[0].b.c');
4519
+ * // => 3
4520
+ *
4521
+ * _.get(object, ['a', '0', 'b', 'c']);
4522
+ * // => 3
4523
+ *
4524
+ * _.get(object, 'a.b.c', 'default');
4525
+ * // => 'default'
4526
+ */
4527
+ function get(object, path, defaultValue) {
4528
+ var result = object == null ? undefined : baseGet(object, path);
4529
+ return result === undefined ? defaultValue : result;
4530
+ }
4531
+ var get_1 = get;
4532
+ var get$1 = /*@__PURE__*/getDefaultExportFromCjs(get_1);
4533
+ const getLanguageParams = (select, document) => {
4534
+ if (!select || !document) {
4535
+ return {};
4536
+ }
4537
+ const selection = select || {};
4538
+ const selectedValue = {};
4539
+ for (const [key, path] of Object.entries(selection)) {
4540
+ let value = get$1(document, path);
4541
+ if (Array.isArray(value)) {
4542
+ value = value.filter(item => typeof item === "object" ? (item == null ? void 0 : item._type) !== "reference" || "_ref" in item : true);
4543
+ }
4544
+ selectedValue[key] = value;
4545
+ }
4546
+ return selectedValue;
4547
+ };
4548
+ const FieldTranslationContext = createContext({
4549
+ openFieldTranslation: () => {},
4550
+ translationLoading: false
4551
+ //loadLanguages: () => {},
4552
+ });
4553
+ function useFieldTranslation() {
4554
+ return useContext(FieldTranslationContext);
4555
+ }
4556
+ function FieldTranslationProvider(props) {
4557
+ var _a, _b;
4558
+ const {
4559
+ config: assistConfig
4560
+ } = useAiAssistanceConfig();
4561
+ const apiClient = useApiClient(assistConfig.__customApiClient);
4562
+ const config = (_a = assistConfig.translate) == null ? void 0 : _a.field;
4563
+ const {
4564
+ translate: runTranslate
4565
+ } = useTranslate(apiClient);
4566
+ const [dialogOpen, setDialogOpen] = useState(false);
4567
+ const [document, setDocument] = useState();
4568
+ const [documentSchema, setDocumentSchema] = useState();
4569
+ const [languages, setLanguages] = useState();
4570
+ const [fromLanguage, setFromLanguage] = useState(void 0);
4571
+ const [toLanguages, setToLanguages] = useState(void 0);
4572
+ const [translationMap, setTranslationMap] = useState();
4573
+ const close = useCallback(() => {
4574
+ setDialogOpen(false);
4575
+ setLanguages(void 0);
4576
+ setDocument(void 0);
4577
+ setDocument(void 0);
4578
+ }, []);
4579
+ const languageClient = useClient({
4580
+ apiVersion: (_b = config == null ? void 0 : config.apiVersion) != null ? _b : "2022-11-27"
4581
+ });
4582
+ const documentId = document == null ? void 0 : document._id;
4583
+ const id = useId();
4584
+ const selectFromLanguage = useCallback((from, languages2, document2, documentSchema2) => {
4585
+ var _a2, _b2;
4586
+ setFromLanguage(from);
4587
+ if (!document2 || !documentSchema2 || !languages2) {
4588
+ setTranslationMap(void 0);
4589
+ return;
4590
+ }
4591
+ const to = languages2.filter(l => l.id !== (from == null ? void 0 : from.id));
4592
+ setToLanguages(to);
4593
+ const fromId = from == null ? void 0 : from.id;
4594
+ const toIds = (_a2 = to == null ? void 0 : to.map(l => l.id)) != null ? _a2 : [];
4595
+ const docMembers = getDocumentMembersFlat(document2, documentSchema2);
4596
+ if (fromId && (toIds == null ? void 0 : toIds.length)) {
4597
+ const transMap = getTranslationMap(documentSchema2, docMembers, fromId, toIds, (_b2 = config == null ? void 0 : config.translationOutputs) != null ? _b2 : defaultLanguageOutputs);
4598
+ setTranslationMap(transMap);
4599
+ } else {
4600
+ setTranslationMap(void 0);
4601
+ }
4602
+ }, [config]);
4603
+ const toggleToLanguage = useCallback((toggledLang, toLanguages2, languages2) => {
4604
+ if (!languages2) {
4605
+ return;
4606
+ }
4607
+ const wasSelected = !!(toLanguages2 == null ? void 0 : toLanguages2.find(l => l.id === toggledLang.id));
4608
+ 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);
4609
+ setToLanguages(newToLangs);
4610
+ }, []);
4611
+ const openFieldTranslation = useCallback(async _ref11 => {
4612
+ let {
4613
+ document: document2,
4614
+ documentSchema: documentSchema2
4615
+ } = _ref11;
4616
+ setDialogOpen(true);
4617
+ const languageParams = getLanguageParams(config == null ? void 0 : config.selectLanguageParams, document2);
4618
+ 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));
4619
+ setLanguages(languages2);
4620
+ setDocument(document2);
4621
+ setDocumentSchema(documentSchema2);
4622
+ const fromLanguage2 = languages2 == null ? void 0 : languages2[0];
4623
+ if (fromLanguage2) {
4624
+ selectFromLanguage(fromLanguage2, languages2, document2, documentSchema2);
4625
+ } else {
4626
+ console.error("No languages available for selected language params", languageParams);
4627
+ }
4628
+ }, [selectFromLanguage, config, languageClient]);
4629
+ const contextValue = useMemo(() => {
4630
+ return {
4631
+ openFieldTranslation,
4632
+ translationLoading: false
4633
+ };
4634
+ }, [openFieldTranslation]);
4635
+ const runDisabled = !fromLanguage || !(toLanguages == null ? void 0 : toLanguages.length) || !(translationMap == null ? void 0 : translationMap.length) || !documentId;
4636
+ const onRunTranslation = useCallback(() => {
4637
+ if (translationMap && documentId) {
4638
+ runTranslate({
4639
+ documentId,
4640
+ fieldLanguageMap: translationMap.map(map => ({
4641
+ ...map,
4642
+ // eslint-disable-next-line max-nested-callbacks
4643
+ outputs: map.outputs.filter(out => !!(toLanguages == null ? void 0 : toLanguages.find(l => l.id === out.id)))
4644
+ }))
4645
+ });
4646
+ }
4647
+ close();
4648
+ }, [translationMap, documentId, runTranslate, close, toLanguages]);
4649
+ const runButton = /* @__PURE__ */jsx(Button, {
4650
+ text: "Translate",
4651
+ tone: "primary",
4652
+ icon: PlayIcon,
4653
+ style: {
4654
+ width: "100%"
4655
+ },
4656
+ disabled: runDisabled,
4657
+ onClick: onRunTranslation
4658
+ });
4659
+ return /* @__PURE__ */jsxs(FieldTranslationContext.Provider, {
4660
+ value: contextValue,
4661
+ children: [dialogOpen ? /* @__PURE__ */jsx(Dialog, {
4662
+ id,
4663
+ width: 1,
4664
+ open: dialogOpen,
4665
+ onClose: close,
4666
+ header: "Translate fields",
4667
+ footer: /* @__PURE__ */jsx(Flex, {
4668
+ justify: "space-between",
4669
+ padding: 2,
4670
+ flex: 1,
4671
+ children: runDisabled ? /* @__PURE__ */jsx(Tooltip, {
4672
+ content: /* @__PURE__ */jsx(Flex, {
4673
+ padding: 2,
4674
+ children: /* @__PURE__ */jsx(Text, {
4675
+ children: "Nothing to translate."
4676
+ })
4677
+ }),
4678
+ placement: "top",
4679
+ children: /* @__PURE__ */jsx(Flex, {
4680
+ flex: 1,
4681
+ children: runButton
4682
+ })
4683
+ }) : runButton
4684
+ }),
4685
+ children: languages ? /* @__PURE__ */jsxs(Flex, {
4686
+ padding: 4,
4687
+ gap: 5,
4688
+ align: "flex-start",
4689
+ justify: "center",
4690
+ children: [/* @__PURE__ */jsxs(Stack, {
4691
+ space: 2,
4692
+ children: [/* @__PURE__ */jsx(Box, {
4693
+ marginBottom: 2,
4694
+ children: /* @__PURE__ */jsx(Text, {
4695
+ weight: "semibold",
4696
+ children: "From"
4697
+ })
4698
+ }), languages == null ? void 0 : languages.map(l => {
4699
+ var _a2;
4700
+ return /* @__PURE__ */jsxs(Flex, {
4701
+ gap: 3,
4702
+ align: "center",
4703
+ children: [/* @__PURE__ */jsx(Radio, {
4704
+ name: "fromLang",
4705
+ value: l.id,
4706
+ checked: l.id === (fromLanguage == null ? void 0 : fromLanguage.id),
4707
+ onClick: () => selectFromLanguage(l, languages, document, documentSchema)
4708
+ }), /* @__PURE__ */jsx(Text, {
4709
+ children: (_a2 = l.title) != null ? _a2 : l.id
4710
+ })]
4711
+ }, l.id);
4712
+ })]
4713
+ }), /* @__PURE__ */jsxs(Stack, {
4714
+ space: 2,
4715
+ children: [/* @__PURE__ */jsx(Box, {
4716
+ marginBottom: 2,
4717
+ children: /* @__PURE__ */jsx(Text, {
4718
+ weight: "semibold",
4719
+ children: "To"
4720
+ })
4721
+ }), languages == null ? void 0 : languages.filter(l => l.id !== (fromLanguage == null ? void 0 : fromLanguage.id)).map(l => {
4722
+ var _a2;
4723
+ return /* @__PURE__ */jsxs(Flex, {
4724
+ gap: 3,
4725
+ align: "center",
4726
+ children: [/* @__PURE__ */jsx(Checkbox, {
4727
+ name: "toLang",
4728
+ value: l.id,
4729
+ checked: !!(toLanguages == null ? void 0 : toLanguages.find(tl => tl.id === l.id)),
4730
+ onClick: () => toggleToLanguage(l, toLanguages, languages),
4731
+ disabled: !(translationMap == null ? void 0 : translationMap.find(tm => tm.outputs.find(o => o.id === l.id)))
4732
+ }), /* @__PURE__ */jsx(Text, {
4733
+ children: (_a2 = l.title) != null ? _a2 : l.id
4734
+ })]
4735
+ }, l.id);
4736
+ })]
4737
+ })]
4738
+ }) : /* @__PURE__ */jsxs(Flex, {
4739
+ padding: 4,
4740
+ gap: 2,
4741
+ align: "flex-start",
4742
+ justify: "center",
4743
+ children: [/* @__PURE__ */jsx(Box, {
4744
+ children: /* @__PURE__ */jsx(Spinner, {})
4745
+ }), /* @__PURE__ */jsx(Text, {
4746
+ children: "Loading languages..."
4747
+ })]
4748
+ })
4749
+ }) : null, props.children]
4750
+ });
4751
+ }
3201
4752
  function AssistLayout(props) {
3202
4753
  var _a;
3203
4754
  const [connectors, setConnectors] = useState([]);
@@ -3205,14 +4756,16 @@ function AssistLayout(props) {
3205
4756
  return /* @__PURE__ */jsxs(AiAssistanceConfigProvider, {
3206
4757
  config: props.config,
3207
4758
  children: [migrate ? /* @__PURE__ */jsx(AlphaMigration, {}) : null, /* @__PURE__ */jsx(RunInstructionProvider, {
3208
- children: /* @__PURE__ */jsxs(ConnectorsProvider, {
3209
- onConnectorsChange: setConnectors,
3210
- children: [props.renderDefault(props), /* @__PURE__ */jsx(ThemeProvider, {
3211
- tone: "default",
3212
- children: /* @__PURE__ */jsx(AssistConnectorsOverlay, {
3213
- connectors
3214
- })
3215
- })]
4759
+ children: /* @__PURE__ */jsx(FieldTranslationProvider, {
4760
+ children: /* @__PURE__ */jsxs(ConnectorsProvider, {
4761
+ onConnectorsChange: setConnectors,
4762
+ children: [props.renderDefault(props), /* @__PURE__ */jsx(ThemeProvider, {
4763
+ tone: "default",
4764
+ children: /* @__PURE__ */jsx(AssistConnectorsOverlay, {
4765
+ connectors
4766
+ })
4767
+ })]
4768
+ })
3216
4769
  })
3217
4770
  })]
3218
4771
  });
@@ -3308,6 +4861,7 @@ function AssistFormBlock(props) {
3308
4861
  _key: key
3309
4862
  }));
3310
4863
  }, [onChange, key]);
4864
+ const singlePresence = presence[0];
3311
4865
  return /* @__PURE__ */jsx(ErrorWrapper, {
3312
4866
  onChange: localOnChange,
3313
4867
  children: /* @__PURE__ */jsxs(Flex, {
@@ -3316,9 +4870,9 @@ function AssistFormBlock(props) {
3316
4870
  children: [/* @__PURE__ */jsx(Box, {
3317
4871
  flex: 1,
3318
4872
  children: props.renderDefault(props)
3319
- }), presence.map(pre => /* @__PURE__ */jsx(AiFieldPresence, {
3320
- presence: pre
3321
- }, pre.lastActiveAt))]
4873
+ }), singlePresence && /* @__PURE__ */jsx(AiFieldPresence, {
4874
+ presence: singlePresence
4875
+ })]
3322
4876
  })
3323
4877
  });
3324
4878
  }
@@ -3362,16 +4916,24 @@ function InstructionInput(props) {
3362
4916
  ...props
3363
4917
  }), /* @__PURE__ */jsx(ShareField, {
3364
4918
  ...props
3365
- }), /* @__PURE__ */jsx(PromptField, {
4919
+ }), /* @__PURE__ */jsx(ObjectMember, {
4920
+ fieldName: "prompt",
4921
+ ...props
4922
+ }), /* @__PURE__ */jsx(ObjectMember, {
4923
+ fieldName: "output",
3366
4924
  ...props
3367
4925
  })]
3368
4926
  });
3369
4927
  }
3370
- function PromptField(props) {
3371
- const promptMember = findFieldMember(props.members, "prompt");
3372
- return promptMember ? /* @__PURE__ */jsx(ObjectInputMember, {
4928
+ function ObjectMember(_ref12) {
4929
+ let {
4930
+ fieldName,
4931
+ ...props
4932
+ } = _ref12;
4933
+ const member = findFieldMember(props.members, fieldName);
4934
+ return member ? /* @__PURE__ */jsx(ObjectInputMember, {
3373
4935
  ...props,
3374
- member: promptMember
4936
+ member
3375
4937
  }) : null;
3376
4938
  }
3377
4939
  const NONE = [];
@@ -3506,8 +5068,8 @@ function IconInput(props) {
3506
5068
  onChange
3507
5069
  } = props;
3508
5070
  const id = useId();
3509
- const items = useMemo(() => Object.entries(icons).map(_ref10 => {
3510
- let [key, icon] = _ref10;
5071
+ const items = useMemo(() => Object.entries(icons).map(_ref13 => {
5072
+ let [key, icon] = _ref13;
3511
5073
  return /* @__PURE__ */jsx(IconItem, {
3512
5074
  iconKey: key,
3513
5075
  icon,
@@ -3535,12 +5097,12 @@ function IconInput(props) {
3535
5097
  }
3536
5098
  });
3537
5099
  }
3538
- function IconItem(_ref11) {
5100
+ function IconItem(_ref14) {
3539
5101
  let {
3540
5102
  icon,
3541
5103
  iconKey: key,
3542
5104
  onChange
3543
- } = _ref11;
5105
+ } = _ref14;
3544
5106
  const onClick = useCallback(() => onChange(set(key)), [onChange, key]);
3545
5107
  return /* @__PURE__ */jsx(MenuItem, {
3546
5108
  icon,
@@ -3551,8 +5113,8 @@ function IconItem(_ref11) {
3551
5113
  }
3552
5114
  function getIcon(iconName) {
3553
5115
  var _a, _b;
3554
- return (_b = (_a = Object.entries(icons).find(_ref12 => {
3555
- let [key] = _ref12;
5116
+ return (_b = (_a = Object.entries(icons).find(_ref15 => {
5117
+ let [key] = _ref15;
3556
5118
  return key === iconName;
3557
5119
  })) == null ? void 0 : _a[1]) != null ? _b : icons.sparkles;
3558
5120
  }
@@ -3711,11 +5273,11 @@ const contextDocumentSchema = defineType({
3711
5273
  title: "title",
3712
5274
  context: "context"
3713
5275
  },
3714
- prepare(_ref13) {
5276
+ prepare(_ref16) {
3715
5277
  let {
3716
5278
  title,
3717
5279
  context
3718
- } = _ref13;
5280
+ } = _ref16;
3719
5281
  var _a;
3720
5282
  const text = context == null ? void 0 : context.flatMap(block => block == null ? void 0 : block.children).flatMap(child => {
3721
5283
  var _a2;
@@ -3801,6 +5363,200 @@ function InstructionsArrayField(props) {
3801
5363
  title: " "
3802
5364
  });
3803
5365
  }
5366
+ function InstructionOutputField(props) {
5367
+ var _a;
5368
+ const {
5369
+ fieldSchema
5370
+ } = (_a = useContext(SelectedFieldContext)) != null ? _a : {};
5371
+ if (!fieldSchema || !(isObjectSchemaType(fieldSchema) || isArrayOfObjectsSchemaType(fieldSchema))) {
5372
+ return null;
5373
+ }
5374
+ return /* @__PURE__ */jsx(EnabledOutputField, {
5375
+ ...props,
5376
+ fieldSchema,
5377
+ children: props.children
5378
+ });
5379
+ }
5380
+ function EnabledOutputField(_ref17) {
5381
+ let {
5382
+ fieldSchema,
5383
+ ...props
5384
+ } = _ref17;
5385
+ var _a;
5386
+ const [open, setOpen] = useState(!!((_a = props.value) == null ? void 0 : _a.length));
5387
+ const onExpand = useCallback(() => setOpen(true), []);
5388
+ const onCollapse = useCallback(() => setOpen(false), []);
5389
+ return props.renderDefault({
5390
+ ...props,
5391
+ collapsible: true,
5392
+ onExpand,
5393
+ onCollapse,
5394
+ collapsed: !open,
5395
+ level: 1,
5396
+ title: isObjectSchemaType(fieldSchema) ? "Allowed fields" : "Allowed types"
5397
+ });
5398
+ }
5399
+ function InstructionOutputInput(props) {
5400
+ var _a;
5401
+ const {
5402
+ fieldSchema
5403
+ } = (_a = useContext(SelectedFieldContext)) != null ? _a : {};
5404
+ if (!fieldSchema) {
5405
+ return null;
5406
+ }
5407
+ if (isObjectSchemaType(fieldSchema)) {
5408
+ return /* @__PURE__ */jsx(ObjectOutputInput, {
5409
+ ...props,
5410
+ fieldSchema
5411
+ });
5412
+ }
5413
+ if (isArrayOfObjectsSchemaType(fieldSchema)) {
5414
+ return /* @__PURE__ */jsx(ArrayOutputInput, {
5415
+ ...props,
5416
+ fieldSchema
5417
+ });
5418
+ }
5419
+ return null;
5420
+ }
5421
+ function useEmptySelectAllValue(value, allowedValues, onChange) {
5422
+ useEffect(() => {
5423
+ var _a, _b;
5424
+ const validValues = value == null ? void 0 : value.filter(v => allowedValues.find(f => f.name === (v._type === outputFieldTypeName ? v.relativePath : v.type)));
5425
+ const valueLength = (_a = value == null ? void 0 : value.length) != null ? _a : 0;
5426
+ const validLength = (_b = validValues == null ? void 0 : validValues.length) != null ? _b : 0;
5427
+ if (!validLength && valueLength || validLength >= allowedValues.length) {
5428
+ onChange(PatchEvent.from([unset()]));
5429
+ }
5430
+ }, [allowedValues, value, onChange]);
5431
+ }
5432
+ function ObjectOutputInput(_ref18) {
5433
+ let {
5434
+ fieldSchema,
5435
+ ...props
5436
+ } = _ref18;
5437
+ const {
5438
+ value,
5439
+ onChange
5440
+ } = props;
5441
+ const fields = useMemo(() => fieldSchema.fields.filter(field => isAssistSupported(field.type)), [fieldSchema.fields]);
5442
+ useEmptySelectAllValue(value, fields, onChange);
5443
+ const onSelectChange = useCallback((checked, selectedValue) => {
5444
+ if (checked) {
5445
+ if (value == null ? void 0 : value.length) {
5446
+ onChange(PatchEvent.from(unset([{
5447
+ _key: selectedValue
5448
+ }])));
5449
+ } else {
5450
+ const items = fields.filter(f => f.name !== selectedValue).map(field => typed({
5451
+ _key: field.name,
5452
+ _type: "sanity.assist.output.field",
5453
+ relativePath: field.name
5454
+ }));
5455
+ onChange(PatchEvent.from([setIfMissing([]), insert(items, "after", [-1])]));
5456
+ }
5457
+ } else {
5458
+ const patchValue = {
5459
+ _key: selectedValue,
5460
+ _type: "sanity.assist.output.field",
5461
+ relativePath: selectedValue
5462
+ };
5463
+ onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], "after", [-1])]));
5464
+ }
5465
+ }, [onChange, value, fields]);
5466
+ return /* @__PURE__ */jsx(Stack, {
5467
+ space: 2,
5468
+ children: fields.map(field => {
5469
+ var _a;
5470
+ return /* @__PURE__ */jsx(Flex, {
5471
+ align: "center",
5472
+ gap: 2,
5473
+ children: /* @__PURE__ */jsx(Selectable, {
5474
+ value: field.name,
5475
+ title: (_a = field.type.title) != null ? _a : field.name,
5476
+ arrayValue: value,
5477
+ onChange: onSelectChange
5478
+ })
5479
+ }, field.name);
5480
+ })
5481
+ });
5482
+ }
5483
+ function ArrayOutputInput(_ref19) {
5484
+ let {
5485
+ fieldSchema,
5486
+ ...props
5487
+ } = _ref19;
5488
+ const {
5489
+ value,
5490
+ onChange
5491
+ } = props;
5492
+ const ofItems = useMemo(() => fieldSchema.of.filter(itemType => isAssistSupported(itemType)), [fieldSchema.of]);
5493
+ useEmptySelectAllValue(value, ofItems, onChange);
5494
+ const onSelectChange = useCallback((checked, selectedValue) => {
5495
+ if (checked) {
5496
+ if (value == null ? void 0 : value.length) {
5497
+ onChange(PatchEvent.from(unset([{
5498
+ _key: selectedValue
5499
+ }])));
5500
+ } else {
5501
+ const items = ofItems.filter(f => f.name !== selectedValue).map(field => typed({
5502
+ _key: field.name,
5503
+ _type: "sanity.assist.output.type",
5504
+ type: field.name
5505
+ }));
5506
+ onChange(PatchEvent.from([setIfMissing([]), insert(items, "after", [-1])]));
5507
+ }
5508
+ } else {
5509
+ const patchValue = {
5510
+ _key: selectedValue,
5511
+ _type: "sanity.assist.output.type",
5512
+ type: selectedValue
5513
+ };
5514
+ onChange(PatchEvent.from([setIfMissing([]), insert([patchValue], "after", [-1])]));
5515
+ }
5516
+ }, [onChange, value, ofItems]);
5517
+ return /* @__PURE__ */jsx(Stack, {
5518
+ space: 2,
5519
+ children: ofItems.map(itemType => {
5520
+ var _a;
5521
+ return /* @__PURE__ */jsx(Flex, {
5522
+ children: /* @__PURE__ */jsx(Selectable, {
5523
+ value: itemType.name,
5524
+ title: isType(itemType, "block") ? "Text" : (_a = itemType.title) != null ? _a : itemType.name,
5525
+ arrayValue: value,
5526
+ onChange: onSelectChange
5527
+ })
5528
+ }, itemType.name);
5529
+ })
5530
+ });
5531
+ }
5532
+ function Selectable(_ref20) {
5533
+ let {
5534
+ title,
5535
+ arrayValue,
5536
+ value,
5537
+ onChange
5538
+ } = _ref20;
5539
+ const checked = !(arrayValue == null ? void 0 : arrayValue.length) || !!(arrayValue == null ? void 0 : arrayValue.find(v => v._key === value));
5540
+ const handleChange = useCallback(() => onChange(checked, value), [onChange, checked, value]);
5541
+ return /* @__PURE__ */jsxs(Flex, {
5542
+ gap: 2,
5543
+ align: "flex-start",
5544
+ children: [/* @__PURE__ */jsx(Checkbox, {
5545
+ checked,
5546
+ onChange: handleChange
5547
+ }), /* @__PURE__ */jsx(Card, {
5548
+ marginTop: 1,
5549
+ onClick: () => handleChange,
5550
+ children: /* @__PURE__ */jsx(Text, {
5551
+ style: {
5552
+ cursor: "default"
5553
+ },
5554
+ size: 1,
5555
+ children: title
5556
+ })
5557
+ })]
5558
+ });
5559
+ }
3804
5560
  const fieldReference = defineType({
3805
5561
  type: "object",
3806
5562
  name: fieldReferenceTypeName,
@@ -3844,10 +5600,10 @@ const fieldReference = defineType({
3844
5600
  select: {
3845
5601
  path: "path"
3846
5602
  },
3847
- prepare(_ref14) {
5603
+ prepare(_ref21) {
3848
5604
  let {
3849
5605
  path
3850
- } = _ref14;
5606
+ } = _ref21;
3851
5607
  return {
3852
5608
  title: path,
3853
5609
  path,
@@ -3974,7 +5730,6 @@ const prompt = defineType({
3974
5730
  type: userInput.name,
3975
5731
  }),*/]
3976
5732
  });
3977
-
3978
5733
  const instruction = defineType({
3979
5734
  type: "object",
3980
5735
  name: instructionTypeName,
@@ -3993,12 +5748,12 @@ const instruction = defineType({
3993
5748
  title: "title",
3994
5749
  userId: "userId"
3995
5750
  },
3996
- prepare: _ref15 => {
5751
+ prepare: _ref22 => {
3997
5752
  let {
3998
5753
  icon,
3999
5754
  title,
4000
5755
  userId
4001
- } = _ref15;
5756
+ } = _ref22;
4002
5757
  return {
4003
5758
  title,
4004
5759
  icon: icon ? icons[icon] : SparklesIcon,
@@ -4103,6 +5858,33 @@ const instruction = defineType({
4103
5858
  var _a, _b;
4104
5859
  return (_b = (_a = context.currentUser) == null ? void 0 : _a.id) != null ? _b : "";
4105
5860
  }
5861
+ }), defineField({
5862
+ type: "array",
5863
+ name: "output",
5864
+ title: "Output filter",
5865
+ components: {
5866
+ input: InstructionOutputInput,
5867
+ field: InstructionOutputField
5868
+ },
5869
+ of: [defineArrayMember({
5870
+ type: "object",
5871
+ name: outputFieldTypeName,
5872
+ title: "Output field",
5873
+ fields: [{
5874
+ type: "string",
5875
+ name: "path",
5876
+ title: "Path"
5877
+ }]
5878
+ }), defineArrayMember({
5879
+ type: "object",
5880
+ name: outputTypeTypeName,
5881
+ title: "Output type",
5882
+ fields: [{
5883
+ type: "string",
5884
+ name: "type",
5885
+ title: "Type"
5886
+ }]
5887
+ })]
4106
5888
  })]
4107
5889
  });
4108
5890
  const fieldInstructions = defineType({
@@ -4365,7 +6147,7 @@ function ImageContextProvider(props) {
4365
6147
  children: props.renderDefault(props)
4366
6148
  });
4367
6149
  }
4368
- function node$1(node2) {
6150
+ function node$2(node2) {
4369
6151
  return node2;
4370
6152
  }
4371
6153
  const generateCaptionsActions = {
@@ -4386,7 +6168,7 @@ const generateCaptionsActions = {
4386
6168
  documentId
4387
6169
  } = useAssistDocumentContext();
4388
6170
  return useMemo(() => {
4389
- return node$1({
6171
+ return node$2({
4390
6172
  type: "action",
4391
6173
  icon: loading ? () => /* @__PURE__ */jsx(Box, {
4392
6174
  style: {
@@ -4417,6 +6199,109 @@ const generateCaptionsActions = {
4417
6199
  return void 0;
4418
6200
  }
4419
6201
  };
6202
+ function node$1(node2) {
6203
+ return node2;
6204
+ }
6205
+ const translateActions = {
6206
+ name: "sanity-assist-translate",
6207
+ useAction(props) {
6208
+ var _a, _b, _c, _d, _e, _f, _g;
6209
+ const {
6210
+ config
6211
+ } = useAiAssistanceConfig();
6212
+ const apiClient = useApiClient(config == null ? void 0 : config.__customApiClient);
6213
+ const isDocumentLevel = props.path.length === 0;
6214
+ const {
6215
+ schemaType,
6216
+ documentId,
6217
+ documentIsAssistable
6218
+ } = props;
6219
+ const fieldTransEnabled = (_c = (_b = (_a = config.translate) == null ? void 0 : _a.field) == null ? void 0 : _b.documentTypes) == null ? void 0 : _c.includes(schemaType.name);
6220
+ const docTransTypes = (_e = (_d = config.translate) == null ? void 0 : _d.document) == null ? void 0 : _e.documentTypes;
6221
+ const documentTranslationEnabled = isDocumentLevel && (!docTransTypes && isAssistSupported(schemaType) || (docTransTypes == null ? void 0 : docTransTypes.includes(schemaType.name)));
6222
+ if (documentTranslationEnabled || fieldTransEnabled) {
6223
+ const {
6224
+ value: documentValue,
6225
+ onChange: documentOnChange
6226
+ } = useDocumentPane();
6227
+ const docRef = useRef(documentValue);
6228
+ const translationApi = useTranslate(apiClient);
6229
+ const translate = useDraftDelayedTask({
6230
+ documentOnChange,
6231
+ isDocAssistable: documentIsAssistable != null ? documentIsAssistable : false,
6232
+ task: translationApi.translate
6233
+ });
6234
+ docRef.current = documentValue;
6235
+ const languagePath = (_g = (_f = config.translate) == null ? void 0 : _f.document) == null ? void 0 : _g.languageField;
6236
+ const translateDocumentAction = useMemo(() => languagePath && documentTranslationEnabled ? node$1({
6237
+ type: "action",
6238
+ icon: translationApi.loading ? () => /* @__PURE__ */jsx(Box, {
6239
+ style: {
6240
+ height: 17
6241
+ },
6242
+ children: /* @__PURE__ */jsx(Spinner, {
6243
+ style: {
6244
+ transform: "translateY(6px)"
6245
+ }
6246
+ })
6247
+ }) : TranslateIcon,
6248
+ title: "Translate document",
6249
+ onAction: () => {
6250
+ if (translationApi.loading || !languagePath || !documentId) {
6251
+ return;
6252
+ }
6253
+ translate({
6254
+ languagePath,
6255
+ documentId: documentId != null ? documentId : ""
6256
+ });
6257
+ },
6258
+ renderAsButton: true,
6259
+ disabled: translationApi.loading
6260
+ }) : void 0, [languagePath, translate, documentId, translationApi.loading, documentTranslationEnabled]);
6261
+ const fieldTranslate = useFieldTranslation();
6262
+ const openFieldTranslation = useDraftDelayedTask({
6263
+ documentOnChange,
6264
+ isDocAssistable: documentIsAssistable != null ? documentIsAssistable : false,
6265
+ task: fieldTranslate.openFieldTranslation
6266
+ });
6267
+ const translateFieldsAction = useMemo(() => fieldTransEnabled ? node$1({
6268
+ type: "action",
6269
+ icon: fieldTranslate.translationLoading ? () => /* @__PURE__ */jsx(Box, {
6270
+ style: {
6271
+ height: 17
6272
+ },
6273
+ children: /* @__PURE__ */jsx(Spinner, {
6274
+ style: {
6275
+ transform: "translateY(6px)"
6276
+ }
6277
+ })
6278
+ }) : TranslateIcon,
6279
+ title: "Translate fields",
6280
+ onAction: () => {
6281
+ if (fieldTranslate.translationLoading || !documentId) {
6282
+ return;
6283
+ }
6284
+ openFieldTranslation({
6285
+ document: docRef.current,
6286
+ documentSchema: schemaType
6287
+ });
6288
+ },
6289
+ renderAsButton: true,
6290
+ disabled: fieldTranslate.translationLoading
6291
+ }) : void 0, [openFieldTranslation, schemaType, documentId, fieldTranslate.translationLoading, fieldTransEnabled]);
6292
+ return useMemo(() => {
6293
+ return node$1({
6294
+ type: "group",
6295
+ icon: () => null,
6296
+ title: "Translate",
6297
+ children: [translateDocumentAction, translateFieldsAction].filter(c => !!c),
6298
+ expanded: true
6299
+ });
6300
+ }, [translateDocumentAction, translateFieldsAction]);
6301
+ }
6302
+ return void 0;
6303
+ }
6304
+ };
4420
6305
  function node(node2) {
4421
6306
  return node2;
4422
6307
  }
@@ -4437,7 +6322,8 @@ const assistFieldActions = {
4437
6322
  documentOnChange,
4438
6323
  documentSchemaType,
4439
6324
  documentId,
4440
- selectedPath
6325
+ selectedPath,
6326
+ assistableDocumentId
4441
6327
  } =
4442
6328
  // document field actions do not have access to the document context
4443
6329
  // conditional hook _should_ be safe here since the logical path will be stable
@@ -4472,6 +6358,11 @@ const assistFieldActions = {
4472
6358
  const isPathSelected = pathKey === selectedPath;
4473
6359
  const isSelected = isInspectorOpen && isPathSelected;
4474
6360
  const imageCaptionAction = generateCaptionsActions.useAction(props);
6361
+ const translateAction = translateActions.useAction(typed({
6362
+ ...props,
6363
+ documentId: assistableDocumentId,
6364
+ documentIsAssistable
6365
+ }));
4475
6366
  const manageInstructions = useCallback(() => isSelected ? closeInspector(aiInspectorId) : openInspector(aiInspectorId, {
4476
6367
  [fieldPathParam]: pathKey,
4477
6368
  [instructionParam]: void 0
@@ -4498,7 +6389,7 @@ const assistFieldActions = {
4498
6389
  }, [fieldAssist == null ? void 0 : fieldAssist.instructions]);
4499
6390
  const instructions = useMemo(() => [...privateInstructions, ...sharedInstructions], [privateInstructions, sharedInstructions]);
4500
6391
  const runInstructionsGroup = useMemo(() => {
4501
- return (instructions == null ? void 0 : instructions.length) || imageCaptionAction ? node({
6392
+ return (instructions == null ? void 0 : instructions.length) || imageCaptionAction || translateAction ? node({
4502
6393
  type: "group",
4503
6394
  icon: () => null,
4504
6395
  title: "Run instructions",
@@ -4509,10 +6400,10 @@ const assistFieldActions = {
4509
6400
  hidden: isHidden,
4510
6401
  documentIsNew: !!documentIsNew,
4511
6402
  assistSupported
4512
- }))), imageCaptionAction].filter(Boolean),
6403
+ }))), imageCaptionAction].filter(a => !!a),
4513
6404
  expanded: true
4514
6405
  }) : void 0;
4515
- }, [instructions, currentUser == null ? void 0 : currentUser.id, onInstructionAction, isHidden, documentIsNew, assistSupported, imageCaptionAction]);
6406
+ }, [instructions, currentUser == null ? void 0 : currentUser.id, onInstructionAction, isHidden, documentIsNew, assistSupported, imageCaptionAction, translateAction]);
4516
6407
  const instructionsLength = (instructions == null ? void 0 : instructions.length) || 0;
4517
6408
  const manageInstructionsItem = useMemo(() => node({
4518
6409
  type: "action",
@@ -4525,13 +6416,13 @@ const assistFieldActions = {
4525
6416
  type: "group",
4526
6417
  icon: SparklesIcon,
4527
6418
  title: pluginTitleShort,
4528
- children: [runInstructionsGroup, assistSupported && manageInstructionsItem].filter(c => !!c),
6419
+ children: [runInstructionsGroup, translateAction, assistSupported && manageInstructionsItem].filter(c => !!c),
4529
6420
  expanded: false,
4530
6421
  renderAsButton: true,
4531
- hidden: !assistSupported && !imageCaptionAction
6422
+ hidden: !assistSupported && !imageCaptionAction && !translateAction
4532
6423
  }), [
4533
6424
  //documentIsNew,
4534
- runInstructionsGroup, manageInstructionsItem, assistSupported, imageCaptionAction]);
6425
+ runInstructionsGroup, manageInstructionsItem, assistSupported, imageCaptionAction, translateAction]);
4535
6426
  const emptyAction = useMemo(() => node({
4536
6427
  type: "action",
4537
6428
  hidden: !assistSupported,
@@ -4541,7 +6432,7 @@ const assistFieldActions = {
4541
6432
  title: pluginTitleShort,
4542
6433
  selected: isSelected
4543
6434
  }), [assistSupported, manageInstructions, isSelected]);
4544
- if (instructionsLength === 0 && !imageCaptionAction) {
6435
+ if (instructionsLength === 0 && !imageCaptionAction && !translateAction) {
4545
6436
  return emptyAction;
4546
6437
  }
4547
6438
  return group;
@@ -4654,11 +6545,11 @@ function AssistDocumentInputWrapper(props) {
4654
6545
  documentId
4655
6546
  });
4656
6547
  }
4657
- function AssistDocumentInput(_ref16) {
6548
+ function AssistDocumentInput(_ref23) {
4658
6549
  let {
4659
6550
  documentId,
4660
6551
  ...props
4661
- } = _ref16;
6552
+ } = _ref23;
4662
6553
  useInstructionToaster(documentId, props.schemaType);
4663
6554
  return /* @__PURE__ */jsx(FirstAssistedPathProvider, {
4664
6555
  members: props.members,
@@ -4703,11 +6594,11 @@ function AssistDocumentPresence(props) {
4703
6594
  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 => {
4704
6595
  var _a2;
4705
6596
  return (_a2 = run.presence) != null ? _a2 : [];
4706
- }).find(f => f.started && /* @__PURE__ */new Date().getTime() - new Date(f.started).getTime() < 3e4);
6597
+ }).find(f => f.started && ( /* @__PURE__ */new Date()).getTime() - new Date(f.started).getTime() < 3e4);
4707
6598
  if (anyPresence2) {
4708
6599
  return aiPresence(anyPresence2, []);
4709
6600
  }
4710
- 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);
6601
+ 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);
4711
6602
  return anyRun ? aiPresence({
4712
6603
  started: anyRun.started,
4713
6604
  path: documentRootKey,
@@ -4736,6 +6627,9 @@ const assist = definePlugin(config => {
4736
6627
  schema: {
4737
6628
  types: schemaTypes
4738
6629
  },
6630
+ i18n: {
6631
+ bundles: [{}]
6632
+ },
4739
6633
  document: {
4740
6634
  inspectors: (prev, context) => {
4741
6635
  const docSchema = context.schema.get(context.documentType);
@@ -4744,23 +6638,23 @@ const assist = definePlugin(config => {
4744
6638
  }
4745
6639
  return prev;
4746
6640
  },
4747
- unstable_fieldActions: (prev, _ref17) => {
6641
+ unstable_fieldActions: (prev, _ref24) => {
4748
6642
  let {
4749
6643
  documentType,
4750
6644
  schema
4751
- } = _ref17;
6645
+ } = _ref24;
4752
6646
  const docSchema = schema.get(documentType);
4753
6647
  if (docSchema && isSchemaAssistEnabled(docSchema)) {
4754
6648
  return [...prev, assistFieldActions];
4755
6649
  }
4756
6650
  return prev;
4757
6651
  },
4758
- unstable_languageFilter: (prev, _ref18) => {
6652
+ unstable_languageFilter: (prev, _ref25) => {
4759
6653
  let {
4760
6654
  documentId,
4761
6655
  schema,
4762
6656
  schemaType
4763
- } = _ref18;
6657
+ } = _ref25;
4764
6658
  const docSchema = schema.get(schemaType);
4765
6659
  if (docSchema && isObjectSchemaType(docSchema) && isSchemaAssistEnabled(docSchema)) {
4766
6660
  return [...prev, createAssistDocumentPresence(documentId, docSchema)];