@sanity/assist 1.1.0 → 1.1.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.
package/dist/index.js CHANGED
@@ -1975,20 +1975,6 @@ function AiFieldPresence(props) {
1975
1975
  })
1976
1976
  });
1977
1977
  }
1978
- const FirstAssistedPathContext = react.createContext(void 0);
1979
- function FirstAssistedPathProvider(props) {
1980
- const {
1981
- members
1982
- } = props;
1983
- const firstAssistedPath = react.useMemo(() => {
1984
- const firstAssisted = members.find(member => member.kind === "field" && isAssistSupported(member.field.schemaType));
1985
- return (firstAssisted == null ? void 0 : firstAssisted.field.path) ? sanity.pathToString(firstAssisted == null ? void 0 : firstAssisted.field.path) : void 0;
1986
- }, [members]);
1987
- return /* @__PURE__ */jsxRuntime.jsx(FirstAssistedPathContext.Provider, {
1988
- value: firstAssistedPath,
1989
- children: props.children
1990
- });
1991
- }
1992
1978
  function AssistFeatureBadge() {
1993
1979
  return /* @__PURE__ */jsxRuntime.jsx(ui.Badge, {
1994
1980
  fontSize: 0,
@@ -1999,48 +1985,31 @@ function AssistFeatureBadge() {
1999
1985
  children: "Beta"
2000
1986
  });
2001
1987
  }
2002
- function FieldActionsOnboarding(props) {
2003
- const {
2004
- path,
2005
- children
2006
- } = props;
2007
- const firstAssistedPath = react.useContext(FirstAssistedPathContext);
2008
- const isFirstAssisted = react.useMemo(() => sanity.pathToString(path) === firstAssistedPath, [path, firstAssistedPath]);
2009
- if (!isFirstAssisted) {
2010
- return /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
2011
- children
2012
- });
2013
- }
2014
- return /* @__PURE__ */jsxRuntime.jsx(AssistOnboardingPopover, {
2015
- ...props
2016
- });
2017
- }
2018
1988
  function AssistOnboardingPopover(props) {
2019
1989
  const {
2020
- showOnboarding,
2021
- dismissOnboarding
2022
- } = useOnboardingFeature(fieldOnboardingKey);
2023
- if (!showOnboarding) {
2024
- return /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {
2025
- children: props.children
2026
- });
2027
- }
1990
+ dismiss
1991
+ } = props;
2028
1992
  return /* @__PURE__ */jsxRuntime.jsx(ui.Popover, {
2029
1993
  content: /* @__PURE__ */jsxRuntime.jsx(AssistIntroCard, {
2030
- path: props.path,
2031
- dismiss: dismissOnboarding
1994
+ dismiss
2032
1995
  }),
2033
1996
  open: true,
2034
1997
  portal: true,
2035
1998
  placeholder: "bottom",
2036
1999
  tone: "default",
2037
2000
  width: 0,
2038
- children: /* @__PURE__ */jsxRuntime.jsx("div", {
2001
+ children: /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
2002
+ radius: 2,
2003
+ shadow: 2,
2004
+ style: {
2005
+ padding: 2,
2006
+ lineHeight: 0
2007
+ },
2039
2008
  children: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
2040
2009
  disabled: true,
2041
2010
  fontSize: 1,
2042
2011
  icon: icons.SparklesIcon,
2043
- mode: "ghost",
2012
+ mode: "bleed",
2044
2013
  padding: 2
2045
2014
  })
2046
2015
  })
@@ -2096,6 +2065,20 @@ function AssistIntroCard(props) {
2096
2065
  })]
2097
2066
  });
2098
2067
  }
