@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.mjs CHANGED
@@ -211,6 +211,9 @@ function getPathKey(path) {
211
211
  function getInstructionTitle(instruction2) {
212
212
  return instruction2?.title ?? "Untitled";
213
213
  }
214
+ function isDefined(t) {
215
+ return t != null;
216
+ }
214
217
  function isPortableTextArray(type) {
215
218
  return type.of.find((t) => isType(t, "block"));
216
219
  }
@@ -2870,12 +2873,12 @@ function useCustomFieldActions(props) {
2870
2873
  path: props.path
2871
2874
  });
2872
2875
  return useMemo(() => {
2873
- const title = fieldActions?.title, customActions = configActions?.map((node) => createSafeNode({
2876
+ const title = fieldActions?.title, customActions = configActions?.filter(isDefined).map((node) => createSafeNode({
2874
2877
  node,
2875
2878
  pushToast,
2876
2879
  addSyntheticTask,
2877
2880
  removeSyntheticTask
2878
- })), onlyGroups = customActions?.length && customActions?.every((node) => node.type === "group");
2881
+ })).filter(isDefined), onlyGroups = customActions?.length && customActions?.every((node) => node.type === "group");
2879
2882
  return (customActions?.length ? onlyGroups ? customActions : [
2880
2883
  {
2881
2884
  type: "group",
@@ -2892,12 +2895,13 @@ function createSafeNode(args) {
2892
2895
  case "action":
2893
2896
  return createSafeAction({ ...args, action: node });
2894
2897
  case "group":
2895
- return {
2898
+ const children = node.children?.filter(isDefined).map((child) => createSafeNode({ ...args, node: child })).filter(isDefined);
2899
+ return children?.length ? {
2896
2900
  ...node,
2897
2901
  renderAsButton: !1,
2898
2902
  expanded: !0,
2899
- children: node.children?.map((child) => createSafeNode({ ...args, node: child }))
2900
- };
2903
+ children
2904
+ } : void 0;
2901
2905
  case "divider":
2902
2906
  default:
2903
2907
  return node;