@cntrl-site/components 1.0.118-alpha.2 → 1.0.118

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.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./ChroniclesComponent--pzhQXVD.js"),t=`import { Fragment, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type MouseEvent, type PointerEvent, type ReactNode } from 'react';
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./ChroniclesComponent-DkG1aICD.js"),e=`import { Fragment, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type MouseEvent, type PointerEvent, type ReactNode } from 'react';
2
2
  import { CommonComponentProps } from '../props';
3
3
  import { buildColorVars, scalingValue, useScopedStyles } from '../utils';
4
4
  import { useLightboxScrollLock } from '../utils/useLightboxScrollLock';
@@ -27,11 +27,12 @@ type BurgerShowInValue = string | Record<string, string>;
27
27
 
28
28
  type BurgerLink = {
29
29
  link?: {
30
- type?: 'url' | 'page' | 'anchor';
30
+ type?: 'url' | 'page' | 'anchor' | 'file';
31
31
  value?: string;
32
32
  target?: string;
33
33
  anchor?: string;
34
34
  url?: string;
35
+ download?: string;
35
36
  };
36
37
  mode?: 'page' | 'url';
37
38
  page?: string;
@@ -256,10 +257,11 @@ function isBlankTarget(target?: string): boolean {
256
257
  }
257
258
 
258
259
  function getBurgerDest(item: BurgerLink): {
259
- type: 'url' | 'page' | 'anchor';
260
+ type: 'url' | 'page' | 'anchor' | 'file';
260
261
  value: string;
261
262
  target?: '_blank';
262
263
  anchor?: string;
264
+ download?: string;
263
265
  } {
264
266
  const dest = item.link;
265
267
  if (dest && typeof dest === 'object') {
@@ -273,8 +275,12 @@ function getBurgerDest(item: BurgerLink): {
273
275
  if (dest.type === 'page') {
274
276
  return { type: 'page', value: dest.value ?? '', target, anchor: dest.anchor };
275
277
  }
278
+ if (dest.type === 'file') {
279
+ return { type: 'file', value: dest.value ?? '' };
280
+ }
281
+ // a published file link comes as its file's url, with the name to download it under
276
282
  if (typeof dest.url === 'string') {
277
- return { type: 'url', value: dest.url, target };
283
+ return { type: 'url', value: dest.url, target, download: typeof dest.download === 'string' ? dest.download : undefined };
278
284
  }
279
285
  }
280
286
  const target = isBlankTarget(item.openIn) ? '_blank' : undefined;
@@ -295,12 +301,17 @@ function resolveBurgerLink(item: BurgerLink, pages?: BurgerPageRef[]): {
295
301
  label: string;
296
302
  href: string;
297
303
  target?: '_blank';
304
+ download?: string;
298
305
  } {
299
306
  const label = item.label || 'Link';
300
307
  const dest = getBurgerDest(item);
301
308
 
302
309
  if (dest.type === 'url') {
303
- return { label, href: dest.value, target: dest.target };
310
+ return { label, href: dest.value, target: dest.target, download: dest.download };
311
+ }
312
+ if (dest.type === 'file') {
313
+ // only the editor sees a file by its id, and downloads it through onLinkNavigate, right on the click
314
+ return { label, href: dest.value ? '#' : '', target: '_blank' };
304
315
  }
305
316
  if (dest.type === 'anchor') {
306
317
  const anchor = dest.value.replace(/^#/, '');
@@ -912,10 +923,11 @@ function renderTextPaddingControls(
912
923
  type ColorKeys = 'iconColor' | 'closeButtonColor' | 'linkColor' | 'openLinkColor' | 'compactIconColor' | 'compactLinkColor' | 'compactLogoColor' | 'compactBackgroundColor' | 'openLogoColor' | 'menuBackgroundColor' | 'overlayColor' | 'backgroundColor' | 'logoColor';
913
924
 
914
925
  export type BurgerLinkNavigateEvent = {
915
- mode: 'page' | 'url';
926
+ mode: 'page' | 'url' | 'file';
916
927
  href: string;
917
928
  page?: string;
918
929
  url?: string;
930
+ file?: string;
919
931
  anchor?: string;
920
932
  target?: '_blank';
921
933
  };
@@ -1767,6 +1779,28 @@ function findAnchorTarget(hash: string): HTMLElement | null {
1767
1779
  return target instanceof HTMLElement ? target : null;
1768
1780
  }
1769
1781
 
1782
+ // the file is on the cdn, another origin, where the download attribute alone opens it instead
1783
+ function downloadFile(url: string, name: string) {
1784
+ fetch(url)
1785
+ .then((response) => {
1786
+ if (!response.ok) throw new Error(\`Could not download \${url}: \${response.status}\`);
1787
+ return response.blob();
1788
+ })
1789
+ .then((blob) => {
1790
+ const objectUrl = URL.createObjectURL(blob);
1791
+ const link = document.createElement('a');
1792
+ link.href = objectUrl;
1793
+ link.download = name || decodeURIComponent(url.split('?')[0].split('/').pop() ?? '');
1794
+ document.body.appendChild(link);
1795
+ link.click();
1796
+ link.remove();
1797
+ window.setTimeout(() => URL.revokeObjectURL(objectUrl), 0);
1798
+ })
1799
+ .catch(() => {
1800
+ window.location.assign(url);
1801
+ });
1802
+ }
1803
+
1770
1804
  function scrollToAnchor(hash: string): boolean {
1771
1805
  const target = findAnchorTarget(hash);
1772
1806
  if (!target) return false;
@@ -1800,10 +1834,11 @@ function handleLinkClick(
1800
1834
  const resolved = resolveBurgerLink(item, pages);
1801
1835
  const dest = getBurgerDest(item);
1802
1836
  const navigateEvent: BurgerLinkNavigateEvent = {
1803
- mode: dest.type === 'url' ? 'url' : 'page',
1837
+ mode: dest.type === 'url' || dest.type === 'file' ? dest.type : 'page',
1804
1838
  href: resolved.href || href,
1805
1839
  page: dest.type === 'page' ? dest.value : undefined,
1806
1840
  url: dest.type === 'url' ? dest.value : undefined,
1841
+ file: dest.type === 'file' ? dest.value : undefined,
1807
1842
  anchor: dest.type === 'anchor'
1808
1843
  ? dest.value.replace(/^#/, '')
1809
1844
  : (dest.anchor ?? '').replace(/^#/, ''),
@@ -1825,6 +1860,14 @@ function handleLinkClick(
1825
1860
  return;
1826
1861
  }
1827
1862
 
1863
+ const download = item ? getBurgerDest(item).download : undefined;
1864
+ if (download !== undefined && href && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
1865
+ event.preventDefault();
1866
+ downloadFile(href, download);
1867
+ onClose();
1868
+ return;
1869
+ }
1870
+
1828
1871
  if (!opensInNewTab && hash && isSameDocumentHref(href) && findAnchorTarget(hash)) {
1829
1872
  event.preventDefault();
1830
1873
  runAfterClose(() => scrollToAnchor(hash));
@@ -2430,12 +2473,13 @@ export function Burger({
2430
2473
  const showOpenNavControls = showControls && isOpen;
2431
2474
 
2432
2475
  const renderOpenNavItems = (linkClassName: string) => items.filter((item) => isVisibleInOpenNav(item, layoutId)).map((item, index) => {
2433
- const { label, href, target } = resolveBurgerLink(item, pages);
2476
+ const { label, href, target, download } = resolveBurgerLink(item, pages);
2434
2477
  const linkNode = href ? (
2435
2478
  <a
2436
2479
  href={href}
2437
2480
  target={target}
2438
2481
  rel={target === '_blank' ? 'noopener noreferrer' : undefined}
2482
+ download={download}
2439
2483
  className={\`\${linkClassName} \${P}-has-href\`}
2440
2484
  onClick={(event) => onNavLinkClick(event, item)}
2441
2485
  >
@@ -2547,7 +2591,7 @@ export function Burger({
2547
2591
  };
2548
2592
 
2549
2593
  const renderNavLink = (item: BurgerLink, index: number) => {
2550
- const { label, href, target } = resolveBurgerLink(item, pages);
2594
+ const { label, href, target, download } = resolveBurgerLink(item, pages);
2551
2595
  const textContent = (
2552
2596
  <span className={navLinkTextClassName} style={navLinkTextStyle}>
2553
2597
  {renderMultilineText(label)}
@@ -2566,6 +2610,7 @@ export function Burger({
2566
2610
  href={href}
2567
2611
  target={target}
2568
2612
  rel={target === '_blank' ? 'noopener noreferrer' : undefined}
2613
+ download={download}
2569
2614
  className={\`\${P}-nav-link \${P}-has-href\`}
2570
2615
  onClick={(event) => onNavLinkClick(event, item)}
2571
2616
  >
@@ -2683,7 +2728,7 @@ export function Burger({
2683
2728
  </div>
2684
2729
  );
2685
2730
  }
2686
- `,i=`import { Fragment, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type MouseEvent } from 'react';
2731
+ `,t=`import { Fragment, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type MouseEvent } from 'react';
2687
2732
  import { createPortal } from 'react-dom';
2688
2733
  import cn from 'classnames';
2689
2734
  import { CommonComponentProps } from '../props';
@@ -3730,7 +3775,7 @@ export function Chronicles({
3730
3775
  </>
3731
3776
  );
3732
3777
  }
3733
- `,o=`import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3778
+ `,i=`import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3734
3779
  import { CommonComponentProps } from '../props';
3735
3780
  import { LinkWrapper, useScopedStyles, type ContentLink } from '../utils/index';
3736
3781
 
@@ -4259,7 +4304,7 @@ export function ClickGallerie({ settings, content = [], isEditor }: ClickGalleri
4259
4304
  </>
4260
4305
  );
4261
4306
  }
4262
- `,r=`import { useCallback, useEffect, useMemo, useState } from 'react';
4307
+ `,o=`import { useCallback, useEffect, useMemo, useState } from 'react';
4263
4308
  import cn from 'classnames';
4264
4309
  import { CommonComponentProps } from '../props';
4265
4310
  import { buildColorVars, scalingValue, useScopedStyles } from '../utils/index';
@@ -5003,7 +5048,7 @@ export function FAQ({ settings, content, isEditor, isPreviewMode, isEditMode, ac
5003
5048
  </>
5004
5049
  );
5005
5050
  }
5006
- `,a=`import React, { useMemo, useState } from 'react';
5051
+ `,r=`import React, { useMemo, useState } from 'react';
5007
5052
  import { CommonComponentProps } from '../props';
5008
5053
  import { buildColorVars, getFormFieldValidationError, scalingValue, useScopedStyles } from '../utils/index';
5009
5054
  import { omitTextColors, textStylesToCss, type TextStyles } from '../utils/textStylesToCss';
@@ -5641,7 +5686,7 @@ const COLOR_VAR_MAP: Record<ColorKeys, string> = {
5641
5686
  };
5642
5687
 
5643
5688
  const STATE_KEYS = ['hover', 'focus', 'filled', 'success', 'error'] as const;
5644
- `,e=`import { Splide, SplideSlide } from '@splidejs/react-splide';
5689
+ `,a=`import { Splide, SplideSlide } from '@splidejs/react-splide';
5645
5690
  import '@splidejs/react-splide/css/core';
5646
5691
  import { CommonComponentProps } from '../props';
5647
5692
  import { EmbedMediaFrame, getEmbedAspect, getEmbedPlayback, isEmbedMedia } from '../utils/index';
@@ -5779,13 +5824,6 @@ function getCSS(P: string): string {
5779
5824
  flex-direction: column;
5780
5825
  align-items: center;
5781
5826
  }
5782
- .\${P}-custom-layout .\${P}-item-image-link {
5783
- flex: 1 1 0%;
5784
- min-height: 0;
5785
- }
5786
- .\${P}-custom-layout.\${P}-text-outside .\${P}-item-image-link {
5787
- flex: none;
5788
- }
5789
5827
  .\${P}-item-text-link {
5790
5828
  display: flex;
5791
5829
  flex-direction: column;
@@ -7307,94 +7345,11 @@ function resolveLightboxImageDisplay(
7307
7345
  return value?.display === 'cover' ? 'cover' : 'fit';
7308
7346
  }
7309
7347
 
7310
- function getCustomGridSpanWidth(layout: CustomGridLayout, span: number): number {
7311
- return layout.columnWidth * span + layout.gutterWidth * Math.max(0, span - 1);
7312
- }
7313
-
7314
- type CustomGridSlot = {
7315
- // first column the entry covers and how many, kept in the layout's columns
7316
- column: number;
7317
- span: number;
7318
- width: number;
7319
- top: number;
7320
- height: number;
7321
- gridColumn: string;
7322
- gridRow: string;
7323
- };
7324
-
7325
- function getCustomGridBlocksBottom(layout: CustomGridLayout): number {
7326
- return layout.blocks.reduce((bottom, block) => Math.max(bottom, Math.max(0, block.top) + Math.max(0, block.height)), 0);
7327
- }
7328
-
7329
- function getCustomGridVerticalGap(layout: CustomGridLayout): number {
7330
- if (typeof layout.verticalGap === 'number') return Math.max(0, layout.verticalGap);
7331
- return Math.max(0, (layout.repeatHeight ?? 0) - getCustomGridBlocksBottom(layout));
7332
- }
7333
-
7334
- // entries fill the layout's blocks in order, one group after another
7335
- function getCustomGridSlot(layout: CustomGridLayout, index: number): CustomGridSlot {
7336
- const block = layout.blocks[index % layout.blocks.length];
7337
- const span = Math.min(Math.max(1, Math.round(block.span)), layout.columnsCount);
7338
- const column = Math.min(Math.max(0, Math.round(block.column)), layout.columnsCount - span);
7339
- return {
7340
- column,
7341
- span,
7342
- width: getCustomGridSpanWidth(layout, span),
7343
- top: Math.max(0, block.top),
7344
- height: Math.max(0, block.height),
7345
- gridColumn: \`\${column + 1} / span \${span}\`,
7346
- gridRow: \`\${Math.floor(index / layout.blocks.length) + 1}\`,
7347
- };
7348
- }
7349
-
7350
- // the first of the grid's beats at or under \`value\`, from the top of the group
7351
- function snapDownToCustomGridBeat(layout: CustomGridLayout, value: number): number {
7352
- const beat = layout.beat ?? 0;
7353
- return beat > 0 ? Math.ceil(value / beat - 1e-6) * beat : value;
7354
- }
7355
-
7356
- /**
7357
- * With the text outside the blocks, every entry's text takes room under its block: an entry of its
7358
- * group under it in the same columns keeps where it is drawn, moved along with the entry above,
7359
- * unless that text reaches it, and then goes onto the first beat under the text. The group grows to
7360
- * the first beat under its lowest text. Text heights, tops and group heights are in layout units,
7361
- * like the blocks'.
7362
- */
7363
- function getCustomGridOutsideTextPlacement(layout: CustomGridLayout, textHeights: number[]) {
7364
- const slots = textHeights.map((_, index) => getCustomGridSlot(layout, index));
7365
- const tops = slots.map(slot => slot.top);
7366
- const groupHeights: number[] = [];
7367
- for (let groupStart = 0; groupStart < slots.length; groupStart += layout.blocks.length) {
7368
- const group = slots
7369
- .map((slot, index) => ({ slot, index }))
7370
- .slice(groupStart, groupStart + layout.blocks.length)
7371
- .sort((a, b) => a.slot.top - b.slot.top);
7372
- let bottom = getCustomGridBlocksBottom(layout);
7373
- for (const { slot, index } of group) {
7374
- let top = slot.top;
7375
- for (const { slot: above, index: aboveIndex } of group) {
7376
- const isAbove = above.top + above.height <= slot.top + 1e-6 && aboveIndex !== index;
7377
- const sharesColumns = above.column < slot.column + slot.span && slot.column < above.column + above.span;
7378
- if (isAbove && sharesColumns) {
7379
- const textBottom = tops[aboveIndex] + above.height + textHeights[aboveIndex];
7380
- const drawnTop = slot.top + tops[aboveIndex] - above.top;
7381
- top = Math.max(top, drawnTop >= textBottom - 1e-6 ? drawnTop : snapDownToCustomGridBeat(layout, textBottom));
7382
- }
7383
- }
7384
- tops[index] = top;
7385
- bottom = Math.max(bottom, tops[index] + slot.height + textHeights[index]);
7386
- }
7387
- groupHeights.push(snapDownToCustomGridBeat(layout, bottom));
7388
- }
7389
- return { tops, groupHeights };
7390
- }
7391
-
7392
7348
  export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, metadata, activeEvent, layoutId, portalId }: GridProps) {
7393
7349
  const { prefix: P } = useScopedStyles();
7394
7350
  const {
7395
7351
  type = 'a',
7396
7352
  gridLayout,
7397
- customGrid,
7398
7353
  textBoxWidth = 100,
7399
7354
  verticalGap,
7400
7355
  entriesCount,
@@ -7442,7 +7397,6 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7442
7397
  hover = 'none',
7443
7398
  alignEntries = 'off',
7444
7399
  align = 'top',
7445
- textGrowth = 'inside',
7446
7400
  } = settings;
7447
7401
 
7448
7402
  const resolvedTitleTextStyle: TextStyles = {
@@ -7532,16 +7486,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7532
7486
  const hoverEffectClass = hover !== 'none' && (!isEditor || isPreviewMode) ? \` \${P}-hover-\${hover}\` : '';
7533
7487
  const wrapperStateClasses = \`\${stateClass}\${showTextOnHover ? \` \${P}-show-text-hover\` : ''}\${hoverEffectClass}\`.trim();
7534
7488
 
7535
- // a custom layout places entries itself, in place of the columns, gap and entries count: its
7536
- // group of blocks repeats for as many entries as there are. Stored, it is only the preset it is
7537
- // linked to; the CMS and the site put the blocks in before it gets here
7538
- const customLayout = customGrid && Array.isArray(customGrid.blocks) && customGrid.blocks.length > 0 ? customGrid : undefined;
7539
- const resEntriesCount = customLayout || entriesCount === 0 ? Infinity : entriesCount;
7540
- // outside, the media fills the block and the text takes room of its own beyond it: below the
7541
- // media, or above it when the type puts the text first, moving the entries under it down
7542
- const isTextOutside = !!customLayout && textGrowth === 'outside';
7543
- const itemInnerRefs = useRef<(HTMLDivElement | null)[]>([]);
7544
- const [customTextHeights, setCustomTextHeights] = useState<number[]>([]);
7489
+ const resEntriesCount = entriesCount === 0 ? Infinity : entriesCount;
7545
7490
 
7546
7491
  const cropContent = (content ?? []).slice(0, resEntriesCount);
7547
7492
  const lightboxMediaToPreload = useMemo(
@@ -7549,24 +7494,23 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7549
7494
  [cropContent, lightbox],
7550
7495
  );
7551
7496
 
7552
- const size = gridLayout?.entryWidth ?? 0.2;
7497
+ const size = gridLayout.entryWidth ?? 0.2;
7553
7498
 
7554
- const imageDisplaySettings = typeof imageDisplay === 'string' ? { display: imageDisplay } : imageDisplay;
7555
- const isCover = imageDisplaySettings?.display === 'cover';
7556
- const ratioValue = imageDisplaySettings?.ratioValue ?? '1:1';
7557
- const ratioReversed = imageDisplaySettings?.reversed ?? false;
7499
+ const isCover = imageDisplay?.display === 'cover';
7500
+ const ratioValue = imageDisplay?.ratioValue ?? '1:1';
7501
+ const ratioReversed = imageDisplay?.reversed ?? false;
7558
7502
  const [rW, rH] = ratioValue.split(':').map(Number);
7559
7503
  const effW = ratioReversed ? rH : rW;
7560
7504
  const effH = ratioReversed ? rW : rH;
7561
7505
  const aspectRatio = \`\${effW} / \${effH}\`;
7562
7506
 
7563
- const columnsCount = gridLayout?.columnsCount ?? 1;
7507
+ const columnsCount = gridLayout.columnsCount;
7564
7508
  const entryWidthScaled = scalingValue(size ?? 0, isEditor);
7565
- // a custom block sets the entry's height, so the fit slider has nothing to size it by
7566
- const isFitSlider = !customLayout && !isCover && slider !== 'off';
7509
+ const imageWrapperWidth = entryWidthScaled;
7510
+ const isFitSlider = !isCover && slider !== 'off';
7567
7511
 
7568
7512
  const itemsInLastRow = cropContent.length % columnsCount || columnsCount;
7569
- const isPartialLastRow = !customLayout && itemsInLastRow < columnsCount && cropContent.length > 0;
7513
+ const isPartialLastRow = itemsInLastRow < columnsCount && cropContent.length > 0;
7570
7514
  const lastRowStartIndex = cropContent.length - itemsInLastRow;
7571
7515
  const lastRowStartColumn = isPartialLastRow
7572
7516
  ? Math.floor((columnsCount - itemsInLastRow) / 2) + 1
@@ -7574,23 +7518,19 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7574
7518
 
7575
7519
  const imageBorderRadius = imageCorners ? scalingValue(imageCorners, isEditor) : undefined;
7576
7520
 
7577
- const getImageWrapperStyle = (entryWidth: string, slot?: CustomGridSlot): React.CSSProperties => ({
7578
- width: entryWidth,
7579
- // in a custom block the media takes whatever the entry's text leaves of the block's height,
7580
- // or the whole block when the text goes outside it
7581
- ...(slot
7582
- ? isTextOutside
7583
- ? { height: scalingValue(slot.height, isEditor), flexShrink: 0, overflow: 'hidden' }
7584
- : { flex: '1 1 0%', minHeight: 0, overflow: 'hidden' }
7585
- : isCover
7586
- ? { aspectRatio, height: 'auto', overflow: 'hidden' }
7587
- : { height: 'auto' }),
7521
+ const imageWrapperStyle: React.CSSProperties = {
7522
+ width: imageWrapperWidth,
7523
+ ...(isCover
7524
+ ? { aspectRatio, height: 'auto', overflow: 'hidden' }
7525
+ : { height: 'auto' }),
7588
7526
  ...(imageBorderRadius ? { borderRadius: imageBorderRadius, overflow: 'hidden' } : {}),
7589
- });
7527
+ };
7590
7528
 
7591
7529
  const imageWrapperClassName = \`\${P}-item-image-wrapper\${isFitSlider ? \` \${P}-item-image-wrapper-fit-slider\` : ''}\`.trim();
7592
7530
  const isTextBeforeImage = type === 'd' || type === 'e' || type === 'f';
7593
- const shouldAlignEntries = !customLayout && alignEntries === 'on';
7531
+ const shouldAlignEntries = alignEntries === 'on';
7532
+ const textBoxWidthStyle = \`calc(\${scalingValue(size ?? 0, isEditor)} * (\${textBoxWidth} / 100))\`;
7533
+ const controlWidthStyle = scalingValue(size * textBoxWidth / 100, isEditor);
7594
7534
 
7595
7535
  const imageRadiusStyle = imageBorderRadius
7596
7536
  ? { borderRadius: imageBorderRadius, [MEDIA_RADIUS_VAR]: imageBorderRadius } as React.CSSProperties
@@ -7610,68 +7550,9 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7610
7550
  width: 'auto',
7611
7551
  height: 'auto',
7612
7552
  maxWidth: '100%',
7613
- ...(customLayout ? { maxHeight: '100%' } : {}),
7614
7553
  ...imageRadiusStyle,
7615
7554
  };
7616
7555
 
7617
- // the text's height is only known once laid out: what an entry measures beyond its media, in
7618
- // layout units, the layout's whole width taken as the wrapper's
7619
- const customGridWidth = customLayout ? getCustomGridSpanWidth(customLayout, customLayout.columnsCount) : 0;
7620
- useLayoutEffect(() => {
7621
- if (!isTextOutside) {
7622
- setCustomTextHeights(prev => (prev.length > 0 ? [] : prev));
7623
- return;
7624
- }
7625
- const wrapper = containerRef.current;
7626
- const inners = itemInnerRefs.current.slice(0, cropContent.length);
7627
- const measure = () => {
7628
- const unit = wrapper && customGridWidth > 0 ? wrapper.offsetWidth / customGridWidth : 0;
7629
- const heights = inners.map((inner) => {
7630
- const media = inner?.querySelector<HTMLElement>(\`.\${P}-item-image-wrapper\`);
7631
- return inner && media && unit > 0 ? Math.max(0, inner.offsetHeight - media.offsetHeight) / unit : 0;
7632
- });
7633
- setCustomTextHeights(prev => (
7634
- prev.length === heights.length && prev.every((height, index) => Math.abs(height - heights[index]) < 1e-5)
7635
- ? prev
7636
- : heights
7637
- ));
7638
- };
7639
- measure();
7640
- const ro = new ResizeObserver(measure);
7641
- if (wrapper) ro.observe(wrapper);
7642
- inners.forEach(inner => inner && ro.observe(inner));
7643
- return () => ro.disconnect();
7644
- }, [isTextOutside, cropContent.length, customGridWidth, P]);
7645
- const customOutsideText = customLayout && isTextOutside
7646
- ? getCustomGridOutsideTextPlacement(customLayout, cropContent.map((_: unknown, index: number) => customTextHeights[index] ?? 0))
7647
- : undefined;
7648
-
7649
- const customRowsCount = customLayout ? Math.ceil(cropContent.length / customLayout.blocks.length) : 0;
7650
- const customGroupHeight = customLayout ? scalingValue(getCustomGridBlocksBottom(customLayout), isEditor) : '';
7651
- const wrapperLayoutStyle: React.CSSProperties = customLayout
7652
- ? {
7653
- gridTemplateColumns: \`repeat(\${customLayout.columnsCount}, \${scalingValue(customLayout.columnWidth, isEditor)})\`,
7654
- // every group keeps the height of its blocks, or of the beats its text outside them takes,
7655
- // but the last, which ends where its entries do
7656
- gridTemplateRows: customRowsCount > 1
7657
- ? customOutsideText
7658
- ? \`\${customOutsideText.groupHeights.slice(0, -1).map(height => \`minmax(\${scalingValue(height, isEditor)}, auto)\`).join(' ')} auto\`
7659
- : \`repeat(\${customRowsCount - 1}, minmax(\${customGroupHeight}, auto)) auto\`
7660
- : 'auto',
7661
- rowGap: scalingValue(getCustomGridVerticalGap(customLayout), isEditor),
7662
- columnGap: scalingValue(customLayout.gutterWidth, isEditor),
7663
- width: scalingValue(getCustomGridSpanWidth(customLayout, customLayout.columnsCount), isEditor),
7664
- }
7665
- : {
7666
- gridTemplateColumns: \`repeat(\${columnsCount}, \${entryWidthScaled})\`,
7667
- rowGap: shouldAlignEntries ? 0 : scalingValue(verticalGap ?? 0, isEditor),
7668
- columnGap: scalingValue(gridLayout?.horizontalGap ?? 0, isEditor),
7669
- width: scalingValue(gridLayout?.wrapperWidth ?? 0, isEditor),
7670
- ...(shouldAlignEntries
7671
- ? { [\`--\${P}-align-entries-row-gap\`]: scalingValue(verticalGap ?? 0, isEditor) }
7672
- : {}),
7673
- };
7674
-
7675
7556
  const [containerWidth, setContainerWidth] = useState(0);
7676
7557
  const containerRef = useRef<HTMLDivElement>(null);
7677
7558
 
@@ -7741,8 +7622,16 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7741
7622
  <div style={colorVars}>
7742
7623
  <div
7743
7624
  ref={containerRef}
7744
- className={\`\${P}-wrapper \${P}-type-\${type}\${shouldAlignEntries ? \` \${P}-align-entries\` : ''}\${customLayout ? \` \${P}-custom-layout\` : ''}\${isTextOutside ? \` \${P}-text-outside\` : ''} \${P}-image-align-\${align} \${wrapperStateClasses}\`.trim()}
7745
- style={wrapperLayoutStyle}>
7625
+ className={\`\${P}-wrapper \${P}-type-\${type}\${shouldAlignEntries ? \` \${P}-align-entries\` : ''} \${P}-image-align-\${align} \${wrapperStateClasses}\`.trim()}
7626
+ style={{
7627
+ gridTemplateColumns: \`repeat(\${columnsCount}, \${entryWidthScaled})\`,
7628
+ rowGap: shouldAlignEntries ? 0 : scalingValue(verticalGap ?? 0, isEditor),
7629
+ columnGap: scalingValue(gridLayout.horizontalGap ?? 0, isEditor),
7630
+ width: scalingValue(gridLayout.wrapperWidth ?? 0, isEditor),
7631
+ ...(shouldAlignEntries
7632
+ ? { [\`--\${P}-align-entries-row-gap\`]: scalingValue(verticalGap ?? 0, isEditor) }
7633
+ : {}),
7634
+ }}>
7746
7635
  {cropContent.map((item: any, index: number) => {
7747
7636
  const hasTitle = hasText(item.title);
7748
7637
  const hasSubtitle = hasText(item.subtitle);
@@ -7752,20 +7641,6 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7752
7641
  const gridColumn = isPartialLastRow && index >= lastRowStartIndex
7753
7642
  ? \`\${lastRowStartColumn + (index - lastRowStartIndex)}\`
7754
7643
  : undefined;
7755
- const customSlot = customLayout ? getCustomGridSlot(customLayout, index) : undefined;
7756
- const itemSize = customSlot?.width ?? size;
7757
- const itemWidthScaled = scalingValue(itemSize, isEditor);
7758
- const textBoxWidthStyle = \`calc(\${itemWidthScaled} * (\${textBoxWidth} / 100))\`;
7759
- const controlWidthStyle = scalingValue(itemSize * textBoxWidth / 100, isEditor);
7760
- const imageWrapperStyle = getImageWrapperStyle(itemWidthScaled, customSlot);
7761
- const itemStyle: React.CSSProperties | undefined = customSlot
7762
- ? {
7763
- gridColumn: customSlot.gridColumn,
7764
- gridRow: customSlot.gridRow,
7765
- alignSelf: 'start',
7766
- marginTop: scalingValue(customOutsideText?.tops[index] ?? customSlot.top, isEditor),
7767
- }
7768
- : gridColumn && !shouldAlignEntries ? { gridColumn } : undefined;
7769
7644
 
7770
7645
  const typeCTextBlock = isTextBeforeImage ? (
7771
7646
  <div className={\`\${P}-item-text-block\`}>
@@ -7913,7 +7788,7 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
7913
7788
  </div>
7914
7789
  )}
7915
7790
  <Splide
7916
- key={\`\${transition}-\${itemSize}-\${direction}-\${sliderTiming}-\${containerWidth}-\${layoutId}\`}
7791
+ key={\`\${transition}-\${size}-\${direction}-\${sliderTiming}-\${containerWidth}-\${layoutId}\`}
7917
7792
  className={\`\${P}-item-slider\`}
7918
7793
  options={{
7919
7794
  arrows: false,
@@ -8007,18 +7882,16 @@ export function Grid({ settings, content, isEditor, isPreviewMode, isEditMode, m
8007
7882
  <div
8008
7883
  key={index}
8009
7884
  className={\`\${P}-item\`.trim()}
8010
- style={itemStyle}
7885
+ style={gridColumn && !shouldAlignEntries ? { gridColumn } : undefined}
8011
7886
  >
8012
7887
  <div
8013
- ref={(el) => { itemInnerRefs.current[index] = el; }}
8014
- className={\`\${isEditMode
8015
- ? \`\${P}-item-inner\`
7888
+ className={\`\${isEditMode
7889
+ ? \`\${P}-item-inner\`
8016
7890
  : \`\${P}-item-inner-hidden\`}\${shouldAlignEntries && isLastRow ? \` \${P}-item-inner-last-row\` : ''}\`.trim()}
8017
7891
  style={{
8018
7892
  width: (textBoxWidth ?? 0) > 100
8019
- ? \`calc(\${itemWidthScaled} * (\${textBoxWidth} / 100))\`
8020
- : itemWidthScaled,
8021
- ...(customSlot && !isTextOutside ? { height: scalingValue(customSlot.height, isEditor) } : {}),
7893
+ ? \`calc(\${entryWidthScaled} * (\${textBoxWidth} / 100))\`
7894
+ : entryWidthScaled,
8022
7895
  ...(gridColumn && shouldAlignEntries ? { gridColumn } : {}),
8023
7896
  }}
8024
7897
  >
@@ -8101,45 +7974,17 @@ type GridLayoutConfig = {
8101
7974
  lockedParam?: 'wrapperWidth' | 'entryWidth' | 'horizontalGap' | null;
8102
7975
  };
8103
7976
 
8104
- type CustomGridBlock = {
8105
- // first column the block covers, from 0
8106
- column: number;
8107
- span: number;
8108
- // offset from the top of its group
8109
- top: number;
8110
- // height of the whole entry: its media fills what the text leaves
8111
- height: number;
8112
- };
8113
-
8114
- // lengths are fractions of the layout width, like the article grid's
8115
- type CustomGridLayout = {
8116
- columnsCount: number;
8117
- columnWidth: number;
8118
- gutterWidth: number;
8119
- maxWidth: number | null;
8120
- // space between one group of blocks and the next
8121
- verticalGap?: number;
8122
- // the article grid's beat: entries the text outside the blocks pushes down land on it; 0, or
8123
- // missing from layouts resolved before it, when there is none
8124
- beat?: number;
8125
- // layouts saved before the vertical gap kept the height of a whole group instead
8126
- repeatHeight?: number;
8127
- blocks: CustomGridBlock[];
8128
- };
8129
-
8130
7977
  type GridSettings = {
8131
7978
  type: 'a' | 'b' | 'c' | 'd' | 'e' | 'f';
8132
- // one of the two places entries: Neptune's columns, or a layout drawn in the custom grid builder
8133
- gridLayout?: GridLayoutConfig;
8134
- customGrid?: CustomGridLayout;
7979
+ gridLayout: GridLayoutConfig;
8135
7980
  textBoxWidth: number;
8136
- verticalGap?: number;
8137
- entriesCount?: number;
7981
+ verticalGap: number;
7982
+ entriesCount: number;
8138
7983
  lightbox: 'on' | 'off';
8139
- imageDisplay: 'fit' | 'cover' | {
7984
+ imageDisplay: {
8140
7985
  display: 'fit' | 'cover';
8141
- ratioValue?: '1:1' | '2:3' | '3:4' | '4:5' | '16:9';
8142
- reversed?: boolean;
7986
+ ratioValue: '1:1' | '2:3' | '3:4' | '4:5' | '16:9';
7987
+ reversed: boolean;
8143
7988
  };
8144
7989
  imageCorners?: number;
8145
7990
  lightboxImageDisplay?: 'fit' | 'cover' | { display?: 'fit' | 'cover' };
@@ -8149,10 +7994,8 @@ type GridSettings = {
8149
7994
  transition: 'fade' | 'slide',
8150
7995
  showText: 'always' | 'on hover';
8151
7996
  hover?: 'none' | 'zoom-in' | 'greyscale' | 'scale-down';
8152
- alignEntries?: 'on' | 'off';
7997
+ alignEntries: 'on' | 'off';
8153
7998
  align?: 'top' | 'center' | 'bottom';
8154
- // with a custom layout: whether a block holds the entry's text or only its media
8155
- textGrowth?: 'inside' | 'outside';
8156
7999
  titleMarginTop: number;
8157
8000
  subtitleMarginTop: number;
8158
8001
  titleColor: string;
@@ -25519,4 +25362,4 @@ export function Waterfall({
25519
25362
  </>
25520
25363
  );
25521
25364
  }
25522
- `,C={[n.BurgerComponent.id]:t,[n.ChroniclesComponent.id]:i,[n.ClickGallerieComponent.id]:o,[n.CustomGridComponent.id]:e,[n.FAQComponent.id]:r,[n.FormComponent.id]:a,[n.GridComponent.id]:e,[n.HelixComponent.id]:s,[n.HiveComponent.id]:l,[n.LightboxJournalComponent.id]:c,[n.LightboxStripComponent.id]:d,[n.ListComponent.id]:u,[n.MarqueeComponent.id]:g,[n.MarqueeTextComponent.id]:m,[n.MercuryComponent.id]:p,[n.OnelinerFormComponent.id]:h,[n.PretextComponent.id]:f,[n.ScaleComponent.id]:v,[n.SimpleButtonComponent.id]:P,[n.Slider20Component.id]:x,[n.TestimonialGridComponent.id]:b,[n.TestimonialSingleComponent.id]:y,[n.WaterfallComponent.id]:S};exports.componentSources=C;
25365
+ `,w={[n.BurgerComponent.id]:e,[n.ChroniclesComponent.id]:t,[n.ClickGallerieComponent.id]:i,[n.FAQComponent.id]:o,[n.FormComponent.id]:r,[n.GridComponent.id]:a,[n.HelixComponent.id]:s,[n.HiveComponent.id]:l,[n.LightboxJournalComponent.id]:c,[n.LightboxStripComponent.id]:d,[n.ListComponent.id]:u,[n.MarqueeComponent.id]:g,[n.MarqueeTextComponent.id]:m,[n.MercuryComponent.id]:p,[n.OnelinerFormComponent.id]:h,[n.PretextComponent.id]:f,[n.ScaleComponent.id]:v,[n.SimpleButtonComponent.id]:P,[n.Slider20Component.id]:x,[n.TestimonialGridComponent.id]:b,[n.TestimonialSingleComponent.id]:y,[n.WaterfallComponent.id]:S};exports.componentSources=w;