2068
+ const FirstAssistedPathContext = react.createContext(void 0);
2069
+ function FirstAssistedPathProvider(props) {
2070
+ const {
2071
+ members
2072
+ } = props;
2073
+ const firstAssistedPath = react.useMemo(() => {
2074
+ const firstAssisted = members.find(member => member.kind === "field" && isAssistSupported(member.field.schemaType));
2075
+ return (firstAssisted == null ? void 0 : firstAssisted.field.path) ? sanity.pathToString(firstAssisted == null ? void 0 : firstAssisted.field.path) : void 0;
2076
+ }, [members]);
2077
+ return /* @__PURE__ */jsxRuntime.jsx(FirstAssistedPathContext.Provider, {
2078
+ value: firstAssistedPath,
2079
+ children: props.children
2080
+ });
2081
+ }
2099
2082
  function AssistFieldWrapper(props) {
2100
2083
  const {
2101
2084
  schemaType
@@ -2113,8 +2096,17 @@ function AssistFieldWrapper(props) {
2113
2096
  return props.renderDefault(props);
2114
2097
  }
2115
2098
  function AssistField(props) {
2099
+ const {
2100
+ path
2101
+ } = props;
2116
2102
  const isPortableText = react.useMemo(() => !!(sanity.isArraySchemaType(props.schemaType) && isPortableTextArray(props.schemaType)), [props.schemaType]);
2117
2103
  const presence = useAssistPresence(props.path, isPortableText);
2104
+ const firstAssistedPath = react.useContext(FirstAssistedPathContext);
2105
+ const isFirstAssisted = react.useMemo(() => sanity.pathToString(path) === firstAssistedPath, [path, firstAssistedPath]);
2106
+ const {
2107
+ showOnboarding,
2108
+ dismissOnboarding
2109
+ } = useOnboardingFeature(fieldOnboardingKey);
2118
2110
  const actions = /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2119
2111
  gap: 2,
2120
2112
  align: "center",
@@ -2123,14 +2115,17 @@ function AssistField(props) {
2123
2115
  children: /* @__PURE__ */jsxRuntime.jsx(AiFieldPresence, {
2124
2116
  presence: pre
2125
2117
  }, pre.lastActiveAt)
2126
- }, pre.user.id)), /* @__PURE__ */jsxRuntime.jsx(FieldActionsOnboarding, {
2127
- ...props,
2128
- children: props.actions
2118
+ }, pre.user.id)), isFirstAssisted && showOnboarding && /* @__PURE__ */jsxRuntime.jsx(AssistOnboardingPopover, {
2119
+ dismiss: dismissOnboarding
2129
2120
  })]
2130
2121
  });
2131
2122
  return props.renderDefault({
2132
2123
  ...props,
2133
- actions
2124
+ // When showing the onboarding, prevent default field actions from being rendered
2125
+ actions: isFirstAssisted && showOnboarding ? [] : props.actions,
2126
+ // Render presence (and possibly onboarding) in the internal slot (between presence and the field actions)
2127
+ // eslint-disable-next-line camelcase
2128
+ __internal_slot: actions
2134
2129
  });
2135
2130
  }
2136
2131
  const ConnectorsStoreContext = react.createContext(null);
@@ -4355,18 +4350,18 @@ const assistFieldActions = {
4355
4350
  }, [fieldAssist == null ? void 0 : fieldAssist.instructions]);
4356
4351
  const instructions = react.useMemo(() => [...privateInstructions, ...sharedInstructions], [privateInstructions, sharedInstructions]);
4357
4352
  const runInstructionsGroup = react.useMemo(() => {
4358
- return (instructions == null ? void 0 : instructions.length) ? node({
4353
+ return (instructions == null ? void 0 : instructions.length) || imageCaptionAction ? node({
4359
4354
  type: "group",
4360
4355
  icon: () => null,
4361
4356
  title: "Run instructions",
4362
- children: [...instructions.map(instruction => instructionItem({
4357
+ children: [...(instructions == null ? void 0 : instructions.map(instruction => instructionItem({
4363
4358
  instruction,
4364
4359
  isPrivate: Boolean(instruction.userId && instruction.userId === (currentUser == null ? void 0 : currentUser.id)),
4365
4360
  onInstructionAction,
4366
4361
  hidden: isHidden,
4367
4362
  documentIsNew: !!documentIsNew,
4368
4363
  assistSupported
4369
- })), imageCaptionAction].filter(Boolean),
4364
+ }))), imageCaptionAction].filter(Boolean),
4370
4365
  expanded: true
4371
4366
  }) : void 0;
4372
4367
  }, [instructions, currentUser == null ? void 0 : currentUser.id, onInstructionAction, isHidden, documentIsNew, assistSupported, imageCaptionAction]);
@@ -4382,23 +4377,13 @@ const assistFieldActions = {
4382
4377
  type: "group",
4383
4378
  icon: icons.SparklesIcon,
4384
4379
  title: pluginTitleShort,
4385
- children: [runInstructionsGroup,
4386
- /* documentIsNew && {
4387
- type: 'action',
4388
- disabled: true,
4389
- title: `Document is new. Make an edit to enable `,
4390
- icon: WarningOutlineIcon,
4391
- tone: 'caution',
4392
- status: 'warning',
4393
- onAction: () => {},
4394
- },*/
4395
- manageInstructionsItem].filter(c => !!c),
4380
+ children: [runInstructionsGroup, assistSupported && manageInstructionsItem].filter(c => !!c),
4396
4381
  expanded: false,
4397
4382
  renderAsButton: true,
4398
- hidden: !assistSupported
4383
+ hidden: !assistSupported && !imageCaptionAction
4399
4384
  }), [
4400
4385
  //documentIsNew,
4401
- runInstructionsGroup, manageInstructionsItem, assistSupported]);
4386
+ runInstructionsGroup, manageInstructionsItem, assistSupported, imageCaptionAction]);
4402
4387
  const emptyAction = react.useMemo(() => node({
4403
4388
  type: "action",
4404
4389
  hidden: !assistSupported,