MCPcopy
hub / github.com/puckeditor/puck / mapFields

Function mapFields

packages/core/lib/data/map-fields.ts:208–243  ·  view source on GitHub ↗
(
  item: any,
  mappers: Mappers,
  config: Config,
  recurseSlots: boolean = false,
  shouldDefaultSlots: boolean = true
)

Source from the content-addressed store, hash-verified

206): Promise<T>;
207
208export function mapFields(
209 item: any,
210 mappers: Mappers,
211 config: Config,
212 recurseSlots: boolean = false,
213 shouldDefaultSlots: boolean = true
214): any {
215 const itemType = "type" in item ? item.type : "root";
216
217 const componentConfig =
218 itemType === "root" ? config.root : config.components?.[itemType];
219
220 const newProps = walkObject({
221 value: shouldDefaultSlots
222 ? defaultSlots(item.props ?? {}, componentConfig?.fields ?? {})
223 : item.props,
224 fields: componentConfig?.fields ?? {},
225 mappers,
226 id: item.props ? item.props.id ?? "root" : "root",
227 getPropPath: (k) => k,
228 config,
229 recurseSlots,
230 });
231
232 if (isPromise(newProps)) {
233 return newProps.then((resolvedProps) => ({
234 ...item,
235 props: resolvedProps,
236 }));
237 }
238
239 return {
240 ...item,
241 props: newProps,
242 };
243}

Callers 8

resolveNodeFunction · 0.90
resolveComponentDataFunction · 0.90
useFieldTransformsFunction · 0.90
processItemFunction · 0.90
stripSlotsFunction · 0.90
walkItemFunction · 0.90
walkFieldFunction · 0.85

Calls 3

defaultSlotsFunction · 0.90
walkObjectFunction · 0.85
isPromiseFunction · 0.85

Tested by

no test coverage detected