@selfhelp/shared 1.14.10 → 1.14.12

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.
@@ -475,6 +475,101 @@ export function mapChipVariantToHeroUiVariant(
475
475
  }
476
476
  }
477
477
 
478
+ // ===== layout dimensions (shared_width / shared_height / grid span / divider) =====
479
+
480
+ /** A React Native-safe dimension: a px number, a percentage string, or "auto". */
481
+ export type TReactNativeDimension = number | `${number}%` | 'auto';
482
+
483
+ /**
484
+ * Parse a CMS dimension string (`shared_width`/`shared_height`/`shared_mi*`/
485
+ * `shared_ma*`) into a React Native-safe value. Web (Mantine) accepts the raw
486
+ * string verbatim ("320px", "100%", "auto"); React Native does NOT accept a
487
+ * unit suffix, so a px value must become a unitless number:
488
+ * "320px" | "320" | 320 -> 320 (number)
489
+ * "50%" -> "50%" (percentage string)
490
+ * "auto" -> "auto"
491
+ * ""/undefined/unknown -> undefined (renderer keeps its default)
492
+ */
493
+ export function parseDimensionToReactNative(
494
+ value: string | number | undefined | null,
495
+ ): TReactNativeDimension | undefined {
496
+ if (value === undefined || value === null) return undefined;
497
+ if (typeof value === 'number') return Number.isFinite(value) ? value : undefined;
498
+ const trimmed = value.trim();
499
+ if (trimmed === '') return undefined;
500
+ if (trimmed === 'auto') return 'auto';
501
+ const pct = /^(\d+(?:\.\d+)?)%$/.exec(trimmed);
502
+ if (pct) {
503
+ const n = Number(pct[1]);
504
+ return `${n}%`;
505
+ }
506
+ const px = /^(\d+(?:\.\d+)?)(?:px)?$/.exec(trimmed);
507
+ if (px) return Number(px[1]);
508
+ return undefined;
509
+ }
510
+
511
+ /**
512
+ * Web pass-through for a CMS dimension: Mantine accepts "320px"/"100%"/"auto"
513
+ * verbatim. Returns undefined for empty so the renderer omits the prop.
514
+ */
515
+ export function parseDimensionToWeb(
516
+ value: string | number | undefined | null,
517
+ ): string | number | undefined {
518
+ if (value === undefined || value === null) return undefined;
519
+ if (typeof value === 'number') return value;
520
+ const trimmed = value.trim();
521
+ return trimmed === '' ? undefined : trimmed;
522
+ }
523
+
524
+ /** React Native flex layout for one emulated grid column. */
525
+ export interface IReactNativeGridColumn {
526
+ flexBasis: TReactNativeDimension;
527
+ flexGrow: number;
528
+ flexShrink: number;
529
+ }
530
+
531
+ /**
532
+ * Convert a Mantine `Grid.Col` span into a React Native flex layout for the
533
+ * emulated mobile grid. `cols` is the parent grid's column count (Mantine
534
+ * default 12).
535
+ * number -> a flex-basis percentage of (span / cols)
536
+ * "auto" -> grow to share remaining space (flexGrow 1, basis 0)
537
+ * "content" -> size to content (no grow/shrink, basis auto)
538
+ * invalid -> full row ("100%")
539
+ */
540
+ export function gridSpanToReactNativeColumn(
541
+ span: string | number | undefined | null,
542
+ cols: number = 12,
543
+ ): IReactNativeGridColumn {
544
+ const totalCols = cols > 0 ? cols : 12;
545
+ if (span === 'auto') return { flexBasis: 0, flexGrow: 1, flexShrink: 1 };
546
+ if (span === 'content') return { flexBasis: 'auto', flexGrow: 0, flexShrink: 0 };
547
+ const n = typeof span === 'number' ? span : Number.parseInt(String(span ?? ''), 10);
548
+ if (!Number.isFinite(n) || n <= 0) return { flexBasis: '100%', flexGrow: 0, flexShrink: 1 };
549
+ const clamped = Math.min(n, totalCols);
550
+ const pct = Math.round((clamped / totalCols) * 10000) / 100;
551
+ return { flexBasis: `${pct}%`, flexGrow: 0, flexShrink: 1 };
552
+ }
553
+
554
+ /**
555
+ * Map a `shared_divider_variant` (solid/dashed/dotted) onto a React Native
556
+ * `borderStyle`. The vocabularies are identical, so this validates the domain
557
+ * and falls back to 'solid'.
558
+ */
559
+ export function mapDividerVariantToReactNative(
560
+ variant: string | undefined | null,
561
+ ): 'solid' | 'dashed' | 'dotted' {
562
+ switch (variant) {
563
+ case 'dashed':
564
+ return 'dashed';
565
+ case 'dotted':
566
+ return 'dotted';
567
+ case 'solid':
568
+ default:
569
+ return 'solid';
570
+ }
571
+ }
572
+
478
573
  // ===== state helpers =====
