@cntrl-site/components 1.0.118-alpha.8 → 1.0.118-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sources.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { W as e, b as t, T as i, h as o, g as r, S as a, P as s, O as l, i as c, a as d, M as u, L as g, e as m, f as p, H as h, j as f, G as v, F as P, d as x, c as b, C as y, k as S, B as C } from "./ChroniclesComponent-B-93AhZK.mjs";
1
+ import { W as e, b as t, T as i, h as o, g as r, S as a, P as s, O as l, i as c, a as d, M as u, L as g, e as m, f as p, H as h, j as f, G as v, F as P, d as x, c as b, C as y, k as S, B as C } from "./ChroniclesComponent-Bf8jxaas.mjs";
2
2
  const w = `import { Fragment, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type MouseEvent, type PointerEvent, type ReactNode } from 'react';
3
3
  import { CommonComponentProps } from '../props';
4
4
  import { buildColorVars, scalingValue, useScopedStyles } from '../utils';
@@ -5824,9 +5824,13 @@ function getCSS(P: string): string {
5824
5824
  flex: 1 1 0%;
5825
5825
  min-height: 0;
5826
5826
  }
5827
- .\${P}-custom-layout.\${P}-text-outside .\${P}-item-image-link {
5827
+ .\${P}-custom-layout.\${P}-text-outside .\${P}-item-image-link,
5828
+ .\${P}-custom-layout.\${P}-auto-height .\${P}-item-image-link {
5828
5829
  flex: none;
5829
5830
  }
5831
+ .\${P}-auto-height .\${P}-item-image-wrapper-fit-slider > .\${P}-item-image-wrapper-sizer :is(img, video) {
5832
+ width: 100%;
5833
+ }
5830
5834
  .\${P}-item-text-link {
5831
5835
  display: flex;
5832
5836
  flex-direction: column;
@@ -7563,6 +7567,47 @@ function getCustomGridRows(layout: CustomGridLayout, entriesCount: number, entry
7563
7567
  return { tracks, gridRows };
7564
7568
  }
7565
7569
 
7570
+ function getGridMediaAspect(media: GridMedia): number | undefined {
7571
+ if (isEmbedMedia(media)) return getEmbedAspect(media);
7572
+ return media.width && media.height && media.width > 0 && media.height > 0 ? media.width / media.height : undefined;
7573
+ }
7574
+
7575
+ /**
7576
+ * Where each entry stands, given the height it takes; the CMS grid builder places its blocks the same way.
7577
+ * A block keeps its drawn distance to the blocks above it in its group; a block with none above it starts at
7578
+ * its drawn top in the group, or, with masonry on, the vertical gap below whatever earlier group reaches
7579
+ * lowest in its columns.
7580
+ */
7581
+ function placeCustomGridEntries(layout: CustomGridLayout, slots: CustomGridSlot[], heights: number[]) {
7582
+ const groupSize = layout.blocks.length;
7583
+ const verticalGap = getCustomGridVerticalGap(layout);
7584
+ const isMasonry = layout.masonry === 'on';
7585
+ const tops: number[] = [];
7586
+ const placed: { column: number; span: number; bottom: number; group: number }[] = [];
7587
+ const getBottom = (items: typeof placed) => items.reduce((bottom, item) => Math.max(bottom, item.bottom), 0);
7588
+ let groupStart = 0;
7589
+ for (let start = 0; start < slots.length; start += groupSize) {
7590
+ const group = start / groupSize;
7591
+ const entries = Array.from({ length: Math.min(groupSize, slots.length - start) }, (_, index) => start + index)
7592
+ .sort((a, b) => slots[a].top - slots[b].top || a - b);
7593
+ for (const entry of entries) {
7594
+ const slot = slots[entry];
7595
+ const sharesColumns = (other: { column: number; span: number }) => other.column < slot.column + slot.span
7596
+ && slot.column < other.column + other.span;
7597
+ const above = entries.filter(other => other !== entry && tops[other] !== undefined && sharesColumns(slots[other])
7598
+ && slots[other].top + slots[other].height <= slot.top + EDGE_TOLERANCE);
7599
+ const earlier = isMasonry ? placed.filter(item => item.group < group && sharesColumns(item)) : [];
7600
+ const candidates = above.map(other => tops[other] + heights[other] + slot.top - (slots[other].top + slots[other].height));
7601
+ if (earlier.length > 0) candidates.push(getBottom(earlier) + verticalGap);
7602
+ if (candidates.length === 0) candidates.push(groupStart + slot.top);
7603
+ tops[entry] = Math.max(...candidates);
7604
+ placed.push({ column: slot.column, span: slot.span, bottom: tops[entry] + heights[entry], group });
7605
+ }
7606
+ groupStart = getBottom(placed) + verticalGap;
7607
+ }
7608
+ return { tops, bottom: getBottom(placed) };
7609
+ }
7610
+
7566
7611
  export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, metadata, activeEvent, layoutId, portalId }: GridProps) {
7567
7612
  const { prefix: P } = useScopedStyles();
7568
7613
  const {
@@ -7713,6 +7758,9 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7713
7758
  const customLayout = customGrid && Array.isArray(customGrid.blocks) && customGrid.blocks.length > 0 ? customGrid : undefined;
7714
7759
  const resEntriesCount = customLayout || entriesCount === 0 ? Infinity : entriesCount;
7715
7760
  const isTextOutside = !!customLayout && textGrowth === 'outside';
7761
+ const isAutoHeight = customLayout?.cellHeight === 'auto';
7762
+ // entries stand where placeCustomGridEntries puts them rather than on grid rows
7763
+ const isPlacedLayout = isAutoHeight || customLayout?.masonry === 'on';
7716
7764
  const itemInnerRefs = useRef<(HTMLDivElement | null)[]>([]);
7717
7765
  const [customEntryHeights, setCustomEntryHeights] = useState<number[]>([]);
7718
7766
 
@@ -7745,7 +7793,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7745
7793
 
7746
7794
  const columnsCount = gridLayout?.columnsCount ?? 1;
7747
7795
  const entryWidthScaled = scalingValue(size ?? 0, isEditor);
7748
- const isFitSlider = !customLayout && !isCover && slider !== 'off';
7796
+ const isFitSlider = slider !== 'off' && (customLayout ? isAutoHeight : !isCover);
7749
7797
 
7750
7798
  const itemsInLastRow = cropContent.length % columnsCount || columnsCount;
7751
7799
  const isPartialLastRow = !customLayout && itemsInLastRow < columnsCount && cropContent.length > 0;
@@ -7756,9 +7804,21 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7756
7804
 
7757
7805
  const imageBorderRadius = imageCorners ? scalingValue(imageCorners, isEditor) : undefined;
7758
7806
 
7759
- const getImageWrapperStyle = (entryWidth: string, slot?: CustomGridSlot): React.CSSProperties => ({
7807
+ const getImageWrapperStyle = (
7808
+ entryWidth: string,
7809
+ slot?: CustomGridSlot,
7810
+ media?: { aspect?: number; isEmpty: boolean },
7811
+ ): React.CSSProperties => ({
7760
7812
  width: entryWidth,
7761
- ...(slot
7813
+ ...(slot && isAutoHeight
7814
+ ? {
7815
+ // an entry with no media keeps the drawn height, so it can still be seen and filled
7816
+ height: media?.isEmpty ? scalingValue(slot.height, isEditor) : 'auto',
7817
+ flexShrink: 0,
7818
+ overflow: 'hidden',
7819
+ ...(media?.aspect && !isFitSlider ? { aspectRatio: \`\${media.aspect}\` } : {}),
7820
+ }
7821
+ : slot
7762
7822
  ? isTextOutside
7763
7823
  ? { height: scalingValue(slot.height, isEditor), flexShrink: 0, overflow: 'hidden' }
7764
7824
  : { flex: '1 1 0%', minHeight: 0, overflow: 'hidden' }
@@ -7775,7 +7835,16 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7775
7835
  const imageRadiusStyle = imageBorderRadius
7776
7836
  ? { borderRadius: imageBorderRadius, [MEDIA_RADIUS_VAR]: imageBorderRadius } as React.CSSProperties
7777
7837
  : {};
7778
- const imageStyle: React.CSSProperties = isCover
7838
+ const imageStyle: React.CSSProperties = isAutoHeight
7839
+ ? {
7840
+ objectFit: isFitSlider && !isCover ? 'contain' : 'cover',
7841
+ pointerEvents: 'auto',
7842
+ width: '100%',
7843
+ height: '100%',
7844
+ maxWidth: '100%',
7845
+ ...imageRadiusStyle,
7846
+ }
7847
+ : isCover
7779
7848
  ? {
7780
7849
  objectFit: 'cover',
7781
7850
  pointerEvents: 'auto',
@@ -7794,7 +7863,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7794
7863
  ...imageRadiusStyle,
7795
7864
  };
7796
7865
 
7797
- const shouldMeasureEntries = (customLayout?.beat ?? 0) > 0;
7866
+ const shouldMeasureEntries = (customLayout?.beat ?? 0) > 0 || isPlacedLayout;
7798
7867
  const customGridWidth = customLayout ? getCustomGridSpanWidth(customLayout, customLayout.columnsCount) : 0;
7799
7868
  useLayoutEffect(() => {
7800
7869
  if (!shouldMeasureEntries) {
@@ -7836,6 +7905,26 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7836
7905
  () => (customLayout ? cropContent.map((_, index) => getCustomGridSlot(customLayout, index)) : undefined),
7837
7906
  [customLayout, cropContent.length],
7838
7907
  );
7908
+ // the aspect a single media keeps when the cell takes its height
7909
+ const entryMediaAspects = useMemo(
7910
+ () => entriesMedia.map(({ displayItems }) => (
7911
+ isAutoHeight && displayItems.length > 0 ? getGridMediaAspect(displayItems[0].displayMedia) : undefined
7912
+ )),
7913
+ [entriesMedia, isAutoHeight],
7914
+ );
7915
+ const customPlacement = useMemo(() => {
7916
+ if (!customLayout || !customSlots || !isPlacedLayout) return undefined;
7917
+ const beat = customLayout.beat ?? 0;
7918
+ const heights = customSlots.map((slot, index) => {
7919
+ // until the entries are measured, a media that tells its size gives the height it will take
7920
+ const aspects = entriesMedia[index].displayItems.map(({ displayMedia }) => getGridMediaAspect(displayMedia));
7921
+ const known = aspects.filter((aspect): aspect is number => aspect !== undefined);
7922
+ const estimate = isAutoHeight && known.length > 0 ? Math.max(...known.map(aspect => slot.width / aspect)) : slot.height;
7923
+ const height = measuredEntryHeights?.[index] ?? estimate;
7924
+ return beat > 0 ? Math.ceil(height / beat - 1e-3) * beat : height;
7925
+ });
7926
+ return placeCustomGridEntries(customLayout, customSlots, heights);
7927
+ }, [customLayout, customSlots, isPlacedLayout, isAutoHeight, entriesMedia, measuredEntryHeights]);
7839
7928
  const wrapperLayoutStyle: React.CSSProperties = customLayout
7840
7929
  ? {
7841
7930
  gridTemplateColumns: \`repeat(\${customLayout.columnsCount}, \${scalingValue(customLayout.columnWidth, isEditor)})\`,
@@ -7843,6 +7932,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7843
7932
  rowGap: 0,
7844
7933
  columnGap: scalingValue(customLayout.gutterWidth, isEditor),
7845
7934
  width: scalingValue(getCustomGridSpanWidth(customLayout, customLayout.columnsCount), isEditor),
7935
+ ...(customPlacement ? { position: 'relative', height: scalingValue(customPlacement.bottom, isEditor) } : {}),
7846
7936
  }
7847
7937
  : {
7848
7938
  gridTemplateColumns: \`repeat(\${columnsCount}, \${entryWidthScaled})\`,
@@ -7904,7 +7994,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7904
7994
  <div style={colorVars}>
7905
7995
  <div
7906
7996
  ref={containerRef}
7907
- className={\`\${P}-wrapper \${P}-type-\${type}\${shouldAlignEntries ? \` \${P}-align-entries\` : ''}\${customLayout ? \` \${P}-custom-layout\` : ''}\${isTextOutside ? \` \${P}-text-outside\` : ''} \${P}-image-align-\${align} \${wrapperStateClasses}\`.trim()}
7997
+ className={\`\${P}-wrapper \${P}-type-\${type}\${shouldAlignEntries ? \` \${P}-align-entries\` : ''}\${customLayout ? \` \${P}-custom-layout\` : ''}\${isTextOutside ? \` \${P}-text-outside\` : ''}\${isAutoHeight ? \` \${P}-auto-height\` : ''} \${P}-image-align-\${customLayout ? 'top' : align} \${wrapperStateClasses}\`.trim()}
7908
7998
  style={wrapperLayoutStyle}>
7909
7999
  {cropContent.map((item: any, index: number) => {
7910
8000
  const hasTitle = hasText(item.title);
@@ -7920,8 +8010,24 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7920
8010
  const itemWidthScaled = scalingValue(itemSize, isEditor);
7921
8011
  const textBoxWidthStyle = \`calc(\${itemWidthScaled} * (\${textBoxWidth} / 100))\`;
7922
8012
  const controlWidthStyle = scalingValue(itemSize * textBoxWidth / 100, isEditor);
7923
- const imageWrapperStyle = getImageWrapperStyle(itemWidthScaled, customSlot);
7924
- const itemStyle: React.CSSProperties | undefined = customSlot
8013
+ const { displayItems, lightboxItemsForEntry, lightboxIndexes } = entriesMedia[index];
8014
+ const mediaAspect = slider === 'off' ? entryMediaAspects[index] : undefined;
8015
+ const imageWrapperStyle = getImageWrapperStyle(
8016
+ itemWidthScaled,
8017
+ customSlot,
8018
+ { aspect: mediaAspect, isEmpty: displayItems.length === 0 },
8019
+ );
8020
+ const entryImageStyle = isAutoHeight && slider === 'off' && !mediaAspect
8021
+ ? { ...imageStyle, height: 'auto' }
8022
+ : imageStyle;
8023
+ const itemStyle: React.CSSProperties | undefined = customSlot && customLayout && customPlacement
8024
+ ? {
8025
+ position: 'absolute',
8026
+ left: scalingValue(customSlot.column * (customLayout.columnWidth + customLayout.gutterWidth), isEditor),
8027
+ top: scalingValue(customPlacement.tops[index], isEditor),
8028
+ width: itemWidthScaled,
8029
+ }
8030
+ : customSlot
7925
8031
  ? {
7926
8032
  gridColumn: customSlot.gridColumn,
7927
8033
  gridRow: customRows?.gridRows[index],
@@ -8031,8 +8137,6 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
8031
8137
  </LinkWrapper>
8032
8138
  );
8033
8139
 
8034
- const { displayItems, lightboxItemsForEntry, lightboxIndexes } = entriesMedia[index];
8035
-
8036
8140
  const imageContent = (
8037
8141
  <GridItemMediaWrapper className={imageWrapperClassName} style={imageWrapperStyle}>
8038
8142
  {displayItems.length === 0
@@ -8046,7 +8150,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
8046
8150
  <GridMediaItem
8047
8151
  media={displayMedia}
8048
8152
  className={\`\${P}-item-\${isVideoMedia(displayMedia) ? 'video' : 'image'}\`.trim()}
8049
- style={imageStyle}
8153
+ style={entryImageStyle}
8050
8154
  hasLightbox={lightbox === 'on'}
8051
8155
  onMediaClick={canOpenLightboxMedia && lightboxIndex >= 0
8052
8156
  ? () => openLightbox(lightboxItemsForEntry, lightboxIndex)
@@ -8153,7 +8257,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
8153
8257
  width: (textBoxWidth ?? 0) > 100
8154
8258
  ? \`calc(\${itemWidthScaled} * (\${textBoxWidth} / 100))\`
8155
8259
  : itemWidthScaled,
8156
- ...(customSlot && !isTextOutside ? { height: scalingValue(customSlot.height, isEditor) } : {}),
8260
+ ...(customSlot && !isTextOutside && !isAutoHeight ? { height: scalingValue(customSlot.height, isEditor) } : {}),
8157
8261
  ...(gridColumn && shouldAlignEntries ? { gridColumn } : {}),
8158
8262
  }}
8159
8263
  >
@@ -8252,6 +8356,8 @@ type CustomGridLayout = {
8252
8356
  beat?: number;
8253
8357
  repeatHeight?: number;
8254
8358
  blocks: CustomGridBlock[];
8359
+ cellHeight?: 'manual' | 'auto';
8360
+ masonry?: 'off' | 'on';
8255
8361
  };
8256
8362
 
8257
8363
  type GridSettings = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cntrl-site/components",
3
- "version": "1.0.118-alpha.8",
3
+ "version": "1.0.118-alpha.9",
4
4
  "description": "Custom components for control editor and public websites.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",