@selfhelp/shared 1.14.23 → 1.14.24
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/CHANGELOG.md +37 -0
- package/dist/{common-udJ0O8qC.d.mts → common-qaDIAYS3.d.mts} +5 -4
- package/dist/{common-udJ0O8qC.d.ts → common-qaDIAYS3.d.ts} +5 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +94 -170
- package/dist/index.mjs +94 -167
- package/dist/plugin-sdk/index.d.mts +2 -2
- package/dist/plugin-sdk/index.d.ts +2 -2
- package/dist/plugin-sdk/index.js +90 -91
- package/dist/plugin-sdk/index.mjs +90 -91
- package/dist/registry/index.d.mts +3 -3
- package/dist/registry/index.d.ts +3 -3
- package/dist/registry/index.js +90 -90
- package/dist/registry/index.mjs +90 -90
- package/dist/{styles.registry-CZZwODJY.d.mts → styles.registry-4W0LzmZB.d.mts} +2 -189
- package/dist/{styles.registry-DQKcvIBZ.d.ts → styles.registry-D6xMm5VR.d.ts} +2 -189
- package/dist/theme/index.d.mts +27 -76
- package/dist/theme/index.d.ts +27 -76
- package/dist/theme/index.js +4 -80
- package/dist/theme/index.mjs +4 -77
- package/package.json +1 -1
- package/src/plugin-sdk/define.ts +0 -1
- package/src/registry/__tests__/platform.test.ts +0 -4
- package/src/registry/__tests__/registry.test.ts +0 -2
- package/src/registry/styles.registry.ts +90 -96
- package/src/theme/__tests__/mantineVariant.test.ts +2 -2
- package/src/theme/__tests__/semantic.test.ts +16 -53
- package/src/theme/mantineVariant.ts +3 -3
- package/src/theme/semantic.ts +24 -164
- package/src/theme/tokens.ts +2 -2
- package/src/types/mantine/common.ts +4 -3
- package/src/types/styles/base.ts +1 -1
- package/src/types/styles/composite.ts +0 -2
package/src/theme/semantic.ts
CHANGED
|
@@ -4,8 +4,9 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Shared semantic style mapper — the single source of truth that turns
|
|
7
|
-
* renderer-agnostic CMS values (
|
|
8
|
-
* props. Renderers consume this module instead of duplicating
|
|
7
|
+
* renderer-agnostic CMS values (the unprefixed portable fields) into concrete
|
|
8
|
+
* per-platform props. Renderers consume this module instead of duplicating
|
|
9
|
+
* mapping logic.
|
|
9
10
|
*
|
|
10
11
|
* - Web -> Mantine (`toMantineSemanticProps`)
|
|
11
12
|
* - Mobile -> HeroUI Native (`toHeroUiSemanticProps`)
|
|
@@ -17,14 +18,15 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
17
18
|
* value maps 1:1 to each platform. The backend enforces the same domain
|
|
18
19
|
* (migration `Version20260618195450`).
|
|
19
20
|
* - NO implicit cross-platform fallback. These functions take already-resolved
|
|
20
|
-
*
|
|
21
|
-
* component default is applied by each platform renderer,
|
|
21
|
+
* portable props; the precedence `web_*`/`mobile_*` override -> portable
|
|
22
|
+
* (unprefixed) -> component default is applied by each platform renderer,
|
|
23
|
+
* never here.
|
|
22
24
|
* - Exhaustive enum handling (every switch covers the full domain).
|
|
23
25
|
*
|
|
24
|
-
* Platform-specific props stay separate from these
|
|
26
|
+
* Platform-specific props stay separate from these portable values:
|
|
25
27
|
* - `web_*` Mantine-only fields
|
|
26
28
|
* - `mobile_*` HeroUI/native-only fields
|
|
27
|
-
* -
|
|
29
|
+
* - portable the unprefixed semantic fields mapped here
|
|
28
30
|
*/
|
|
29
31
|
|
|
30
32
|
import { RADIUS_PX, SPACING_PX, type TCanonicalSpacing } from './tokens';
|
|
@@ -37,23 +39,14 @@ export type TSemanticSize = TSharedSize; // 'sm' | 'md' | 'lg'
|
|
|
37
39
|
export type TSemanticSpacing = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
38
40
|
/** Cross-platform radius. `full` = pill; `none` = square. */
|
|
39
41
|
export type TSemanticRadius = TSharedRadius; // 'none' | 'sm' | 'md' | 'lg' | 'full'
|
|
40
|
-
export type TSemanticIntent =
|
|
41
|
-
| 'primary'
|
|
42
|
-
| 'secondary'
|
|
43
|
-
| 'success'
|
|
44
|
-
| 'warning'
|
|
45
|
-
| 'danger'
|
|
46
|
-
| 'neutral';
|
|
47
42
|
export type TSemanticState = 'disabled' | 'loading' | 'invalid' | 'required';
|
|
48
43
|
|
|
49
44
|
/**
|
|
50
45
|
* Cross-platform colour + variant authored in the CMS (`color` /
|
|
51
|
-
* `variant`)
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* live catalog); the mapper maps them onto HeroUI Native for mobile, while the
|
|
56
|
-
* web renderer feeds them straight into Mantine.
|
|
46
|
+
* `variant`), stored as Mantine palette / variant *values* kept verbatim by the
|
|
47
|
+
* catalog. They are the canonical cross-platform appearance fields; the mapper
|
|
48
|
+
* maps them onto HeroUI Native for mobile, while the web renderer feeds them
|
|
49
|
+
* straight into Mantine.
|
|
57
50
|
*/
|
|
58
51
|
export type TSemanticColor = TMantineColor;
|
|
59
52
|
export type TSemanticVariant = TMantineVariant;
|
|
@@ -63,14 +56,6 @@ export const FULL_RADIUS_PX = 9999;
|
|
|
63
56
|
|
|
64
57
|
const SEMANTIC_SIZES: readonly TSemanticSize[] = ['sm', 'md', 'lg'];
|
|
65
58
|
const SEMANTIC_RADII: readonly TSemanticRadius[] = ['none', 'sm', 'md', 'lg', 'full'];
|
|
66
|
-
const SEMANTIC_INTENTS: readonly TSemanticIntent[] = [
|
|
67
|
-
'primary',
|
|
68
|
-
'secondary',
|
|
69
|
-
'success',
|
|
70
|
-
'warning',
|
|
71
|
-
'danger',
|
|
72
|
-
'neutral',
|
|
73
|
-
];
|
|
74
59
|
|
|
75
60
|
/**
|
|
76
61
|
* Renderer-agnostic style values configured in the CMS. Every field is
|
|
@@ -85,12 +70,6 @@ export interface ISharedStyleProps {
|
|
|
85
70
|
color?: TSemanticColor;
|
|
86
71
|
/** Mantine variant authored via `variant` (cross-platform). */
|
|
87
72
|
variant?: TSemanticVariant;
|
|
88
|
-
/**
|
|
89
|
-
* Legacy semantic intent. Kept for back-compat; `shared_intent` is NOT in the
|
|
90
|
-
* live catalog, so real CMS sections drive appearance through `color` /
|
|
91
|
-
* `variant` above. Used as the final fallback in the platform resolvers.
|
|
92
|
-
*/
|
|
93
|
-
intent?: TSemanticIntent;
|
|
94
73
|
/** Active boolean states. Stored as a small set so multiple can apply. */
|
|
95
74
|
states?: readonly TSemanticState[];
|
|
96
75
|
/** Layout: stretch the control to the full width of its container. */
|
|
@@ -99,19 +78,13 @@ export interface ISharedStyleProps {
|
|
|
99
78
|
|
|
100
79
|
// ===== Mantine (web) target shapes =====
|
|
101
80
|
|
|
102
|
-
export type TMantineMappedColor =
|
|
103
|
-
| 'blue'
|
|
104
|
-
| 'gray'
|
|
105
|
-
| 'green'
|
|
106
|
-
| 'yellow'
|
|
107
|
-
| 'red';
|
|
108
|
-
export type TMantineMappedVariant = 'filled' | 'light' | 'outline' | 'default';
|
|
109
|
-
|
|
110
81
|
export interface IMantineResolvedStyle {
|
|
111
82
|
/** Mantine accepts sm|md|lg 1:1 (a subset of its xs..xl scale). */
|
|
112
83
|
size?: TSemanticSize;
|
|
113
|
-
color
|
|
114
|
-
|
|
84
|
+
/** Mantine palette colour, read verbatim from the `color` field. */
|
|
85
|
+
color?: TSemanticColor;
|
|
86
|
+
/** Mantine variant, read verbatim from the `variant` field. */
|
|
87
|
+
variant?: TSemanticVariant;
|
|
115
88
|
/** Mantine `radius` accepts a token or a number; pill => FULL_RADIUS_PX. */
|
|
116
89
|
radius?: TSemanticSize | number;
|
|
117
90
|
/** Margin/padding spacing token (xs..xl); `none` => undefined. */
|
|
@@ -141,9 +114,9 @@ export type THeroUiColor = 'accent' | 'default' | 'success' | 'warning' | 'dange
|
|
|
141
114
|
|
|
142
115
|
export interface IHeroUiResolvedStyle {
|
|
143
116
|
size?: THeroUiSize;
|
|
144
|
-
/**
|
|
117
|
+
/** Button variant derived from the Mantine `variant`/`color`. */
|
|
145
118
|
buttonVariant?: THeroUiButtonVariant;
|
|
146
|
-
/**
|
|
119
|
+
/** Semantic color derived from the Mantine `color` (Chip/Tag/etc). */
|
|
147
120
|
color?: THeroUiColor;
|
|
148
121
|
/** Resolved radius in px (pill => FULL_RADIUS_PX, none => 0). */
|
|
149
122
|
radiusPx?: number;
|
|
@@ -243,109 +216,6 @@ export function mapSpacingToPx(spacing: TSemanticSpacing | undefined): number |
|
|
|
243
216
|
return SPACING_PX[spacing as TCanonicalSpacing];
|
|
244
217
|
}
|
|
245
218
|
|
|
246
|
-
// ===== intent =====
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Map a semantic intent to a Mantine `{ color, variant }` pair.
|
|
250
|
-
* primary -> blue / filled
|
|
251
|
-
* secondary -> gray / light
|
|
252
|
-
* success -> green / filled
|
|
253
|
-
* warning -> yellow / filled
|
|
254
|
-
* danger -> red / filled
|
|
255
|
-
* neutral -> gray / default
|
|
256
|
-
*/
|
|
257
|
-
export function mapIntentToMantine(
|
|
258
|
-
intent: TSemanticIntent | undefined,
|
|
259
|
-
): { color: TMantineMappedColor; variant: TMantineMappedVariant } | undefined {
|
|
260
|
-
if (!intent) return undefined;
|
|
261
|
-
switch (intent) {
|
|
262
|
-
case 'primary':
|
|
263
|
-
return { color: 'blue', variant: 'filled' };
|
|
264
|
-
case 'secondary':
|
|
265
|
-
return { color: 'gray', variant: 'light' };
|
|
266
|
-
case 'success':
|
|
267
|
-
return { color: 'green', variant: 'filled' };
|
|
268
|
-
case 'warning':
|
|
269
|
-
return { color: 'yellow', variant: 'filled' };
|
|
270
|
-
case 'danger':
|
|
271
|
-
return { color: 'red', variant: 'filled' };
|
|
272
|
-
case 'neutral':
|
|
273
|
-
return { color: 'gray', variant: 'default' };
|
|
274
|
-
default:
|
|
275
|
-
return undefined;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Map a semantic intent to a HeroUI Native **Button** variant.
|
|
281
|
-
*
|
|
282
|
-
* HeroUI buttons have no dedicated success/warning variant. Rather than
|
|
283
|
-
* silently collapse them, the dedicated status surfaces use
|
|
284
|
-
* {@link mapIntentToHeroUiColor}; the Button variant maps success/warning to
|
|
285
|
-
* `primary` because that is the closest *prominent* action affordance, and the
|
|
286
|
-
* status color is carried separately. This is an explicit semantic choice, not
|
|
287
|
-
* a clamp that hides an unsupported size/scale value.
|
|
288
|
-
* primary -> primary
|
|
289
|
-
* secondary -> secondary
|
|
290
|
-
* success -> primary (status color carried by mapIntentToHeroUiColor)
|
|
291
|
-
* warning -> primary (status color carried by mapIntentToHeroUiColor)
|
|
292
|
-
* danger -> danger
|
|
293
|
-
* neutral -> secondary
|
|
294
|
-
*/
|
|
295
|
-
export function mapIntentToHeroUiButtonVariant(
|
|
296
|
-
intent: TSemanticIntent | undefined,
|
|
297
|
-
): THeroUiButtonVariant | undefined {
|
|
298
|
-
if (!intent) return undefined;
|
|
299
|
-
switch (intent) {
|
|
300
|
-
case 'primary':
|
|
301
|
-
return 'primary';
|
|
302
|
-
case 'secondary':
|
|
303
|
-
return 'secondary';
|
|
304
|
-
case 'success':
|
|
305
|
-
return 'primary';
|
|
306
|
-
case 'warning':
|
|
307
|
-
return 'primary';
|
|
308
|
-
case 'danger':
|
|
309
|
-
return 'danger';
|
|
310
|
-
case 'neutral':
|
|
311
|
-
return 'secondary';
|
|
312
|
-
default:
|
|
313
|
-
return undefined;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Map a semantic intent to a HeroUI Native semantic color (Chip/Tag/
|
|
319
|
-
* status surfaces, which DO support success/warning).
|
|
320
|
-
* primary -> accent
|
|
321
|
-
* secondary -> default
|
|
322
|
-
* success -> success
|
|
323
|
-
* warning -> warning
|
|
324
|
-
* danger -> danger
|
|
325
|
-
* neutral -> default
|
|
326
|
-
*/
|
|
327
|
-
export function mapIntentToHeroUiColor(
|
|
328
|
-
intent: TSemanticIntent | undefined,
|
|
329
|
-
): THeroUiColor | undefined {
|
|
330
|
-
if (!intent) return undefined;
|
|
331
|
-
switch (intent) {
|
|
332
|
-
case 'primary':
|
|
333
|
-
return 'accent';
|
|
334
|
-
case 'secondary':
|
|
335
|
-
return 'default';
|
|
336
|
-
case 'success':
|
|
337
|
-
return 'success';
|
|
338
|
-
case 'warning':
|
|
339
|
-
return 'warning';
|
|
340
|
-
case 'danger':
|
|
341
|
-
return 'danger';
|
|
342
|
-
case 'neutral':
|
|
343
|
-
return 'default';
|
|
344
|
-
default:
|
|
345
|
-
return undefined;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
219
|
// ===== color / variant (the REAL cross-platform appearance fields) =====
|
|
350
220
|
|
|
351
221
|
/**
|
|
@@ -625,13 +495,6 @@ export function resolveSharedStyleProps(fields: Record<string, unknown>): IShare
|
|
|
625
495
|
resolved.variant = variant as TSemanticVariant;
|
|
626
496
|
}
|
|
627
497
|
|
|
628
|
-
// Legacy: `shared_intent` is not in the live catalog, but keep reading it so
|
|
629
|
-
// any forward-compat seed still resolves. Domain-checked like size/radius.
|
|
630
|
-
const intent = readString(fields.shared_intent);
|
|
631
|
-
if (intent !== undefined && (SEMANTIC_INTENTS as readonly string[]).includes(intent)) {
|
|
632
|
-
resolved.intent = intent as TSemanticIntent;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
498
|
const fullWidth = readBool(fields.full_width);
|
|
636
499
|
if (fullWidth !== undefined) {
|
|
637
500
|
resolved.fullWidth = fullWidth;
|
|
@@ -644,12 +507,11 @@ export function resolveSharedStyleProps(fields: Record<string, unknown>): IShare
|
|
|
644
507
|
|
|
645
508
|
/** Resolve shared props into Mantine (web) props. */
|
|
646
509
|
export function toMantineSemanticProps(props: ISharedStyleProps): IMantineResolvedStyle {
|
|
647
|
-
const intent = mapIntentToMantine(props.intent);
|
|
648
510
|
const spacing = props.spacing && props.spacing !== 'none' ? props.spacing : undefined;
|
|
649
511
|
return {
|
|
650
512
|
size: mapSizeToMantine(props.size),
|
|
651
|
-
color:
|
|
652
|
-
variant:
|
|
513
|
+
color: props.color,
|
|
514
|
+
variant: props.variant,
|
|
653
515
|
radius: mapRadiusToMantine(props.radius),
|
|
654
516
|
spacing,
|
|
655
517
|
disabled: hasState(props.states, 'disabled') || undefined,
|
|
@@ -666,16 +528,14 @@ export function toMantineSemanticProps(props: ISharedStyleProps): IMantineResolv
|
|
|
666
528
|
* Appearance precedence (mirrors the web renderer, which reads the same CMS
|
|
667
529
|
* fields straight into Mantine):
|
|
668
530
|
* 1. `variant` (Mantine variant) mapped onto the HeroUI button vocab;
|
|
669
|
-
* 2. else `color` (Mantine palette) mapped onto a button variant
|
|
670
|
-
*
|
|
671
|
-
* The semantic `color` is resolved from `color` first, then `intent`.
|
|
531
|
+
* 2. else `color` (Mantine palette) mapped onto a button variant.
|
|
532
|
+
* The semantic `color` is resolved from `color`.
|
|
672
533
|
*/
|
|
673
534
|
export function toHeroUiSemanticProps(props: ISharedStyleProps): IHeroUiResolvedStyle {
|
|
674
535
|
const buttonVariant =
|
|
675
536
|
mapMantineVariantToHeroUiButtonVariant(props.variant) ??
|
|
676
|
-
mapMantineColorToHeroUiButtonVariant(props.color)
|
|
677
|
-
|
|
678
|
-
const color = mapMantineColorToHeroUiColor(props.color) ?? mapIntentToHeroUiColor(props.intent);
|
|
537
|
+
mapMantineColorToHeroUiButtonVariant(props.color);
|
|
538
|
+
const color = mapMantineColorToHeroUiColor(props.color);
|
|
679
539
|
return {
|
|
680
540
|
size: mapSizeToHeroUi(props.size),
|
|
681
541
|
buttonVariant,
|
package/src/theme/tokens.ts
CHANGED
|
@@ -91,8 +91,8 @@ export const CONTAINER_SIZE_PX: Record<TMantineSize, number> = {
|
|
|
91
91
|
/**
|
|
92
92
|
* Mantine palette base colors (color-6 from each scale). Each renderer
|
|
93
93
|
* maps these to its own theme tokens. For HeroUI Native we feed these
|
|
94
|
-
* into the theme builder so `
|
|
95
|
-
* same Mantine-blue look on mobile.
|
|
94
|
+
* into the theme builder so the portable `color: 'blue'` field resolves
|
|
95
|
+
* to the same Mantine-blue look on mobile.
|
|
96
96
|
*/
|
|
97
97
|
export const COLOR_PALETTE: Record<TCanonicalColor, string> = {
|
|
98
98
|
gray: '#868e96',
|
|
@@ -15,14 +15,15 @@ export type TMantineRadius = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | string;
|
|
|
15
15
|
export type TMantineSpacing = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'none' | string;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* Cross-platform
|
|
18
|
+
* Cross-platform semantic scales — the TRUE common denominator
|
|
19
19
|
* between Mantine (web) and HeroUI Native / React Native (mobile). HeroUI Native
|
|
20
|
-
* only exposes `sm | md | lg`, so portable `size` / `radius` fields
|
|
20
|
+
* only exposes `sm | md | lg`, so the portable unprefixed `size` / `radius` fields
|
|
21
21
|
* use these narrowed scales instead of the full Mantine `xs..xl` range. The
|
|
22
22
|
* backend enforces the same domain (migration `Version20260618195450`), and the
|
|
23
23
|
* semantic mapper (`theme/semantic.ts`) maps these 1:1 without clamping.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
25
|
+
* Genuinely web-specific size/radius fields (typed `TMantineSize` / `TMantineRadius`)
|
|
26
|
+
* keep the full Mantine range.
|
|
26
27
|
*/
|
|
27
28
|
export type TSharedSize = 'sm' | 'md' | 'lg';
|
|
28
29
|
export type TSharedRadius = 'none' | 'sm' | 'md' | 'lg' | 'full';
|
package/src/types/styles/base.ts
CHANGED
|
@@ -65,6 +65,6 @@ export interface IBaseStyle {
|
|
|
65
65
|
|
|
66
66
|
/** Styles that support the unified spacing field. */
|
|
67
67
|
export interface IStyleWithSpacing extends IBaseStyle {
|
|
68
|
-
/** Portable box-model spacing (margin + padding). Backend field `spacing`;
|
|
68
|
+
/** Portable box-model spacing (margin + padding). Backend field `spacing`; every spacing-capable style uses this single unified field. */
|
|
69
69
|
spacing?: IContentField<string>;
|
|
70
70
|
}
|
|
@@ -6,7 +6,6 @@ import type { IBaseStyle, IContentField, IStyleWithSpacing } from './base';
|
|
|
6
6
|
import type {
|
|
7
7
|
TMantineColor,
|
|
8
8
|
TMantineRadius,
|
|
9
|
-
TMantineSpacing,
|
|
10
9
|
TMantineOrientation,
|
|
11
10
|
TMantineAccordionVariant,
|
|
12
11
|
TMantineTabsVariant,
|
|
@@ -109,7 +108,6 @@ export interface ITimelineItemStyle extends IBaseStyle {
|
|
|
109
108
|
export interface IListStyle extends IStyleWithSpacing {
|
|
110
109
|
style_name: 'list';
|
|
111
110
|
web_list_type?: IContentField<TMantineListType>;
|
|
112
|
-
web_spacing?: IContentField<TMantineSpacing>;
|
|
113
111
|
size?: IContentField<TSharedSize>; web_list_list_style_type?: IContentField<TMantineListStyleType>;
|
|
114
112
|
web_list_with_padding?: IContentField<TMantineListWithPadding>;
|
|
115
113
|
web_list_center?: IContentField<TMantineListCenter>;
|