479
574
 
480
575
  function hasState(states: readonly TSemanticState[] | undefined, state: TSemanticState): boolean {
@@ -4,7 +4,6 @@ SPDX-License-Identifier: MPL-2.0
4
4
  */
5
5
  import type { IBaseStyle, IContentField, IStyleWithSpacing } from './base';
6
6
  import type {
7
- TMantineSpacing,
8
7
  TMantineColor,
9
8
  TMantineOrientation,
10
9
  TMantineDirection,
@@ -12,34 +11,43 @@ import type {
12
11
  TMantineJustify,
13
12
  TMantineAlign,
14
13
  TMantineGridSpan,
14
+ TMantineGridGrow,
15
+ TMantineGridOverflow,
15
16
  TSharedSize,
16
17
  TSharedRadius,
17
18
  } from '../mantine/common';
18
19
 
19
20
  // Style-specific helper types only used in layout interfaces
20
21
  export type TMantineBorder = '0' | '1';
21
- // Cross-platform border toggle (card family): Mantine `withBorder` on web,
22
- // a themed border/divider on mobile.
22
+ // Cross-platform border toggle (card family + paper): Mantine `withBorder` on
23
+ // web, a themed border on mobile.
23
24
  export type TSharedBorder = '0' | '1';
25
+ // Cross-platform width/height/min/max dimension (e.g. "100%", "320px", "auto").
26
+ // Drives the web (Mantine) and the mobile (RN flexbox) renderer via the mapper.
27
+ export type TSharedDimension = string;
24
28
  export type TMantineWidth = string;
25
29
  export type TMantineHeight = string;
30
+ // Cross-platform divider line style (Mantine `variant` / RN `borderStyle`).
31
+ export type TSharedDividerVariant = 'solid' | 'dashed' | 'dotted';
32
+ export type TSharedDividerLabelPosition = 'left' | 'center' | 'right';
26
33
  export type TMantineDividerVariant = 'solid' | 'dashed' | 'dotted';
27
34
  export type TMantinePaperShadow = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
28
35
  export type TMantineCardShadow = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
29
36
  export type TMantineCardPadding = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
30
37
  export type TMantineGap = '0' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
38
+ // Cross-platform grid column count (string-encoded integer).
39
+ export type TSharedCols = string;
31
40
  export type TMantineCols = string;
32
41
  export type TMantineGridOffset = string;
33
42
  export type TMantineGridOrder = string;
34
43
  export type TMantineScrollAreaSize = string;
35
- export type TMantineScrollAreaType = 'hover' | 'always' | 'never' | 'scroll';
44
+ export type TMantineScrollAreaType = 'hover' | 'always' | 'auto' | 'never' | 'scroll';
36
45
 
37
46
  export interface IContainerStyle extends IStyleWithSpacing {
38
47
  style_name: 'container';
39
48
  shared_size?: IContentField<TSharedSize>;
40
49
  web_fluid?: IContentField<string>;
41
- web_px?: IContentField<TMantineSpacing>;
42
- web_py?: IContentField<TMantineSpacing>;}
50
+ }
43
51
 
44
52
  export interface IBoxStyle extends IStyleWithSpacing {
45
53
  style_name: 'box';
@@ -52,8 +60,8 @@ export interface IFlexStyle extends IStyleWithSpacing {
52
60
  shared_align?: IContentField<TMantineAlign>;
53
61
  shared_direction?: IContentField<TMantineDirection>;
54
62
  shared_wrap?: IContentField<TMantineWrap>;
55
- web_width?: IContentField<TMantineWidth>;
56
- web_height?: IContentField<TMantineHeight>;
63
+ shared_width?: IContentField<TSharedDimension>;
64
+ shared_height?: IContentField<TSharedDimension>;
57
65
  }
58
66
 
59
67
  export interface IGroupStyle extends IStyleWithSpacing {
@@ -61,10 +69,10 @@ export interface IGroupStyle extends IStyleWithSpacing {
61
69
  shared_gap?: IContentField<TMantineGap>;
62
70
  shared_justify?: IContentField<TMantineJustify>;
63
71
  shared_align?: IContentField<TMantineAlign>;
72
+ shared_width?: IContentField<TSharedDimension>;
73
+ shared_height?: IContentField<TSharedDimension>;
64
74
  web_group_wrap?: IContentField<'0' | '1'>;
65
75
  web_group_grow?: IContentField<'0' | '1'>;
66
- web_width?: IContentField<TMantineWidth>;
67
- web_height?: IContentField<TMantineHeight>;
68
76
  }
69
77
 
70
78
  export interface IStackStyle extends IStyleWithSpacing {
@@ -72,71 +80,77 @@ export interface IStackStyle extends IStyleWithSpacing {
72
80
  shared_gap?: IContentField<TMantineGap>;
73
81
  shared_justify?: IContentField<TMantineJustify>;
74
82
  shared_align?: IContentField<TMantineAlign>;
75
- web_width?: IContentField<TMantineWidth>;
76
- web_height?: IContentField<TMantineHeight>;
83
+ shared_width?: IContentField<TSharedDimension>;
84
+ shared_height?: IContentField<TSharedDimension>;
77
85
  }
78
86
 
79
87
  export interface ISimpleGridStyle extends IStyleWithSpacing {
80
88
  style_name: 'simple-grid';
81
- web_cols?: IContentField<TMantineCols>;
82
- web_spacing?: IContentField<TMantineSpacing>;
83
- web_breakpoints?: IContentField<string>;
84
- web_vertical_spacing?: IContentField<TMantineSpacing>;
85
- web_width?: IContentField<TMantineWidth>;
86
- web_height?: IContentField<TMantineHeight>;
89
+ shared_cols?: IContentField<TSharedCols>;
90
+ shared_gap?: IContentField<TMantineGap>;
91
+ shared_vertical_spacing?: IContentField<TMantineGap>;
92
+ shared_width?: IContentField<TSharedDimension>;
93
+ shared_height?: IContentField<TSharedDimension>;
94
+ // Web-only responsive column overrides; clear to inherit shared_cols.
95
+ web_cols_sm?: IContentField<TSharedCols>;
96
+ web_cols_md?: IContentField<TSharedCols>;
97
+ web_cols_lg?: IContentField<TSharedCols>;
87
98
  }
88
99
 
89
100
  export interface IGridStyle extends IStyleWithSpacing {
90
101
  style_name: 'grid';
91
- web_cols?: IContentField<TMantineCols>;
102
+ shared_cols?: IContentField<TSharedCols>;
92
103
  shared_gap?: IContentField<TMantineGap>;
93
104
  shared_justify?: IContentField<TMantineJustify>;
94
105
  shared_align?: IContentField<TMantineAlign>;
95
- web_grid_overflow?: IContentField<string>;
96
- web_width?: IContentField<TMantineWidth>;
97
- web_height?: IContentField<TMantineHeight>;}
106
+ shared_width?: IContentField<TSharedDimension>;
107
+ shared_height?: IContentField<TSharedDimension>;
108
+ web_grid_overflow?: IContentField<TMantineGridOverflow>;
109
+ }
98
110
 
99
111
  export interface IGridColumnStyle extends IStyleWithSpacing {
100
112
  style_name: 'grid-column';
101
- web_grid_span?: IContentField<TMantineGridSpan>;
102
- web_grid_offset?: IContentField<TMantineGridOffset>;
103
- web_grid_order?: IContentField<TMantineGridOrder>;
104
- web_grid_grow?: IContentField<string>;
105
- web_width?: IContentField<TMantineWidth>;
106
- web_height?: IContentField<TMantineHeight>;}
113
+ shared_grid_span?: IContentField<TMantineGridSpan>;
114
+ shared_grid_offset?: IContentField<TMantineGridOffset>;
115
+ shared_grid_order?: IContentField<TMantineGridOrder>;
116
+ shared_grid_grow?: IContentField<TMantineGridGrow>;
117
+ shared_width?: IContentField<TSharedDimension>;
118
+ shared_height?: IContentField<TSharedDimension>;
119
+ }
107
120
 
108
121
  export interface ISpaceStyle extends IStyleWithSpacing {
109
122
  style_name: 'space';
110
123
  shared_size?: IContentField<TSharedSize>;
111
- web_space_direction?: IContentField<string>;
124
+ shared_orientation?: IContentField<TMantineOrientation>;
112
125
  }
113
126
 
114
- export interface IDividerStyle extends IBaseStyle {
127
+ export interface IDividerStyle extends IStyleWithSpacing {
115
128
  style_name: 'divider';
116
- web_divider_variant?: IContentField<TMantineDividerVariant>;
129
+ shared_divider_variant?: IContentField<TSharedDividerVariant>;
117
130
  shared_size?: IContentField<TSharedSize>;
118
131
  divider_label?: IContentField<string>;
119
- web_divider_label_position?: IContentField<string>;
132
+ shared_divider_label_position?: IContentField<TSharedDividerLabelPosition>;
120
133
  shared_orientation?: IContentField<TMantineOrientation>;
121
134
  shared_color?: IContentField<TMantineColor>;}
122
135
 
123
136
  export interface IPaperStyle extends IStyleWithSpacing {
124
137
  style_name: 'paper';
138
+ // Optional auto-styled heading rendered above the content when non-empty;
139
+ // never auto-creates a child section.
140
+ title?: IContentField<string>;
125
141
  web_paper_shadow?: IContentField<TMantinePaperShadow>;
126
142
  shared_radius?: IContentField<TSharedRadius>;
127
- web_px?: IContentField<TMantineSpacing>;
128
- web_py?: IContentField<TMantineSpacing>;
129
- web_border?: IContentField<TMantineBorder>;}
143
+ shared_border?: IContentField<TSharedBorder>;}
130
144
 
131
- export interface ICenterStyle extends IBaseStyle {
145
+ export interface ICenterStyle extends IStyleWithSpacing {
132
146
  style_name: 'center';
133
147
  web_center_inline?: IContentField<string>;
134
- web_width?: IContentField<TMantineWidth>;
135
- web_height?: IContentField<TMantineHeight>;
136
- web_miw?: IContentField<TMantineWidth>;
137
- web_mih?: IContentField<TMantineHeight>;
138
- web_maw?: IContentField<TMantineWidth>;
139
- web_mah?: IContentField<TMantineHeight>;
148
+ shared_width?: IContentField<TSharedDimension>;
149
+ shared_height?: IContentField<TSharedDimension>;
150
+ shared_miw?: IContentField<TSharedDimension>;
151
+ shared_mih?: IContentField<TSharedDimension>;
152
+ shared_maw?: IContentField<TSharedDimension>;
153
+ shared_mah?: IContentField<TSharedDimension>;
140
154
  }
141
155
 
142
156
  export interface IScrollAreaStyle extends IStyleWithSpacing {
@@ -145,8 +159,7 @@ export interface IScrollAreaStyle extends IStyleWithSpacing {
145
159
  web_scroll_area_type?: IContentField<TMantineScrollAreaType>;
146
160
  web_scroll_area_offset_scrollbars?: IContentField<string>;
147
161
  web_scroll_area_scroll_hide_delay?: IContentField<string>;
148
- web_height?: IContentField<TMantineHeight>;
149
- web_width?: IContentField<TMantineWidth>;
162
+ shared_height?: IContentField<TSharedDimension>;
150
163
  }
151
164
 
152
165
  export interface ICardStyle extends IStyleWithSpacing {
@@ -157,7 +170,9 @@ export interface ICardStyle extends IStyleWithSpacing {
157
170
  img_src?: IContentField<string>;
158
171
  // Cross-platform border (Mantine withBorder / themed border on mobile).
159
172
  shared_border?: IContentField<TSharedBorder>;
160
- web_card_padding?: IContentField<TMantineCardPadding>;
173
+ // NOTE: no web-only card padding — padding is the portable `shared_spacing`
174
+ // (pt/pb/ps/pe), which renders on web AND mobile. The renderer keeps a fixed
175
+ // Mantine inner padding ("md") as the default + Card.Section bleed reference.
161
176
  web_card_shadow?: IContentField<TMantineCardShadow>;
162
177
  shared_radius?: IContentField<TSharedRadius>;}
163
178