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

Function processItem

packages/core/lib/data/walk-app-state.ts:96–158  ·  view source on GitHub ↗
(
    item: ComponentData,
    path: string[],
    index: number
  )

Source from the content-addressed store, hash-verified

94 };
95
96 const processItem = (
97 item: ComponentData,
98 path: string[],
99 index: number
100 ): ComponentData => {
101 const mappedItem = mapNodeOrSkip(item, path, index);
102
103 // Only modify the item if the user has returned it, enabling us to prevent unnecessary mapping and creating new references, which results in re-renders
104 if (!mappedItem) return item;
105
106 const id = mappedItem.props.id;
107
108 const newProps = {
109 ...mapFields(
110 mappedItem,
111 {
112 slot: ({ value, parentId, propPath }) => {
113 const content = value as Content;
114 const zoneCompound = `${parentId}:${propPath}`;
115
116 const [_, newContent] = processContent(
117 path,
118 zoneCompound,
119 content,
120 "slot",
121 parentId
122 );
123
124 return newContent;
125 },
126 },
127 config
128 ).props,
129 id,
130 };
131
132 processRelatedZones(item, id, path);
133
134 const newItem = { ...mappedItem, props: newProps };
135
136 const thisZoneCompound = path[path.length - 1];
137 const [parentId, zone] = thisZoneCompound
138 ? thisZoneCompound.split(":")
139 : [null, ""];
140
141 newNodeIndex[id] = {
142 data: newItem,
143 flatData: flattenNode(newItem, config) as ComponentData,
144 path,
145 parentId,
146 zone,
147 };
148
149 // For now, we strip type and id from root. This may change in future.
150 const finalData: any = { ...newItem, props: { ...newItem.props } };
151
152 if (newProps.id === "root") {
153 delete finalData["type"];

Callers 2

processContentFunction · 0.85
walkAppStateFunction · 0.85

Calls 4

mapFieldsFunction · 0.90
flattenNodeFunction · 0.90
processRelatedZonesFunction · 0.85
processContentFunction · 0.70

Tested by

no test coverage detected