@@ -3,8 +3,8 @@ import { getNode, type FormKitNode, type FormKitProps } from "@formkit/core";
33import { undefine } from " @formkit/utils" ;
44import { IconClose , VButton } from " @halo-dev/components" ;
55import { utils } from " @halo-dev/ui-shared" ;
6- import { isNil } from " es-toolkit" ;
7- import { cloneDeepWith , get , toArray } from " es-toolkit/compat" ;
6+ import { isNil , isNotNil } from " es-toolkit" ;
7+ import { cloneDeepWith , get } from " es-toolkit/compat" ;
88import objectHash from " object-hash" ;
99import { onMounted , ref , toRaw , watch } from " vue" ;
1010import { VueDraggable } from " vue-draggable-plus" ;
@@ -95,7 +95,7 @@ onMounted(async () => {
9595
9696type FormattedItemLabel =
9797 | {
98- type: " text " | " image " | " color " ;
98+ type: Exclude < ArrayItemLabelType , " iconify " > ;
9999 value: string ;
100100 }
101101 | {
@@ -108,7 +108,7 @@ type FormattedItemLabel =
108108const parseItemLabel = async (
109109 itemLabel : ArrayItemLabel ,
110110 item : Record <string , unknown >
111- ): Promise <FormattedItemLabel | FormattedItemLabel [] | undefined > => {
111+ ): Promise <FormattedItemLabel [] | undefined > => {
112112 if (! itemLabel .label ) {
113113 return ;
114114 }
@@ -119,20 +119,24 @@ const parseItemLabel = async (
119119 const node = hiddenChildrenFormKit .value ?.at (path );
120120
121121 if (! node ) {
122- return {
123- type: itemLabel .type ,
124- value: String (value ?? " " ),
125- } as FormattedItemLabel ;
122+ return [
123+ {
124+ type: itemLabel .type ,
125+ value: String (value ?? " " ),
126+ } as FormattedItemLabel ,
127+ ];
126128 }
127129 const renderedValue = await renderItemLabelValue (node , value );
128130 const castRenderedValueArray = Array .isArray (renderedValue )
129131 ? renderedValue
130132 : [renderedValue ];
131133 if (castRenderedValueArray .length === 0 ) {
132- return {
133- type: itemLabel .type ,
134- value: String (value ?? " " ),
135- } as FormattedItemLabel ;
134+ return [
135+ {
136+ type: itemLabel .type ,
137+ value: String (value ?? " " ),
138+ } as FormattedItemLabel ,
139+ ];
136140 }
137141 return castRenderedValueArray .map ((renderedValue ) => {
138142 return {
@@ -155,12 +159,11 @@ const formatItemLabel = async (
155159 });
156160 const itemLabels = props .node .props .itemLabels ?? defaultItemLabel ;
157161 if (itemLabels .length > 0 ) {
158- const results = (
159- await Promise .all (itemLabels .map ((label ) => parseItemLabel (label , item )))
160- ).flatMap (toArray );
161- return results .filter (
162- (itemLabel ): itemLabel is FormattedItemLabel => !! itemLabel ?.value
163- );
162+ const results = await Promise .all <FormattedItemLabel [][]>(
163+ itemLabels .map ((label : ArrayItemLabel ) => parseItemLabel (label , item ))
164+ ).then ((results ) => results .flat ());
165+
166+ return results .filter (isNotNil );
164167 }
165168 return [];
166169};
0 commit comments