MCPcopy Create free account
hub / github.com/dailydotdev/apps / createPlacementBuilder

Function createPlacementBuilder

packages/shared/src/lib/feedHighlightColSpan.ts:181–278  ·  view source on GitHub ↗
({
  numCards,
  isMobile,
  isList,
  isEnabled,
  minSpacing,
  startIndex,
  widenableTypes,
  firstSlotOffset = 0,
  minWideCardRow = 0,
  hasWideWidgets = false,
}: PlacementBuilderOptions)

Source from the content-addressed store, hash-verified

179 * awareness) share one implementation.
180 */
181export const createPlacementBuilder = ({
182 numCards,
183 isMobile,
184 isList,
185 isEnabled,
186 minSpacing,
187 startIndex,
188 widenableTypes,
189 firstSlotOffset = 0,
190 minWideCardRow = 0,
191 hasWideWidgets = false,
192}: PlacementBuilderOptions): PlacementBuilder => {
193 const layoutEnabled =
194 (isEnabled || hasWideWidgets) && !isMobile && !isList && numCards > 1;
195 const safeNumCards = Math.max(numCards, 1);
196 const safeFirstSlotOffset = Math.max(
197 0,
198 Math.min(firstSlotOffset, safeNumCards - 1),
199 );
200
201 let row = 0;
202 let col = safeFirstSlotOffset;
203 let lastLargeIndex = -Infinity;
204 let itemIdx = 0;
205
206 return {
207 next(
208 item,
209 { fullRowBefore = false, maxColSpan = Infinity } = {},
210 ): FeedItemPlacement {
211 if (!layoutEnabled) {
212 const shifted = itemIdx + safeFirstSlotOffset;
213 const placement: FeedItemPlacement = {
214 colSpan: 1,
215 row: Math.floor(shifted / safeNumCards),
216 column: shifted % safeNumCards,
217 };
218 itemIdx += 1;
219 return placement;
220 }
221
222 if (fullRowBefore) {
223 if (col !== 0) {
224 row += 1;
225 }
226 row += 1;
227 col = 0;
228 }
229
230 const requested = requestedColSpan(item, widenableTypes);
231 const actual = ((): number => {
232 if (requested === 1) {
233 return 1;
234 }
235 // The reader placed it, so the hero rules (where, how often) do not
236 // apply; it only has to fit the row and stop short of an ad's cell,
237 // and narrows to one card where it does not.
238 if (isWideFeedWidgetItem(item)) {

Callers 3

useFeedFunction · 0.90
computePlacementsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected