(
item: ComponentData,
path: string[],
index: number
)
| 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"]; |
no test coverage detected