@sanity/assist 4.3.1 → 4.3.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
@@ -204,6 +204,9 @@ function getPathKey(path) {
204
204
  function getInstructionTitle(instruction2) {
205
205
  return instruction2?.title ?? "Untitled";
206
206
  }
207
+ function isDefined(t) {
208
+ return t != null;
209
+ }
207
210
  function isPortableTextArray(type) {
208
211
  return type.of.find((t) => isType(t, "block"));
209
212
  }
@@ -2863,12 +2866,12 @@ function useCustomFieldActions(props) {
2863
2866
  path: props.path
2864
2867
  });
2865
2868
  return react.useMemo(() => {
2866
- const title = fieldActions?.title, customActions = configActions?.map((node) => createSafeNode({
2869
+ const title = fieldActions?.title, customActions = configActions?.filter(isDefined).map((node) => createSafeNode({
2867
2870
  node,
2868
2871
  pushToast,
2869
2872
  addSyntheticTask,
2870
2873
  removeSyntheticTask
2871
- })), onlyGroups = customActions?.length && customActions?.every((node) => node.type === "group");
2874
+ })).filter(isDefined), onlyGroups = customActions?.length && customActions?.every((node) => node.type === "group");
2872
2875
  return (customActions?.length ? onlyGroups ? customActions : [
2873
2876
  {
2874
2877
  type: "group",
@@ -2885,12 +2888,13 @@ function createSafeNode(args) {
2885
2888
  case "action":
2886
2889
  return createSafeAction({ ...args, action: node });
2887
2890
  case "group":
2888
- return {
2891
+ const children = node.children?.filter(isDefined).map((child) => createSafeNode({ ...args, node: child })).filter(isDefined);
2892
+ return children?.length ? {
2889
2893
  ...node,
2890
2894
  renderAsButton: !1,
2891
2895
  expanded: !0,
2892
- children: node.children?.map((child) => createSafeNode({ ...args, node: child }))
2893
- };
2896
+ children
2897
+ } : void 0;
2894
2898
  case "divider":
2895
2899
  default:
2896
2900
  return node;