@selfhelp/shared 1.8.0 → 1.11.0
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 +67 -0
- package/dist/{common-B96dASgu.d.mts → common-CJSHQL1E.d.mts} +13 -1
- package/dist/{common-B96dASgu.d.ts → common-CJSHQL1E.d.ts} +13 -1
- package/dist/index.d.mts +136 -44
- package/dist/index.d.ts +136 -44
- package/dist/index.js +395 -8
- package/dist/index.mjs +371 -8
- package/dist/plugin-sdk/index.d.mts +2 -2
- package/dist/plugin-sdk/index.d.ts +2 -2
- package/dist/plugin-sdk/index.js +10 -1
- package/dist/plugin-sdk/index.mjs +10 -1
- package/dist/registry/index.d.mts +42 -4
- package/dist/registry/index.d.ts +42 -4
- package/dist/registry/index.js +56 -3
- package/dist/registry/index.mjs +48 -2
- package/dist/{styles.registry-ClluRYkN.d.ts → styles.registry-BV1iF7k-.d.ts} +678 -461
- package/dist/{styles.registry-nl8uzvMN.d.mts → styles.registry-DkoT-FmN.d.mts} +678 -461
- package/dist/theme/index.d.mts +225 -4
- package/dist/theme/index.d.ts +225 -4
- package/dist/theme/index.js +343 -9
- package/dist/theme/index.mjs +325 -8
- package/dist/theme/tailwind.d.mts +2 -2
- package/dist/theme/tailwind.d.ts +2 -2
- package/package.json +1 -1
- package/src/registry/__tests__/platform.test.ts +187 -0
- package/src/registry/index.ts +73 -0
- package/src/registry/styles.registry.ts +60 -0
- package/src/theme/__tests__/mantineVariant.test.ts +87 -0
- package/src/theme/__tests__/semantic.test.ts +231 -0
- package/src/theme/index.ts +2 -0
- package/src/theme/mantineVariant.ts +145 -0
- package/src/theme/semantic.ts +472 -0
- package/src/theme/tailwind.ts +2 -2
- package/src/theme/tokens.ts +2 -2
- package/src/types/__tests__/mobile-adapters.test.ts +80 -0
- package/src/types/index.ts +1 -0
- package/src/types/mantine/common.ts +13 -0
- package/src/types/mobile-adapters.ts +144 -0
- package/src/types/styles/auth.ts +11 -11
- package/src/types/styles/base.ts +4 -4
- package/src/types/styles/composite.ts +59 -45
- package/src/types/styles/error.ts +24 -13
- package/src/types/styles/forms.ts +184 -184
- package/src/types/styles/interactive.ts +81 -76
- package/src/types/styles/layout.ts +103 -85
- package/src/types/styles/media.ts +20 -20
- package/src/types/styles/typography.ts +39 -39
- package/src/types/styles/unknown.ts +20 -2
- package/src/utils/spacing.ts +1 -1
package/dist/theme/index.mjs
CHANGED
|
@@ -93,23 +93,23 @@ function radiusToPx(token) {
|
|
|
93
93
|
function colorToHex(name, shade = 6) {
|
|
94
94
|
if (!name) return void 0;
|
|
95
95
|
if (name.startsWith("#") || name.startsWith("rgb") || name.startsWith("hsl")) return name;
|
|
96
|
-
const
|
|
97
|
-
if (!
|
|
98
|
-
return
|
|
96
|
+
const scale2 = COLOR_SCALES[name];
|
|
97
|
+
if (!scale2) return name;
|
|
98
|
+
return scale2[Math.max(0, Math.min(9, shade))];
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
// src/theme/tailwind.ts
|
|
102
102
|
var px = (n) => n === void 0 ? "0px" : `${n}px`;
|
|
103
|
-
var colorScaleToTailwind = (
|
|
103
|
+
var colorScaleToTailwind = (scale2) => {
|
|
104
104
|
const out = {};
|
|
105
|
-
|
|
105
|
+
scale2.forEach((value, idx) => {
|
|
106
106
|
out[String(idx)] = value;
|
|
107
107
|
});
|
|
108
108
|
return out;
|
|
109
109
|
};
|
|
110
110
|
var colors = {};
|
|
111
|
-
for (const [name,
|
|
112
|
-
colors[name] = colorScaleToTailwind(
|
|
111
|
+
for (const [name, scale2] of Object.entries(COLOR_SCALES)) {
|
|
112
|
+
colors[name] = colorScaleToTailwind(scale2);
|
|
113
113
|
}
|
|
114
114
|
var spacing = {
|
|
115
115
|
none: px(SPACING_PX.none),
|
|
@@ -144,19 +144,336 @@ var sharedTailwindPreset = {
|
|
|
144
144
|
extend: sharedTailwindExtend
|
|
145
145
|
}
|
|
146
146
|
};
|
|
147
|
+
|
|
148
|
+
// src/theme/semantic.ts
|
|
149
|
+
var FULL_RADIUS_PX = 9999;
|
|
150
|
+
var SEMANTIC_SIZES = ["sm", "md", "lg"];
|
|
151
|
+
var SEMANTIC_RADII = ["none", "sm", "md", "lg", "full"];
|
|
152
|
+
var SEMANTIC_INTENTS = [
|
|
153
|
+
"primary",
|
|
154
|
+
"secondary",
|
|
155
|
+
"success",
|
|
156
|
+
"warning",
|
|
157
|
+
"danger",
|
|
158
|
+
"neutral"
|
|
159
|
+
];
|
|
160
|
+
function mapSizeToMantine(size) {
|
|
161
|
+
return size;
|
|
162
|
+
}
|
|
163
|
+
function mapSizeToHeroUi(size) {
|
|
164
|
+
if (!size) return void 0;
|
|
165
|
+
switch (size) {
|
|
166
|
+
case "sm":
|
|
167
|
+
return "sm";
|
|
168
|
+
case "md":
|
|
169
|
+
return "md";
|
|
170
|
+
case "lg":
|
|
171
|
+
return "lg";
|
|
172
|
+
default:
|
|
173
|
+
return void 0;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function mapRadiusToPx(radius) {
|
|
177
|
+
if (!radius) return void 0;
|
|
178
|
+
switch (radius) {
|
|
179
|
+
case "none":
|
|
180
|
+
return 0;
|
|
181
|
+
case "full":
|
|
182
|
+
return FULL_RADIUS_PX;
|
|
183
|
+
case "sm":
|
|
184
|
+
return RADIUS_PX.sm;
|
|
185
|
+
case "md":
|
|
186
|
+
return RADIUS_PX.md;
|
|
187
|
+
case "lg":
|
|
188
|
+
return RADIUS_PX.lg;
|
|
189
|
+
default:
|
|
190
|
+
return void 0;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function mapRadiusToMantine(radius) {
|
|
194
|
+
if (!radius) return void 0;
|
|
195
|
+
switch (radius) {
|
|
196
|
+
case "none":
|
|
197
|
+
return 0;
|
|
198
|
+
case "full":
|
|
199
|
+
return FULL_RADIUS_PX;
|
|
200
|
+
case "sm":
|
|
201
|
+
return "sm";
|
|
202
|
+
case "md":
|
|
203
|
+
return "md";
|
|
204
|
+
case "lg":
|
|
205
|
+
return "lg";
|
|
206
|
+
default:
|
|
207
|
+
return void 0;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function mapSpacingToPx(spacing2) {
|
|
211
|
+
if (!spacing2) return void 0;
|
|
212
|
+
if (spacing2 === "none") return 0;
|
|
213
|
+
return SPACING_PX[spacing2];
|
|
214
|
+
}
|
|
215
|
+
function mapIntentToMantine(intent) {
|
|
216
|
+
if (!intent) return void 0;
|
|
217
|
+
switch (intent) {
|
|
218
|
+
case "primary":
|
|
219
|
+
return { color: "blue", variant: "filled" };
|
|
220
|
+
case "secondary":
|
|
221
|
+
return { color: "gray", variant: "light" };
|
|
222
|
+
case "success":
|
|
223
|
+
return { color: "green", variant: "filled" };
|
|
224
|
+
case "warning":
|
|
225
|
+
return { color: "yellow", variant: "filled" };
|
|
226
|
+
case "danger":
|
|
227
|
+
return { color: "red", variant: "filled" };
|
|
228
|
+
case "neutral":
|
|
229
|
+
return { color: "gray", variant: "default" };
|
|
230
|
+
default:
|
|
231
|
+
return void 0;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function mapIntentToHeroUiButtonVariant(intent) {
|
|
235
|
+
if (!intent) return void 0;
|
|
236
|
+
switch (intent) {
|
|
237
|
+
case "primary":
|
|
238
|
+
return "primary";
|
|
239
|
+
case "secondary":
|
|
240
|
+
return "secondary";
|
|
241
|
+
case "success":
|
|
242
|
+
return "primary";
|
|
243
|
+
case "warning":
|
|
244
|
+
return "primary";
|
|
245
|
+
case "danger":
|
|
246
|
+
return "danger";
|
|
247
|
+
case "neutral":
|
|
248
|
+
return "secondary";
|
|
249
|
+
default:
|
|
250
|
+
return void 0;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function mapIntentToHeroUiColor(intent) {
|
|
254
|
+
if (!intent) return void 0;
|
|
255
|
+
switch (intent) {
|
|
256
|
+
case "primary":
|
|
257
|
+
return "accent";
|
|
258
|
+
case "secondary":
|
|
259
|
+
return "default";
|
|
260
|
+
case "success":
|
|
261
|
+
return "success";
|
|
262
|
+
case "warning":
|
|
263
|
+
return "warning";
|
|
264
|
+
case "danger":
|
|
265
|
+
return "danger";
|
|
266
|
+
case "neutral":
|
|
267
|
+
return "default";
|
|
268
|
+
default:
|
|
269
|
+
return void 0;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function hasState(states, state) {
|
|
273
|
+
return !!states && states.includes(state);
|
|
274
|
+
}
|
|
275
|
+
function readString(value) {
|
|
276
|
+
if (typeof value === "string" && value !== "") return value;
|
|
277
|
+
return void 0;
|
|
278
|
+
}
|
|
279
|
+
function readBool(value) {
|
|
280
|
+
if (typeof value === "boolean") return value;
|
|
281
|
+
if (value === "1" || value === 1) return true;
|
|
282
|
+
if (value === "0" || value === 0) return false;
|
|
283
|
+
return void 0;
|
|
284
|
+
}
|
|
285
|
+
function resolveSharedStyleProps(fields) {
|
|
286
|
+
const resolved = {};
|
|
287
|
+
const size = readString(fields.shared_size);
|
|
288
|
+
if (size !== void 0 && SEMANTIC_SIZES.includes(size)) {
|
|
289
|
+
resolved.size = size;
|
|
290
|
+
}
|
|
291
|
+
const radius = readString(fields.shared_radius);
|
|
292
|
+
if (radius !== void 0 && SEMANTIC_RADII.includes(radius)) {
|
|
293
|
+
resolved.radius = radius;
|
|
294
|
+
}
|
|
295
|
+
const intent = readString(fields.shared_intent);
|
|
296
|
+
if (intent !== void 0 && SEMANTIC_INTENTS.includes(intent)) {
|
|
297
|
+
resolved.intent = intent;
|
|
298
|
+
}
|
|
299
|
+
const fullWidth = readBool(fields.shared_full_width);
|
|
300
|
+
if (fullWidth !== void 0) {
|
|
301
|
+
resolved.fullWidth = fullWidth;
|
|
302
|
+
}
|
|
303
|
+
return resolved;
|
|
304
|
+
}
|
|
305
|
+
function toMantineSemanticProps(props) {
|
|
306
|
+
const intent = mapIntentToMantine(props.intent);
|
|
307
|
+
const spacing2 = props.spacing && props.spacing !== "none" ? props.spacing : void 0;
|
|
308
|
+
return {
|
|
309
|
+
size: mapSizeToMantine(props.size),
|
|
310
|
+
color: intent?.color,
|
|
311
|
+
variant: intent?.variant,
|
|
312
|
+
radius: mapRadiusToMantine(props.radius),
|
|
313
|
+
spacing: spacing2,
|
|
314
|
+
disabled: hasState(props.states, "disabled") || void 0,
|
|
315
|
+
loading: hasState(props.states, "loading") || void 0,
|
|
316
|
+
error: hasState(props.states, "invalid") || void 0,
|
|
317
|
+
required: hasState(props.states, "required") || void 0,
|
|
318
|
+
fullWidth: props.fullWidth || void 0
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function toHeroUiSemanticProps(props) {
|
|
322
|
+
return {
|
|
323
|
+
size: mapSizeToHeroUi(props.size),
|
|
324
|
+
buttonVariant: mapIntentToHeroUiButtonVariant(props.intent),
|
|
325
|
+
color: mapIntentToHeroUiColor(props.intent),
|
|
326
|
+
radiusPx: mapRadiusToPx(props.radius),
|
|
327
|
+
spacingPx: mapSpacingToPx(props.spacing),
|
|
328
|
+
isDisabled: hasState(props.states, "disabled") || void 0,
|
|
329
|
+
isLoading: hasState(props.states, "loading") || void 0,
|
|
330
|
+
isInvalid: hasState(props.states, "invalid") || void 0,
|
|
331
|
+
isRequired: hasState(props.states, "required") || void 0,
|
|
332
|
+
fullWidth: props.fullWidth || void 0
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function toReactNativeSemanticStyle(props, theme) {
|
|
336
|
+
const style = {};
|
|
337
|
+
if (props.radius !== void 0) {
|
|
338
|
+
const borderRadius2 = resolveRadiusPx(props.radius, theme);
|
|
339
|
+
if (borderRadius2 !== void 0) style.borderRadius = borderRadius2;
|
|
340
|
+
}
|
|
341
|
+
if (props.spacing !== void 0) {
|
|
342
|
+
const padding = resolveSpacingPx(props.spacing, theme);
|
|
343
|
+
if (padding !== void 0) style.padding = padding;
|
|
344
|
+
}
|
|
345
|
+
if (props.fullWidth) {
|
|
346
|
+
style.alignSelf = "stretch";
|
|
347
|
+
style.width = "100%";
|
|
348
|
+
}
|
|
349
|
+
return style;
|
|
350
|
+
}
|
|
351
|
+
function resolveRadiusPx(radius, theme) {
|
|
352
|
+
if (radius === "none") return 0;
|
|
353
|
+
if (radius === "full") return FULL_RADIUS_PX;
|
|
354
|
+
return theme?.radiusPx?.[radius] ?? mapRadiusToPx(radius);
|
|
355
|
+
}
|
|
356
|
+
function resolveSpacingPx(spacing2, theme) {
|
|
357
|
+
if (spacing2 === "none") return 0;
|
|
358
|
+
return theme?.spacingPx?.[spacing2] ?? mapSpacingToPx(spacing2);
|
|
359
|
+
}
|
|
360
|
+
function resolveSharedStyle(props) {
|
|
361
|
+
return {
|
|
362
|
+
web: toMantineSemanticProps(props),
|
|
363
|
+
mobile: toHeroUiSemanticProps(props)
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
var resolveSharedStyleForWeb = toMantineSemanticProps;
|
|
367
|
+
var resolveSharedStyleForMobile = toHeroUiSemanticProps;
|
|
368
|
+
|
|
369
|
+
// src/theme/mantineVariant.ts
|
|
370
|
+
var TRANSPARENT = "transparent";
|
|
371
|
+
function scale(color) {
|
|
372
|
+
if (!color) return COLOR_SCALES.blue;
|
|
373
|
+
return COLOR_SCALES[color] ?? COLOR_SCALES.blue;
|
|
374
|
+
}
|
|
375
|
+
function resolveMantineVariant(variant, color) {
|
|
376
|
+
const palette = scale(color);
|
|
377
|
+
const accent = COLOR_PALETTE[color] ?? palette[6] ?? "#228be6";
|
|
378
|
+
const v = variant ?? "filled";
|
|
379
|
+
switch (v) {
|
|
380
|
+
case "light":
|
|
381
|
+
return {
|
|
382
|
+
background: palette[0],
|
|
383
|
+
foreground: palette[8],
|
|
384
|
+
border: TRANSPARENT,
|
|
385
|
+
borderWidth: 0,
|
|
386
|
+
pressedBackground: palette[1],
|
|
387
|
+
accent
|
|
388
|
+
};
|
|
389
|
+
case "outline":
|
|
390
|
+
return {
|
|
391
|
+
background: TRANSPARENT,
|
|
392
|
+
foreground: palette[7],
|
|
393
|
+
border: palette[6],
|
|
394
|
+
borderWidth: 1,
|
|
395
|
+
pressedBackground: palette[0],
|
|
396
|
+
accent
|
|
397
|
+
};
|
|
398
|
+
case "default":
|
|
399
|
+
return {
|
|
400
|
+
background: "#ffffff",
|
|
401
|
+
foreground: "#212529",
|
|
402
|
+
border: "#dee2e6",
|
|
403
|
+
borderWidth: 1,
|
|
404
|
+
pressedBackground: "#f1f3f5",
|
|
405
|
+
accent
|
|
406
|
+
};
|
|
407
|
+
case "subtle":
|
|
408
|
+
return {
|
|
409
|
+
background: TRANSPARENT,
|
|
410
|
+
foreground: palette[7],
|
|
411
|
+
border: TRANSPARENT,
|
|
412
|
+
borderWidth: 0,
|
|
413
|
+
pressedBackground: palette[0],
|
|
414
|
+
accent
|
|
415
|
+
};
|
|
416
|
+
case "transparent":
|
|
417
|
+
return {
|
|
418
|
+
background: TRANSPARENT,
|
|
419
|
+
foreground: palette[7],
|
|
420
|
+
border: TRANSPARENT,
|
|
421
|
+
borderWidth: 0,
|
|
422
|
+
pressedBackground: TRANSPARENT,
|
|
423
|
+
accent
|
|
424
|
+
};
|
|
425
|
+
case "dot":
|
|
426
|
+
return {
|
|
427
|
+
background: TRANSPARENT,
|
|
428
|
+
foreground: palette[7],
|
|
429
|
+
border: "#dee2e6",
|
|
430
|
+
borderWidth: 1,
|
|
431
|
+
pressedBackground: "#f8f9fa",
|
|
432
|
+
accent
|
|
433
|
+
};
|
|
434
|
+
case "filled":
|
|
435
|
+
case "gradient":
|
|
436
|
+
default:
|
|
437
|
+
return {
|
|
438
|
+
background: accent,
|
|
439
|
+
foreground: "#ffffff",
|
|
440
|
+
border: TRANSPARENT,
|
|
441
|
+
borderWidth: 0,
|
|
442
|
+
pressedBackground: palette[7] ?? accent,
|
|
443
|
+
accent
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
}
|
|
147
447
|
export {
|
|
148
448
|
COLOR_PALETTE,
|
|
149
449
|
COLOR_SCALES,
|
|
150
450
|
CONTAINER_SIZE_PX,
|
|
151
451
|
FONT_SIZE_PX,
|
|
452
|
+
FULL_RADIUS_PX,
|
|
152
453
|
LINE_HEIGHT,
|
|
153
454
|
RADIUS_PX,
|
|
154
455
|
SPACING_PX,
|
|
155
456
|
SPACING_TO_TAILWIND,
|
|
156
457
|
colorToHex,
|
|
458
|
+
mapIntentToHeroUiButtonVariant,
|
|
459
|
+
mapIntentToHeroUiColor,
|
|
460
|
+
mapIntentToMantine,
|
|
461
|
+
mapRadiusToMantine,
|
|
462
|
+
mapRadiusToPx,
|
|
463
|
+
mapSizeToHeroUi,
|
|
464
|
+
mapSizeToMantine,
|
|
465
|
+
mapSpacingToPx,
|
|
157
466
|
radiusToPx,
|
|
467
|
+
resolveMantineVariant,
|
|
468
|
+
resolveSharedStyle,
|
|
469
|
+
resolveSharedStyleForMobile,
|
|
470
|
+
resolveSharedStyleForWeb,
|
|
471
|
+
resolveSharedStyleProps,
|
|
158
472
|
sharedTailwindExtend,
|
|
159
473
|
sharedTailwindPreset,
|
|
160
474
|
sizeToFontPx,
|
|
161
|
-
spacingToPx
|
|
475
|
+
spacingToPx,
|
|
476
|
+
toHeroUiSemanticProps,
|
|
477
|
+
toMantineSemanticProps,
|
|
478
|
+
toReactNativeSemanticStyle
|
|
162
479
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared Tailwind preset extended by both the web frontend (Tailwind v4)
|
|
3
3
|
* and the mobile app (Uniwind v4 inside HeroUI Native). Anchors the same
|
|
4
|
-
* scale values that drive `
|
|
5
|
-
* `
|
|
4
|
+
* scale values that drive `shared_size`, `shared_radius`,
|
|
5
|
+
* `shared_spacing`, and the color palette so a class like `p-md` or
|
|
6
6
|
* `text-blue-6` resolves identically on web and mobile.
|
|
7
7
|
*/
|
|
8
8
|
/**
|
package/dist/theme/tailwind.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared Tailwind preset extended by both the web frontend (Tailwind v4)
|
|
3
3
|
* and the mobile app (Uniwind v4 inside HeroUI Native). Anchors the same
|
|
4
|
-
* scale values that drive `
|
|
5
|
-
* `
|
|
4
|
+
* scale values that drive `shared_size`, `shared_radius`,
|
|
5
|
+
* `shared_spacing`, and the color palette so a class like `p-md` or
|
|
6
6
|
* `text-blue-6` resolves identically on web and mobile.
|
|
7
7
|
*/
|
|
8
8
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Shared TypeScript package for SelfHelp web frontend and mobile app: style registry, types, API contracts, Mantine theme tokens, condition + interpolation engines, CMS class allow-list.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
6
|
+
import {
|
|
7
|
+
BASE_STYLE_REGISTRY,
|
|
8
|
+
extendStyleRegistry,
|
|
9
|
+
getStylePlacement,
|
|
10
|
+
getStylePlatforms,
|
|
11
|
+
isStyleAllowedOnPage,
|
|
12
|
+
isStylePlacementAllowed,
|
|
13
|
+
isStyleSupportedOnPlatform,
|
|
14
|
+
setToStylePlatform,
|
|
15
|
+
stylePlatformToSet,
|
|
16
|
+
_resetPluginStyleRegistry,
|
|
17
|
+
type IStyleRegistryEntry,
|
|
18
|
+
} from '../index';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Render-target contract. Established styles default to BOTH targets so nothing
|
|
22
|
+
* stops rendering; a style that declares a single target must be skipped on the
|
|
23
|
+
* other platform's dispatcher and filtered by page target. (Milestone one ships
|
|
24
|
+
* no single-target *core* style — the eight system/data styles all render on
|
|
25
|
+
* both — so single-target behaviour is asserted through plugin entries, which is
|
|
26
|
+
* exactly how plugin mobile-only/web-only styles behave at runtime.)
|
|
27
|
+
*/
|
|
28
|
+
describe('style render-target targeting', () => {
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
_resetPluginStyleRegistry();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('defaults registered styles without a render target to both', () => {
|
|
34
|
+
expect(getStylePlatforms('container')).toEqual(['web', 'mobile']);
|
|
35
|
+
expect(isStyleSupportedOnPlatform('container', 'web')).toBe(true);
|
|
36
|
+
expect(isStyleSupportedOnPlatform('container', 'mobile')).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('defaults the eight established system/data styles to both', () => {
|
|
40
|
+
for (const name of [
|
|
41
|
+
'no-access', 'missing', 'not-found', 'version',
|
|
42
|
+
'ref-container', 'data-container', 'show-user-input', 'timeline-item',
|
|
43
|
+
]) {
|
|
44
|
+
expect(getStylePlatforms(name)).toEqual(['web', 'mobile']);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('defaults unknown styles to both (safe fallback)', () => {
|
|
49
|
+
expect(getStylePlatforms('qa-not-a-real-style')).toEqual(['web', 'mobile']);
|
|
50
|
+
expect(isStyleSupportedOnPlatform('qa-not-a-real-style', 'mobile')).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('honours an explicit mobile-only render target on a (plugin) style entry', () => {
|
|
54
|
+
const mobileOnly: IStyleRegistryEntry = {
|
|
55
|
+
description: 'QA mobile-only plugin style',
|
|
56
|
+
category: 'plugin',
|
|
57
|
+
frontendOnly: true,
|
|
58
|
+
canHaveChildren: false,
|
|
59
|
+
platforms: ['mobile'],
|
|
60
|
+
};
|
|
61
|
+
extendStyleRegistry({ 'qa-fab': mobileOnly }, { pluginId: 'qa-shp-platform' });
|
|
62
|
+
|
|
63
|
+
expect(getStylePlatforms('qa-fab')).toEqual(['mobile']);
|
|
64
|
+
expect(isStyleSupportedOnPlatform('qa-fab', 'mobile')).toBe(true);
|
|
65
|
+
expect(isStyleSupportedOnPlatform('qa-fab', 'web')).toBe(false);
|
|
66
|
+
// Hidden on web pages, shown on mobile / both pages.
|
|
67
|
+
expect(isStyleAllowedOnPage('qa-fab', 'web')).toBe(false);
|
|
68
|
+
expect(isStyleAllowedOnPage('qa-fab', 'mobile')).toBe(true);
|
|
69
|
+
expect(isStyleAllowedOnPage('qa-fab', 'both')).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('converts between TStylePlatform and the concrete set', () => {
|
|
73
|
+
expect(stylePlatformToSet('both')).toEqual(['web', 'mobile']);
|
|
74
|
+
expect(stylePlatformToSet('mobile')).toEqual(['mobile']);
|
|
75
|
+
expect(setToStylePlatform(['web', 'mobile'])).toBe('both');
|
|
76
|
+
expect(setToStylePlatform(['mobile'])).toBe('mobile');
|
|
77
|
+
expect(setToStylePlatform(['web'])).toBe('web');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('filters by page target for the add-section picker', () => {
|
|
81
|
+
const webOnly: IStyleRegistryEntry = {
|
|
82
|
+
description: 'QA web-only plugin style',
|
|
83
|
+
category: 'plugin',
|
|
84
|
+
frontendOnly: true,
|
|
85
|
+
canHaveChildren: false,
|
|
86
|
+
platforms: ['web'],
|
|
87
|
+
};
|
|
88
|
+
extendStyleRegistry({ 'qa-web-widget': webOnly }, { pluginId: 'qa-shp-platform' });
|
|
89
|
+
|
|
90
|
+
// A `both` page accepts everything.
|
|
91
|
+
expect(isStyleAllowedOnPage('qa-web-widget', 'both')).toBe(true);
|
|
92
|
+
// A mobile page hides web-only styles.
|
|
93
|
+
expect(isStyleAllowedOnPage('qa-web-widget', 'mobile')).toBe(false);
|
|
94
|
+
// A web page accepts both-target core styles.
|
|
95
|
+
expect(isStyleAllowedOnPage('container', 'web')).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Placement contract. The CMS picker uses this to hide root-only styles when
|
|
101
|
+
* adding a child and container-only styles when adding at page root. No core
|
|
102
|
+
* style declares a non-`any` placement in milestone one, so the rule is pinned
|
|
103
|
+
* through plugin entries.
|
|
104
|
+
*/
|
|
105
|
+
describe('style placement targeting', () => {
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
_resetPluginStyleRegistry();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('defaults styles without a placement to "any" (root or container)', () => {
|
|
111
|
+
expect(getStylePlacement('container')).toBe('any');
|
|
112
|
+
expect(isStylePlacementAllowed('container', true)).toBe(true);
|
|
113
|
+
expect(isStylePlacementAllowed('container', false)).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('defaults unknown styles to "any"', () => {
|
|
117
|
+
expect(getStylePlacement('qa-not-a-real-style')).toBe('any');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('honours rootOnly on a (plugin) style entry', () => {
|
|
121
|
+
const rootOnly: IStyleRegistryEntry = {
|
|
122
|
+
description: 'QA root-only plugin style',
|
|
123
|
+
category: 'plugin',
|
|
124
|
+
frontendOnly: true,
|
|
125
|
+
canHaveChildren: false,
|
|
126
|
+
placement: 'rootOnly',
|
|
127
|
+
};
|
|
128
|
+
extendStyleRegistry({ 'qa-overlay': rootOnly }, { pluginId: 'qa-shp-platform' });
|
|
129
|
+
|
|
130
|
+
expect(getStylePlacement('qa-overlay')).toBe('rootOnly');
|
|
131
|
+
expect(isStylePlacementAllowed('qa-overlay', true)).toBe(true);
|
|
132
|
+
expect(isStylePlacementAllowed('qa-overlay', false)).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('honours containerOnly on a (plugin) style entry', () => {
|
|
136
|
+
const childOnly: IStyleRegistryEntry = {
|
|
137
|
+
description: 'QA container-only plugin style',
|
|
138
|
+
category: 'plugin',
|
|
139
|
+
frontendOnly: true,
|
|
140
|
+
canHaveChildren: false,
|
|
141
|
+
placement: 'containerOnly',
|
|
142
|
+
};
|
|
143
|
+
extendStyleRegistry({ 'qa-panel-item': childOnly }, { pluginId: 'qa-shp-platform' });
|
|
144
|
+
|
|
145
|
+
expect(getStylePlacement('qa-panel-item')).toBe('containerOnly');
|
|
146
|
+
expect(isStylePlacementAllowed('qa-panel-item', true)).toBe(false);
|
|
147
|
+
expect(isStylePlacementAllowed('qa-panel-item', false)).toBe(true);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Catalog parity (mobile rendering plan, milestone one). The core registry must
|
|
153
|
+
* be the established 90-style backend catalog: the eight previously-missing
|
|
154
|
+
* system/data/reference styles are present, and the sixteen deferred
|
|
155
|
+
* speculative styles are absent. Drift here means the shared contract and the
|
|
156
|
+
* backend catalog have diverged.
|
|
157
|
+
*/
|
|
158
|
+
describe('core catalog parity (90 established styles)', () => {
|
|
159
|
+
const CORE_NAMES = Object.keys(BASE_STYLE_REGISTRY);
|
|
160
|
+
|
|
161
|
+
const PREVIOUSLY_MISSING = [
|
|
162
|
+
'data-container', 'timeline-item', 'version', 'no-access',
|
|
163
|
+
'missing', 'not-found', 'ref-container', 'show-user-input',
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
const DEFERRED_SPECULATIVE = [
|
|
167
|
+
'dialog', 'popover', 'menu', 'menu-item', 'bottom-sheet', 'skeleton',
|
|
168
|
+
'skeleton-group', 'spinner', 'toast', 'tag-group', 'tag', 'input-group',
|
|
169
|
+
'input-otp', 'search-field', 'fab-button', 'biometric-login-button',
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
it('contains exactly the 90 established core styles', () => {
|
|
173
|
+
expect(CORE_NAMES).toHaveLength(90);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('includes every previously-missing established style', () => {
|
|
177
|
+
for (const name of PREVIOUSLY_MISSING) {
|
|
178
|
+
expect(CORE_NAMES, `missing established style: ${name}`).toContain(name);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('excludes every deferred speculative style', () => {
|
|
183
|
+
for (const name of DEFERRED_SPECULATIVE) {
|
|
184
|
+
expect(CORE_NAMES, `deferred style should be absent: ${name}`).not.toContain(name);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
package/src/registry/index.ts
CHANGED
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
getPluginStyleRegistry,
|
|
10
10
|
type IPluginStyleRegistryEntry,
|
|
11
11
|
type IStyleRegistryEntry,
|
|
12
|
+
type TConcretePlatform,
|
|
13
|
+
type TStylePlacement,
|
|
14
|
+
type TStylePlatform,
|
|
12
15
|
} from './styles.registry';
|
|
13
16
|
|
|
14
17
|
export * from './styles.registry';
|
|
@@ -92,3 +95,73 @@ export function getStylePluginId(name: string): string | undefined {
|
|
|
92
95
|
return plugin?.pluginId;
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
/** Default platform set when a style does not declare one (both targets). */
|
|
99
|
+
const DEFAULT_PLATFORMS: readonly TConcretePlatform[] = ['web', 'mobile'];
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Resolve the render targets a style supports. Unknown / unregistered
|
|
103
|
+
* styles and styles that omit `platforms` default to **both** targets,
|
|
104
|
+
* so existing styles keep rendering everywhere.
|
|
105
|
+
*
|
|
106
|
+
* The renderer should prefer an explicit per-section `platform` value
|
|
107
|
+
* from the backend payload when present; this registry lookup is the
|
|
108
|
+
* compile-time source of truth for core styles.
|
|
109
|
+
*/
|
|
110
|
+
export function getStylePlatforms(name: string): readonly TConcretePlatform[] {
|
|
111
|
+
const entry = getRegistryEntryAny(name);
|
|
112
|
+
return entry?.platforms ?? DEFAULT_PLATFORMS;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Whether a style targets the given concrete platform. Drives the
|
|
117
|
+
* "silently skip styles not meant for this platform" behaviour in both
|
|
118
|
+
* the web and mobile dispatchers.
|
|
119
|
+
*/
|
|
120
|
+
export function isStyleSupportedOnPlatform(name: string, platform: TConcretePlatform): boolean {
|
|
121
|
+
return getStylePlatforms(name).includes(platform);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Expand a CMS `TStylePlatform` value into the concrete platform set. */
|
|
125
|
+
export function stylePlatformToSet(platform: TStylePlatform): readonly TConcretePlatform[] {
|
|
126
|
+
return platform === 'both' ? DEFAULT_PLATFORMS : [platform];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Collapse a concrete platform set back into the CMS `TStylePlatform` value. */
|
|
130
|
+
export function setToStylePlatform(set: readonly TConcretePlatform[]): TStylePlatform {
|
|
131
|
+
const web = set.includes('web');
|
|
132
|
+
const mobile = set.includes('mobile');
|
|
133
|
+
if (web && mobile) return 'both';
|
|
134
|
+
return mobile ? 'mobile' : 'web';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Whether a style is allowed on a page that targets `pagePlatform`.
|
|
139
|
+
* A `both` page accepts every style; a single-platform page accepts only
|
|
140
|
+
* styles that also support that platform. Used by the CMS add-section
|
|
141
|
+
* picker to filter the catalog by page target.
|
|
142
|
+
*/
|
|
143
|
+
export function isStyleAllowedOnPage(name: string, pagePlatform: TStylePlatform): boolean {
|
|
144
|
+
if (pagePlatform === 'both') return true;
|
|
145
|
+
return isStyleSupportedOnPlatform(name, pagePlatform);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Resolve a style's placement rule. Unknown / unregistered styles and styles
|
|
150
|
+
* that omit `placement` default to `any`.
|
|
151
|
+
*/
|
|
152
|
+
export function getStylePlacement(name: string): TStylePlacement {
|
|
153
|
+
return getRegistryEntryAny(name)?.placement ?? 'any';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Whether a style may be placed at the given tree location. `isRoot` is true
|
|
158
|
+
* when adding directly to a page (no parent section). `rootOnly` styles are
|
|
159
|
+
* hidden inside containers; `containerOnly` styles are hidden at page root.
|
|
160
|
+
*/
|
|
161
|
+
export function isStylePlacementAllowed(name: string, isRoot: boolean): boolean {
|
|
162
|
+
const placement = getStylePlacement(name);
|
|
163
|
+
if (placement === 'rootOnly') return isRoot;
|
|
164
|
+
if (placement === 'containerOnly') return !isRoot;
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
|