UNPKG

@wordpress/widget-dashboard

Version:

Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.

1 lines • 1.6 kB
{"version":3,"file":"normalize-grid-settings.cjs","names":[],"sources":["../../../src/utils/normalize-grid-settings/normalize-grid-settings.ts"],"sourcesContent":["import type { WidgetGridLayoutSettings, WidgetGridSettings } from '../../types';\n\n/**\n * Fills in the row height of grid settings. Any finite positive number is\n * honored as-is; an absent or invalid value takes `defaultRowHeight`.\n * Masonry settings pass through, since lane heights follow content.\n *\n * @param settings Grid settings to normalize.\n * @param defaultRowHeight Fallback row height when none is set.\n */\nexport function normalizeGridSettings(\n\tsettings: WidgetGridSettings,\n\tdefaultRowHeight: number\n): WidgetGridSettings {\n\tif ( ( settings.model ?? 'grid' ) === 'masonry' ) {\n\t\treturn settings;\n\t}\n\n\t// The guard above cannot narrow the union for TypeScript: `model` is\n\t// optional and the check goes through `??`.\n\tconst gridSettings = settings as WidgetGridLayoutSettings;\n\n\tconst { rowHeight } = gridSettings;\n\tconst resolved =\n\t\ttypeof rowHeight === 'number' &&\n\t\tNumber.isFinite( rowHeight ) &&\n\t\trowHeight > 0\n\t\t\t? rowHeight\n\t\t\t: defaultRowHeight;\n\n\tif ( rowHeight === resolved ) {\n\t\treturn settings;\n\t}\n\n\treturn {\n\t\t...gridSettings,\n\t\trowHeight: resolved,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;AAUA,SAAgB,sBACf,UACA,kBACqB;CACrB,KAAO,SAAS,SAAS,YAAa,WACrC,OAAO;CAKR,MAAM,eAAe;CAErB,MAAM,EAAE,cAAc;CACtB,MAAM,WACL,OAAO,cAAc,YACrB,OAAO,SAAU,SAAU,KAC3B,YAAY,IACT,YACA;CAEJ,IAAK,cAAc,UAClB,OAAO;CAGR,OAAO;EACN,GAAG;EACH,WAAW;CACZ;AACD"}