@selfhelp/shared 1.14.13 → 1.14.15
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 +64 -0
- package/dist/index.d.mts +75 -3
- package/dist/index.d.ts +75 -3
- package/dist/index.js +149 -0
- package/dist/index.mjs +146 -0
- package/dist/plugin-sdk/index.d.mts +1 -1
- package/dist/plugin-sdk/index.d.ts +1 -1
- package/dist/registry/index.d.mts +2 -2
- package/dist/registry/index.d.ts +2 -2
- package/dist/{styles.registry-CA6p55GE.d.mts → styles.registry-Bxm4jsbO.d.mts} +33 -5
- package/dist/{styles.registry-DACrC1dz.d.ts → styles.registry-QFmOGJUL.d.ts} +33 -5
- package/package.json +1 -1
- package/src/content/__tests__/inlineFormat.test.ts +116 -0
- package/src/content/index.ts +5 -0
- package/src/content/inlineFormat.ts +232 -0
- package/src/index.ts +1 -0
- package/src/types/styles/interactive.ts +10 -1
- package/src/types/styles/media.ts +21 -4
- package/src/types/styles/typography.ts +5 -2
package/dist/index.mjs
CHANGED
|
@@ -1242,6 +1242,149 @@ function resolveAssetSources(sources, baseUrl) {
|
|
|
1242
1242
|
return sources.map((s) => ({ ...s, src: resolveAssetUrl(s.src, baseUrl) }));
|
|
1243
1243
|
}
|
|
1244
1244
|
|
|
1245
|
+
// src/content/inlineFormat.ts
|
|
1246
|
+
var HTML_ENTITIES = {
|
|
1247
|
+
"&": "&",
|
|
1248
|
+
"<": "<",
|
|
1249
|
+
">": ">",
|
|
1250
|
+
""": '"',
|
|
1251
|
+
"'": "'",
|
|
1252
|
+
"'": "'",
|
|
1253
|
+
" ": " ",
|
|
1254
|
+
"/": "/",
|
|
1255
|
+
"/": "/"
|
|
1256
|
+
};
|
|
1257
|
+
function decodeEntities(value) {
|
|
1258
|
+
if (!value.includes("&")) return value;
|
|
1259
|
+
return value.replace(/&[a-zA-Z#0-9]+;/g, (entity) => HTML_ENTITIES[entity.toLowerCase()] ?? entity);
|
|
1260
|
+
}
|
|
1261
|
+
function looksLikeJson(trimmed) {
|
|
1262
|
+
const first = trimmed[0];
|
|
1263
|
+
if (first !== "{" && first !== "[") return false;
|
|
1264
|
+
try {
|
|
1265
|
+
JSON.parse(trimmed);
|
|
1266
|
+
return true;
|
|
1267
|
+
} catch {
|
|
1268
|
+
return false;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
var SEPARATOR_TAGS = /* @__PURE__ */ new Set([
|
|
1272
|
+
"br",
|
|
1273
|
+
"p",
|
|
1274
|
+
"div",
|
|
1275
|
+
"li",
|
|
1276
|
+
"ul",
|
|
1277
|
+
"ol",
|
|
1278
|
+
"h1",
|
|
1279
|
+
"h2",
|
|
1280
|
+
"h3",
|
|
1281
|
+
"h4",
|
|
1282
|
+
"h5",
|
|
1283
|
+
"h6",
|
|
1284
|
+
"blockquote",
|
|
1285
|
+
"tr",
|
|
1286
|
+
"section",
|
|
1287
|
+
"article",
|
|
1288
|
+
"header",
|
|
1289
|
+
"footer",
|
|
1290
|
+
"pre"
|
|
1291
|
+
]);
|
|
1292
|
+
var INLINE_TAG_RE = /<(?:b|strong|i|em|u|a)\b/i;
|
|
1293
|
+
var TAG_RE = /<\/?([a-z][a-z0-9]*)\b([^>]*)>/gi;
|
|
1294
|
+
var HREF_RE = /href\s*=\s*(?:"([^"]*)"|'([^']*)')/i;
|
|
1295
|
+
function extractHref(attrs) {
|
|
1296
|
+
const match = HREF_RE.exec(attrs);
|
|
1297
|
+
return (match?.[1] ?? match?.[2] ?? "").trim();
|
|
1298
|
+
}
|
|
1299
|
+
function formatKey(node) {
|
|
1300
|
+
return `${node.bold ? 1 : 0}|${node.italic ? 1 : 0}|${node.underline ? 1 : 0}|${node.href ?? ""}`;
|
|
1301
|
+
}
|
|
1302
|
+
function parseInlineRich(value) {
|
|
1303
|
+
if (value == null) return [];
|
|
1304
|
+
const str = String(value);
|
|
1305
|
+
if (str === "") return [];
|
|
1306
|
+
const trimmed = str.trim();
|
|
1307
|
+
if (looksLikeJson(trimmed)) return [{ text: str }];
|
|
1308
|
+
if (!str.includes("<")) {
|
|
1309
|
+
const text = decodeEntities(str);
|
|
1310
|
+
return text === "" ? [] : [{ text }];
|
|
1311
|
+
}
|
|
1312
|
+
const raw = [];
|
|
1313
|
+
let bold = 0;
|
|
1314
|
+
let italic = 0;
|
|
1315
|
+
let underline = 0;
|
|
1316
|
+
const hrefStack = [];
|
|
1317
|
+
const pushText = (segment) => {
|
|
1318
|
+
if (segment === "") return;
|
|
1319
|
+
raw.push({
|
|
1320
|
+
text: segment,
|
|
1321
|
+
...bold > 0 ? { bold: true } : {},
|
|
1322
|
+
...italic > 0 ? { italic: true } : {},
|
|
1323
|
+
...underline > 0 ? { underline: true } : {},
|
|
1324
|
+
...hrefStack.length > 0 ? { href: hrefStack[hrefStack.length - 1] } : {}
|
|
1325
|
+
});
|
|
1326
|
+
};
|
|
1327
|
+
let lastIndex = 0;
|
|
1328
|
+
let match;
|
|
1329
|
+
TAG_RE.lastIndex = 0;
|
|
1330
|
+
while ((match = TAG_RE.exec(str)) !== null) {
|
|
1331
|
+
pushText(str.slice(lastIndex, match.index));
|
|
1332
|
+
lastIndex = TAG_RE.lastIndex;
|
|
1333
|
+
const isClose = match[0].charAt(1) === "/";
|
|
1334
|
+
const tag = match[1].toLowerCase();
|
|
1335
|
+
const attrs = match[2] ?? "";
|
|
1336
|
+
if (tag === "b" || tag === "strong") {
|
|
1337
|
+
bold = isClose ? Math.max(0, bold - 1) : bold + 1;
|
|
1338
|
+
} else if (tag === "i" || tag === "em") {
|
|
1339
|
+
italic = isClose ? Math.max(0, italic - 1) : italic + 1;
|
|
1340
|
+
} else if (tag === "u") {
|
|
1341
|
+
underline = isClose ? Math.max(0, underline - 1) : underline + 1;
|
|
1342
|
+
} else if (tag === "a") {
|
|
1343
|
+
if (isClose) {
|
|
1344
|
+
hrefStack.pop();
|
|
1345
|
+
} else {
|
|
1346
|
+
hrefStack.push(extractHref(attrs));
|
|
1347
|
+
}
|
|
1348
|
+
} else if (SEPARATOR_TAGS.has(tag)) {
|
|
1349
|
+
pushText(" ");
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
pushText(str.slice(lastIndex));
|
|
1353
|
+
const merged = [];
|
|
1354
|
+
for (const node of raw) {
|
|
1355
|
+
const prev = merged[merged.length - 1];
|
|
1356
|
+
if (prev && formatKey(prev) === formatKey(node)) {
|
|
1357
|
+
prev.text += node.text;
|
|
1358
|
+
} else {
|
|
1359
|
+
merged.push({ ...node });
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
for (const node of merged) {
|
|
1363
|
+
node.text = decodeEntities(node.text).replace(/\s+/g, " ");
|
|
1364
|
+
}
|
|
1365
|
+
if (merged.length > 0) {
|
|
1366
|
+
merged[0].text = merged[0].text.replace(/^\s+/, "");
|
|
1367
|
+
merged[merged.length - 1].text = merged[merged.length - 1].text.replace(/\s+$/, "");
|
|
1368
|
+
}
|
|
1369
|
+
return merged.filter((node) => node.text !== "");
|
|
1370
|
+
}
|
|
1371
|
+
function hasInlineFormatting(value) {
|
|
1372
|
+
if (value == null) return false;
|
|
1373
|
+
const str = String(value);
|
|
1374
|
+
if (!str.includes("<")) return false;
|
|
1375
|
+
if (looksLikeJson(str.trim())) return false;
|
|
1376
|
+
return INLINE_TAG_RE.test(str);
|
|
1377
|
+
}
|
|
1378
|
+
function stripHtmlToText(value) {
|
|
1379
|
+
if (!value || typeof value !== "string") return value ?? "";
|
|
1380
|
+
const trimmed = value.trim();
|
|
1381
|
+
if (looksLikeJson(trimmed)) return value;
|
|
1382
|
+
if (!/[<&]/.test(value)) return value;
|
|
1383
|
+
let out = value.replace(/<br\s*\/?>/gi, " ").replace(/<\/(p|div|li|h[1-6]|tr|blockquote)>/gi, " ").replace(/<[^>]+>/g, "");
|
|
1384
|
+
out = out.replace(/&[a-zA-Z#0-9]+;/g, (entity) => HTML_ENTITIES[entity.toLowerCase()] ?? entity);
|
|
1385
|
+
return out.replace(/\s+/g, " ").trim();
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1245
1388
|
// src/utils/spacing.ts
|
|
1246
1389
|
var ALLOWED_KEYS = ["mt", "mb", "ms", "me", "pt", "pb", "ps", "pe"];
|
|
1247
1390
|
function parseSpacing(raw) {
|
|
@@ -1352,6 +1495,7 @@ export {
|
|
|
1352
1495
|
getStylePlatforms,
|
|
1353
1496
|
getStylePluginId,
|
|
1354
1497
|
gridSpanToReactNativeColumn,
|
|
1498
|
+
hasInlineFormatting,
|
|
1355
1499
|
isKnownStyleName,
|
|
1356
1500
|
isRegisteredStyleName,
|
|
1357
1501
|
isStyleAllowedOnPage,
|
|
@@ -1373,6 +1517,7 @@ export {
|
|
|
1373
1517
|
mapSpacingToPx,
|
|
1374
1518
|
parseDimensionToReactNative,
|
|
1375
1519
|
parseDimensionToWeb,
|
|
1520
|
+
parseInlineRich,
|
|
1376
1521
|
parseSpacing,
|
|
1377
1522
|
radiusToPx,
|
|
1378
1523
|
replaceCalcedValues,
|
|
@@ -1389,6 +1534,7 @@ export {
|
|
|
1389
1534
|
sizeToFontPx,
|
|
1390
1535
|
spacingToClasses,
|
|
1391
1536
|
spacingToPx,
|
|
1537
|
+
stripHtmlToText,
|
|
1392
1538
|
stylePlatformToSet,
|
|
1393
1539
|
toHeroUiSemanticProps,
|
|
1394
1540
|
toMantineSemanticProps,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCapability, e as IPluginManifestCompatibility, f as IPluginManifestConflict, g as IPluginManifestDataAccess, h as IPluginManifestDependency, i as IPluginManifestExternalHost, j as IPluginManifestFeatureFlag, k as IPluginManifestHealth, l as IPluginManifestLookupExtension, m as IPluginManifestMobile, n as IPluginManifestPermission, o as IPluginManifestRealtimeTopic, p as IPluginManifestScheduledJob, q as IPluginManifestSecurity, r as IPluginManifestStyle, s as IPluginManifestTrustLevel } from '../manifest-C8sBTLJb.mjs';
|
|
2
|
-
import { I as IStyleRegistryEntry } from '../styles.registry-
|
|
2
|
+
import { I as IStyleRegistryEntry } from '../styles.registry-Bxm4jsbO.mjs';
|
|
3
3
|
import '../common-DMm4kymA.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCapability, e as IPluginManifestCompatibility, f as IPluginManifestConflict, g as IPluginManifestDataAccess, h as IPluginManifestDependency, i as IPluginManifestExternalHost, j as IPluginManifestFeatureFlag, k as IPluginManifestHealth, l as IPluginManifestLookupExtension, m as IPluginManifestMobile, n as IPluginManifestPermission, o as IPluginManifestRealtimeTopic, p as IPluginManifestScheduledJob, q as IPluginManifestSecurity, r as IPluginManifestStyle, s as IPluginManifestTrustLevel } from '../manifest-C8sBTLJb.js';
|
|
2
|
-
import { I as IStyleRegistryEntry } from '../styles.registry-
|
|
2
|
+
import { I as IStyleRegistryEntry } from '../styles.registry-QFmOGJUL.js';
|
|
3
3
|
import '../common-DMm4kymA.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TStyleName, I as IStyleRegistryEntry, a as IPluginStyleRegistryEntry, b as TStylePlacement, c as TConcretePlatform, d as TStylePlatform } from '../styles.registry-
|
|
2
|
-
export { B as BASE_STYLE_REGISTRY, S as STYLE_REGISTRY, e as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, f as _resetPluginStyleRegistry, g as extendStyleRegistry, h as getMergedStyleRegistry, i as getPluginStyleRegistry } from '../styles.registry-
|
|
1
|
+
import { T as TStyleName, I as IStyleRegistryEntry, a as IPluginStyleRegistryEntry, b as TStylePlacement, c as TConcretePlatform, d as TStylePlatform } from '../styles.registry-Bxm4jsbO.mjs';
|
|
2
|
+
export { B as BASE_STYLE_REGISTRY, S as STYLE_REGISTRY, e as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, f as _resetPluginStyleRegistry, g as extendStyleRegistry, h as getMergedStyleRegistry, i as getPluginStyleRegistry } from '../styles.registry-Bxm4jsbO.mjs';
|
|
3
3
|
import '../common-DMm4kymA.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/registry/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TStyleName, I as IStyleRegistryEntry, a as IPluginStyleRegistryEntry, b as TStylePlacement, c as TConcretePlatform, d as TStylePlatform } from '../styles.registry-
|
|
2
|
-
export { B as BASE_STYLE_REGISTRY, S as STYLE_REGISTRY, e as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, f as _resetPluginStyleRegistry, g as extendStyleRegistry, h as getMergedStyleRegistry, i as getPluginStyleRegistry } from '../styles.registry-
|
|
1
|
+
import { T as TStyleName, I as IStyleRegistryEntry, a as IPluginStyleRegistryEntry, b as TStylePlacement, c as TConcretePlatform, d as TStylePlatform } from '../styles.registry-QFmOGJUL.js';
|
|
2
|
+
export { B as BASE_STYLE_REGISTRY, S as STYLE_REGISTRY, e as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, f as _resetPluginStyleRegistry, g as extendStyleRegistry, h as getMergedStyleRegistry, i as getPluginStyleRegistry } from '../styles.registry-QFmOGJUL.js';
|
|
3
3
|
import '../common-DMm4kymA.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -393,7 +393,8 @@ interface IHighlightStyle extends IStyleWithSpacing {
|
|
|
393
393
|
}
|
|
394
394
|
interface IBlockquoteStyle extends IStyleWithSpacing {
|
|
395
395
|
style_name: 'blockquote';
|
|
396
|
-
content
|
|
396
|
+
/** Quote body. Dedicated markdown-inline field (not the generic `content`) so authors can bold/italic/link inside the quote without affecting the `code` style. */
|
|
397
|
+
blockquote_content?: IContentField<string>;
|
|
397
398
|
cite?: IContentField<string>;
|
|
398
399
|
web_left_icon?: IContentField<string>;
|
|
399
400
|
web_icon_size?: IContentField<TMantineIconSize>;
|
|
@@ -425,6 +426,8 @@ interface ISpoilerStyle extends IStyleWithSpacing {
|
|
|
425
426
|
web_height?: IContentField<TMantineSpoilerMaxHeight>;
|
|
426
427
|
spoiler_show_label?: IContentField<string>;
|
|
427
428
|
spoiler_hide_label?: IContentField<string>;
|
|
429
|
+
/** Color of the show/hide control link. */
|
|
430
|
+
shared_color?: IContentField<TMantineColor>;
|
|
428
431
|
}
|
|
429
432
|
|
|
430
433
|
type TMantineImageFit = 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
@@ -440,21 +443,38 @@ interface IImageStyle extends IStyleWithSpacing {
|
|
|
440
443
|
web_width?: IContentField<TMantineWidth>;
|
|
441
444
|
web_height?: IContentField<TMantineHeight>;
|
|
442
445
|
shared_radius?: IContentField<TMantineRadius>;
|
|
446
|
+
/** Image shown when the main source fails to load (Mantine Image fallbackSrc). */
|
|
447
|
+
fallback_src?: IContentField<string>;
|
|
443
448
|
}
|
|
444
|
-
interface IVideoStyle extends
|
|
449
|
+
interface IVideoStyle extends IStyleWithSpacing {
|
|
445
450
|
style_name: 'video';
|
|
446
451
|
is_fluid?: IContentField<string>;
|
|
447
452
|
alt?: IContentField<string>;
|
|
448
|
-
|
|
453
|
+
video_src?: IContentField<string>;
|
|
454
|
+
/** Poster image shown before playback. */
|
|
455
|
+
poster_src?: IContentField<string>;
|
|
456
|
+
/** Cross-platform playback toggles ('0' | '1'). */
|
|
457
|
+
has_controls?: IContentField<string>;
|
|
458
|
+
media_loop?: IContentField<string>;
|
|
459
|
+
media_autoplay?: IContentField<string>;
|
|
460
|
+
media_muted?: IContentField<string>;
|
|
449
461
|
}
|
|
450
|
-
interface IAudioStyle extends
|
|
462
|
+
interface IAudioStyle extends IStyleWithSpacing {
|
|
451
463
|
style_name: 'audio';
|
|
464
|
+
alt?: IContentField<string>;
|
|
452
465
|
sources?: IContentField<unknown[]>;
|
|
466
|
+
/** Cross-platform playback toggles ('0' | '1'). */
|
|
467
|
+
has_controls?: IContentField<string>;
|
|
468
|
+
media_loop?: IContentField<string>;
|
|
469
|
+
media_autoplay?: IContentField<string>;
|
|
453
470
|
}
|
|
454
471
|
interface IFigureStyle extends IBaseStyle {
|
|
455
472
|
style_name: 'figure';
|
|
456
473
|
caption_title?: IContentField<string>;
|
|
457
474
|
caption?: IContentField<string>;
|
|
475
|
+
/** Optional built-in image so a figure needs no child image section. */
|
|
476
|
+
img_src?: IContentField<string>;
|
|
477
|
+
alt?: IContentField<string>;
|
|
458
478
|
}
|
|
459
479
|
interface ICarouselStyle extends IStyleWithSpacing {
|
|
460
480
|
style_name: 'carousel';
|
|
@@ -481,6 +501,8 @@ interface ICarouselStyle extends IStyleWithSpacing {
|
|
|
481
501
|
web_carousel_embla_options?: IContentField<string>;
|
|
482
502
|
}
|
|
483
503
|
|
|
504
|
+
/** Mantine `Anchor` `underline` behaviour. */
|
|
505
|
+
type TMantineAnchorUnderline = 'always' | 'hover' | 'never';
|
|
484
506
|
interface IButtonStyle extends IStyleWithSpacing {
|
|
485
507
|
style_name: 'button';
|
|
486
508
|
shared_variant?: IContentField<TMantineVariant>;
|
|
@@ -508,6 +530,10 @@ interface ILinkStyle extends IStyleWithSpacing {
|
|
|
508
530
|
label?: IContentField<string>;
|
|
509
531
|
url?: IContentField<string>;
|
|
510
532
|
open_in_new_tab?: IContentField<string>;
|
|
533
|
+
shared_color?: IContentField<TMantineColor>;
|
|
534
|
+
web_link_underline?: IContentField<TMantineAnchorUnderline>;
|
|
535
|
+
web_left_icon?: IContentField<string>;
|
|
536
|
+
web_right_icon?: IContentField<string>;
|
|
511
537
|
}
|
|
512
538
|
interface IActionIconStyle extends IStyleWithSpacing {
|
|
513
539
|
style_name: 'action-icon';
|
|
@@ -521,6 +547,8 @@ interface IActionIconStyle extends IStyleWithSpacing {
|
|
|
521
547
|
page_keyword?: IContentField<string>;
|
|
522
548
|
open_in_new_tab?: IContentField<string>;
|
|
523
549
|
disabled?: IContentField<string>;
|
|
550
|
+
/** Accessible name for the icon-only control (screen readers). */
|
|
551
|
+
aria_label?: IContentField<string>;
|
|
524
552
|
}
|
|
525
553
|
interface IAlertStyle extends IStyleWithSpacing {
|
|
526
554
|
style_name: 'alert';
|
|
@@ -2517,4 +2545,4 @@ declare function getPluginStyleRegistry(): Record<string, IPluginStyleRegistryEn
|
|
|
2517
2545
|
*/
|
|
2518
2546
|
declare function _resetPluginStyleRegistry(): void;
|
|
2519
2547
|
|
|
2520
|
-
export { type IGridStyle as $, type ICenterStyle as A, BASE_STYLE_REGISTRY as B, type ICheckboxStyle as C, type IChipStyle as D, type ICodeStyle as E, type IColorInputStyle as F, type IColorPickerStyle as G, type IComboboxStyle as H, type IStyleRegistryEntry as I, type IContainerStyle as J, type IDataContainerStyle as K, type IDatePickerStyle as L, type IDividerStyle as M, type IEntryListStyle as N, type IEntryRecordDeleteStyle as O, type IEntryRecordStyle as P, type IFieldsetStyle as Q, type IFigureStyle as R, STYLE_REGISTRY as S, type TStyleName as T, type IFileInputStyle as U, type IFlexStyle as V, type IFormLogStyle as W, type IFormRecordStyle as X, type IFormStyle as Y, type IGridColumnStyle as Z, type _AssertRegistryMatchesStyleName as _, type IPluginStyleRegistryEntry as a, type
|
|
2548
|
+
export { type IGridStyle as $, type ICenterStyle as A, BASE_STYLE_REGISTRY as B, type ICheckboxStyle as C, type IChipStyle as D, type ICodeStyle as E, type IColorInputStyle as F, type IColorPickerStyle as G, type IComboboxStyle as H, type IStyleRegistryEntry as I, type IContainerStyle as J, type IDataContainerStyle as K, type IDatePickerStyle as L, type IDividerStyle as M, type IEntryListStyle as N, type IEntryRecordDeleteStyle as O, type IEntryRecordStyle as P, type IFieldsetStyle as Q, type IFigureStyle as R, STYLE_REGISTRY as S, type TStyleName as T, type IFileInputStyle as U, type IFlexStyle as V, type IFormLogStyle as W, type IFormRecordStyle as X, type IFormStyle as Y, type IGridColumnStyle as Z, type _AssertRegistryMatchesStyleName as _, type IPluginStyleRegistryEntry as a, type TMantineCardShadow as a$, type IGroupStyle as a0, type IHighlightStyle as a1, type IHtmlTagStyle as a2, type IImageStyle as a3, type IIndicatorStyle as a4, type IInputStyle as a5, type IKbdStyle as a6, type ILinkStyle as a7, type IListItemStyle as a8, type IListStyle as a9, type ISpaceStyle as aA, type ISpoilerStyle as aB, type IStackStyle as aC, type IStyleWithSpacing as aD, type ISwitchStyle as aE, type ITabStyle as aF, type ITabsStyle as aG, type ITextInputStyle as aH, type ITextStyle as aI, type ITextareaStyle as aJ, type IThemeIconStyle as aK, type ITimelineItemStyle as aL, type ITimelineStyle as aM, type ITitleStyle as aN, type ITwoFactorAuthStyle as aO, type ITypographyStyle as aP, type IUnknownStyle as aQ, type IValidateStyle as aR, type IVersionStyle as aS, type IVideoStyle as aT, type TMantineAccordionChevronPosition as aU, type TMantineAccordionDisableChevronRotation as aV, type TMantineAccordionLoop as aW, type TMantineAccordionMultiple as aX, type TMantineAnchorUnderline as aY, type TMantineBorder as aZ, type TMantineCardPadding as a_, type ILoginStyle as aa, type ILoopStyle as ab, type IMissingStyle as ac, type INoAccessStyle as ad, type INotFoundStyle as ae, type INotificationStyle as af, type INumberInputStyle as ag, type IPaperStyle as ah, type IProfileStyle as ai, type IProgressRootStyle as aj, type IProgressSectionStyle as ak, type IProgressStyle as al, type IRadioStyle as am, type IRangeSliderStyle as an, type IRatingStyle as ao, type IRefContainerStyle as ap, type IRegisterStyle as aq, type IResetPasswordStyle as ar, type IRichTextEditorStyle as as, type IScrollAreaStyle as at, type ISegmentedControlStyle as au, type ISelectStyle as av, type IShowUserInputEntry as aw, type IShowUserInputStyle as ax, type ISimpleGridStyle as ay, type ISliderStyle as az, type TStylePlacement as b, type TMantineCols as b0, type TMantineDividerVariant as b1, type TMantineGap as b2, type TMantineGridOffset as b3, type TMantineGridOrder as b4, type TMantineHeight as b5, type TMantineIconSize as b6, type TMantineImageFit as b7, type TMantineLineClamp as b8, type TMantineListCenter as b9, type TSharedBorder as bA, type TSharedCols as bB, type TSharedDimension as bC, type TSharedDividerLabelPosition as bD, type TSharedDividerVariant as bE, type TSharedLabelPosition as bF, type TStyle as bG, type TMantineListStyleType as ba, type TMantineListType as bb, type TMantineListWithPadding as bc, type TMantinePaperShadow as bd, type TMantineProgressTransition as be, type TMantineScrollAreaSize as bf, type TMantineScrollAreaType as bg, type TMantineTextAlign as bh, type TMantineTextDecoration as bi, type TMantineTextFontStyle as bj, type TMantineTextFontWeight as bk, type TMantineTextInherit as bl, type TMantineTextInputVariant as bm, type TMantineTextSpan as bn, type TMantineTextTransform as bo, type TMantineTextTruncate as bp, type TMantineTextVariant as bq, type TMantineTextareaAutosize as br, type TMantineTextareaResize as bs, type TMantineTextareaVariant as bt, type TMantineTimelineAlign as bu, type TMantineTitleLineClamp as bv, type TMantineTitleTextWrap as bw, type TMantineTranslatable as bx, type TMantineUseInputWrapper as by, type TMantineWidth as bz, type TConcretePlatform as c, type TStylePlatform as d, type TStyleRegistryKey as e, _resetPluginStyleRegistry as f, extendStyleRegistry as g, getMergedStyleRegistry as h, getPluginStyleRegistry as i, type IContentField as j, type IAccordionItemStyle as k, type IAccordionStyle as l, type IActionIconStyle as m, type IAlertStyle as n, type IAspectRatioStyle as o, type IAudioStyle as p, type IAvatarStyle as q, type IBackgroundImageStyle as r, type IBadgeStyle as s, type IBaseStyle as t, type IBlockquoteStyle as u, type IBoxStyle as v, type IButtonStyle as w, type ICardSegmentStyle as x, type ICardStyle as y, type ICarouselStyle as z };
|
|
@@ -393,7 +393,8 @@ interface IHighlightStyle extends IStyleWithSpacing {
|
|
|
393
393
|
}
|
|
394
394
|
interface IBlockquoteStyle extends IStyleWithSpacing {
|
|
395
395
|
style_name: 'blockquote';
|
|
396
|
-
content
|
|
396
|
+
/** Quote body. Dedicated markdown-inline field (not the generic `content`) so authors can bold/italic/link inside the quote without affecting the `code` style. */
|
|
397
|
+
blockquote_content?: IContentField<string>;
|
|
397
398
|
cite?: IContentField<string>;
|
|
398
399
|
web_left_icon?: IContentField<string>;
|
|
399
400
|
web_icon_size?: IContentField<TMantineIconSize>;
|
|
@@ -425,6 +426,8 @@ interface ISpoilerStyle extends IStyleWithSpacing {
|
|
|
425
426
|
web_height?: IContentField<TMantineSpoilerMaxHeight>;
|
|
426
427
|
spoiler_show_label?: IContentField<string>;
|
|
427
428
|
spoiler_hide_label?: IContentField<string>;
|
|
429
|
+
/** Color of the show/hide control link. */
|
|
430
|
+
shared_color?: IContentField<TMantineColor>;
|
|
428
431
|
}
|
|
429
432
|
|
|
430
433
|
type TMantineImageFit = 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
@@ -440,21 +443,38 @@ interface IImageStyle extends IStyleWithSpacing {
|
|
|
440
443
|
web_width?: IContentField<TMantineWidth>;
|
|
441
444
|
web_height?: IContentField<TMantineHeight>;
|
|
442
445
|
shared_radius?: IContentField<TMantineRadius>;
|
|
446
|
+
/** Image shown when the main source fails to load (Mantine Image fallbackSrc). */
|
|
447
|
+
fallback_src?: IContentField<string>;
|
|
443
448
|
}
|
|
444
|
-
interface IVideoStyle extends
|
|
449
|
+
interface IVideoStyle extends IStyleWithSpacing {
|
|
445
450
|
style_name: 'video';
|
|
446
451
|
is_fluid?: IContentField<string>;
|
|
447
452
|
alt?: IContentField<string>;
|
|
448
|
-
|
|
453
|
+
video_src?: IContentField<string>;
|
|
454
|
+
/** Poster image shown before playback. */
|
|
455
|
+
poster_src?: IContentField<string>;
|
|
456
|
+
/** Cross-platform playback toggles ('0' | '1'). */
|
|
457
|
+
has_controls?: IContentField<string>;
|
|
458
|
+
media_loop?: IContentField<string>;
|
|
459
|
+
media_autoplay?: IContentField<string>;
|
|
460
|
+
media_muted?: IContentField<string>;
|
|
449
461
|
}
|
|
450
|
-
interface IAudioStyle extends
|
|
462
|
+
interface IAudioStyle extends IStyleWithSpacing {
|
|
451
463
|
style_name: 'audio';
|
|
464
|
+
alt?: IContentField<string>;
|
|
452
465
|
sources?: IContentField<unknown[]>;
|
|
466
|
+
/** Cross-platform playback toggles ('0' | '1'). */
|
|
467
|
+
has_controls?: IContentField<string>;
|
|
468
|
+
media_loop?: IContentField<string>;
|
|
469
|
+
media_autoplay?: IContentField<string>;
|
|
453
470
|
}
|
|
454
471
|
interface IFigureStyle extends IBaseStyle {
|
|
455
472
|
style_name: 'figure';
|
|
456
473
|
caption_title?: IContentField<string>;
|
|
457
474
|
caption?: IContentField<string>;
|
|
475
|
+
/** Optional built-in image so a figure needs no child image section. */
|
|
476
|
+
img_src?: IContentField<string>;
|
|
477
|
+
alt?: IContentField<string>;
|
|
458
478
|
}
|
|
459
479
|
interface ICarouselStyle extends IStyleWithSpacing {
|
|
460
480
|
style_name: 'carousel';
|
|
@@ -481,6 +501,8 @@ interface ICarouselStyle extends IStyleWithSpacing {
|
|
|
481
501
|
web_carousel_embla_options?: IContentField<string>;
|
|
482
502
|
}
|
|
483
503
|
|
|
504
|
+
/** Mantine `Anchor` `underline` behaviour. */
|
|
505
|
+
type TMantineAnchorUnderline = 'always' | 'hover' | 'never';
|
|
484
506
|
interface IButtonStyle extends IStyleWithSpacing {
|
|
485
507
|
style_name: 'button';
|
|
486
508
|
shared_variant?: IContentField<TMantineVariant>;
|
|
@@ -508,6 +530,10 @@ interface ILinkStyle extends IStyleWithSpacing {
|
|
|
508
530
|
label?: IContentField<string>;
|
|
509
531
|
url?: IContentField<string>;
|
|
510
532
|
open_in_new_tab?: IContentField<string>;
|
|
533
|
+
shared_color?: IContentField<TMantineColor>;
|
|
534
|
+
web_link_underline?: IContentField<TMantineAnchorUnderline>;
|
|
535
|
+
web_left_icon?: IContentField<string>;
|
|
536
|
+
web_right_icon?: IContentField<string>;
|
|
511
537
|
}
|
|
512
538
|
interface IActionIconStyle extends IStyleWithSpacing {
|
|
513
539
|
style_name: 'action-icon';
|
|
@@ -521,6 +547,8 @@ interface IActionIconStyle extends IStyleWithSpacing {
|
|
|
521
547
|
page_keyword?: IContentField<string>;
|
|
522
548
|
open_in_new_tab?: IContentField<string>;
|
|
523
549
|
disabled?: IContentField<string>;
|
|
550
|
+
/** Accessible name for the icon-only control (screen readers). */
|
|
551
|
+
aria_label?: IContentField<string>;
|
|
524
552
|
}
|
|
525
553
|
interface IAlertStyle extends IStyleWithSpacing {
|
|
526
554
|
style_name: 'alert';
|
|
@@ -2517,4 +2545,4 @@ declare function getPluginStyleRegistry(): Record<string, IPluginStyleRegistryEn
|
|
|
2517
2545
|
*/
|
|
2518
2546
|
declare function _resetPluginStyleRegistry(): void;
|
|
2519
2547
|
|
|
2520
|
-
export { type IGridStyle as $, type ICenterStyle as A, BASE_STYLE_REGISTRY as B, type ICheckboxStyle as C, type IChipStyle as D, type ICodeStyle as E, type IColorInputStyle as F, type IColorPickerStyle as G, type IComboboxStyle as H, type IStyleRegistryEntry as I, type IContainerStyle as J, type IDataContainerStyle as K, type IDatePickerStyle as L, type IDividerStyle as M, type IEntryListStyle as N, type IEntryRecordDeleteStyle as O, type IEntryRecordStyle as P, type IFieldsetStyle as Q, type IFigureStyle as R, STYLE_REGISTRY as S, type TStyleName as T, type IFileInputStyle as U, type IFlexStyle as V, type IFormLogStyle as W, type IFormRecordStyle as X, type IFormStyle as Y, type IGridColumnStyle as Z, type _AssertRegistryMatchesStyleName as _, type IPluginStyleRegistryEntry as a, type
|
|
2548
|
+
export { type IGridStyle as $, type ICenterStyle as A, BASE_STYLE_REGISTRY as B, type ICheckboxStyle as C, type IChipStyle as D, type ICodeStyle as E, type IColorInputStyle as F, type IColorPickerStyle as G, type IComboboxStyle as H, type IStyleRegistryEntry as I, type IContainerStyle as J, type IDataContainerStyle as K, type IDatePickerStyle as L, type IDividerStyle as M, type IEntryListStyle as N, type IEntryRecordDeleteStyle as O, type IEntryRecordStyle as P, type IFieldsetStyle as Q, type IFigureStyle as R, STYLE_REGISTRY as S, type TStyleName as T, type IFileInputStyle as U, type IFlexStyle as V, type IFormLogStyle as W, type IFormRecordStyle as X, type IFormStyle as Y, type IGridColumnStyle as Z, type _AssertRegistryMatchesStyleName as _, type IPluginStyleRegistryEntry as a, type TMantineCardShadow as a$, type IGroupStyle as a0, type IHighlightStyle as a1, type IHtmlTagStyle as a2, type IImageStyle as a3, type IIndicatorStyle as a4, type IInputStyle as a5, type IKbdStyle as a6, type ILinkStyle as a7, type IListItemStyle as a8, type IListStyle as a9, type ISpaceStyle as aA, type ISpoilerStyle as aB, type IStackStyle as aC, type IStyleWithSpacing as aD, type ISwitchStyle as aE, type ITabStyle as aF, type ITabsStyle as aG, type ITextInputStyle as aH, type ITextStyle as aI, type ITextareaStyle as aJ, type IThemeIconStyle as aK, type ITimelineItemStyle as aL, type ITimelineStyle as aM, type ITitleStyle as aN, type ITwoFactorAuthStyle as aO, type ITypographyStyle as aP, type IUnknownStyle as aQ, type IValidateStyle as aR, type IVersionStyle as aS, type IVideoStyle as aT, type TMantineAccordionChevronPosition as aU, type TMantineAccordionDisableChevronRotation as aV, type TMantineAccordionLoop as aW, type TMantineAccordionMultiple as aX, type TMantineAnchorUnderline as aY, type TMantineBorder as aZ, type TMantineCardPadding as a_, type ILoginStyle as aa, type ILoopStyle as ab, type IMissingStyle as ac, type INoAccessStyle as ad, type INotFoundStyle as ae, type INotificationStyle as af, type INumberInputStyle as ag, type IPaperStyle as ah, type IProfileStyle as ai, type IProgressRootStyle as aj, type IProgressSectionStyle as ak, type IProgressStyle as al, type IRadioStyle as am, type IRangeSliderStyle as an, type IRatingStyle as ao, type IRefContainerStyle as ap, type IRegisterStyle as aq, type IResetPasswordStyle as ar, type IRichTextEditorStyle as as, type IScrollAreaStyle as at, type ISegmentedControlStyle as au, type ISelectStyle as av, type IShowUserInputEntry as aw, type IShowUserInputStyle as ax, type ISimpleGridStyle as ay, type ISliderStyle as az, type TStylePlacement as b, type TMantineCols as b0, type TMantineDividerVariant as b1, type TMantineGap as b2, type TMantineGridOffset as b3, type TMantineGridOrder as b4, type TMantineHeight as b5, type TMantineIconSize as b6, type TMantineImageFit as b7, type TMantineLineClamp as b8, type TMantineListCenter as b9, type TSharedBorder as bA, type TSharedCols as bB, type TSharedDimension as bC, type TSharedDividerLabelPosition as bD, type TSharedDividerVariant as bE, type TSharedLabelPosition as bF, type TStyle as bG, type TMantineListStyleType as ba, type TMantineListType as bb, type TMantineListWithPadding as bc, type TMantinePaperShadow as bd, type TMantineProgressTransition as be, type TMantineScrollAreaSize as bf, type TMantineScrollAreaType as bg, type TMantineTextAlign as bh, type TMantineTextDecoration as bi, type TMantineTextFontStyle as bj, type TMantineTextFontWeight as bk, type TMantineTextInherit as bl, type TMantineTextInputVariant as bm, type TMantineTextSpan as bn, type TMantineTextTransform as bo, type TMantineTextTruncate as bp, type TMantineTextVariant as bq, type TMantineTextareaAutosize as br, type TMantineTextareaResize as bs, type TMantineTextareaVariant as bt, type TMantineTimelineAlign as bu, type TMantineTitleLineClamp as bv, type TMantineTitleTextWrap as bw, type TMantineTranslatable as bx, type TMantineUseInputWrapper as by, type TMantineWidth as bz, type TConcretePlatform as c, type TStylePlatform as d, type TStyleRegistryKey as e, _resetPluginStyleRegistry as f, extendStyleRegistry as g, getMergedStyleRegistry as h, getPluginStyleRegistry as i, type IContentField as j, type IAccordionItemStyle as k, type IAccordionStyle as l, type IActionIconStyle as m, type IAlertStyle as n, type IAspectRatioStyle as o, type IAudioStyle as p, type IAvatarStyle as q, type IBackgroundImageStyle as r, type IBadgeStyle as s, type IBaseStyle as t, type IBlockquoteStyle as u, type IBoxStyle as v, type IButtonStyle as w, type ICardSegmentStyle as x, type ICardStyle as y, type ICarouselStyle as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@selfhelp/shared",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.15",
|
|
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,116 @@
|
|
|
1
|
+
/*
|
|
2
|
+
SPDX-FileCopyrightText: 2026 Humdek, University of Bern
|
|
3
|
+
SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect } from 'vitest';
|
|
6
|
+
import { parseInlineRich, hasInlineFormatting, stripHtmlToText } from '../inlineFormat';
|
|
7
|
+
|
|
8
|
+
describe('parseInlineRich', () => {
|
|
9
|
+
it('returns a single plain run for tag-free text', () => {
|
|
10
|
+
expect(parseInlineRich('hello world')).toEqual([{ text: 'hello world' }]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('returns an empty list for empty / nullish input', () => {
|
|
14
|
+
expect(parseInlineRich('')).toEqual([]);
|
|
15
|
+
expect(parseInlineRich(null)).toEqual([]);
|
|
16
|
+
expect(parseInlineRich(undefined)).toEqual([]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('marks <strong> and <b> as bold', () => {
|
|
20
|
+
expect(parseInlineRich('a <strong>bold</strong> c')).toEqual([
|
|
21
|
+
{ text: 'a ' },
|
|
22
|
+
{ text: 'bold', bold: true },
|
|
23
|
+
{ text: ' c' },
|
|
24
|
+
]);
|
|
25
|
+
expect(parseInlineRich('<b>x</b>')).toEqual([{ text: 'x', bold: true }]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('marks <em>/<i> as italic and <u> as underline (merging same-format runs)', () => {
|
|
29
|
+
// <em>e</em><i>i</i> are both italic and adjacent, so they merge.
|
|
30
|
+
expect(parseInlineRich('<em>e</em><i>i</i><u>u</u>')).toEqual([
|
|
31
|
+
{ text: 'ei', italic: true },
|
|
32
|
+
{ text: 'u', underline: true },
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('combines nested formatting into one run', () => {
|
|
37
|
+
expect(parseInlineRich('<strong>bold <em>both</em></strong>')).toEqual([
|
|
38
|
+
{ text: 'bold ', bold: true },
|
|
39
|
+
{ text: 'both', bold: true, italic: true },
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('captures the href on anchor runs', () => {
|
|
44
|
+
expect(parseInlineRich('see <a href="https://x.test">here</a>')).toEqual([
|
|
45
|
+
{ text: 'see ' },
|
|
46
|
+
{ text: 'here', href: 'https://x.test' },
|
|
47
|
+
]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('flattens the leading <p> wrapper the editor leaves behind', () => {
|
|
51
|
+
// The exact "label authored as plain text but stored wrapped" case.
|
|
52
|
+
expect(parseInlineRich('<p class="single-line-paragraph">9 STEF</p>')).toEqual([
|
|
53
|
+
{ text: '9 STEF' },
|
|
54
|
+
]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('collapses block tags + <br> to single spaces', () => {
|
|
58
|
+
expect(parseInlineRich('<p>a</p><p>b</p>')).toEqual([{ text: 'a b' }]);
|
|
59
|
+
expect(parseInlineRich('line<br/>break')).toEqual([{ text: 'line break' }]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('keeps bold across a block boundary as separate runs', () => {
|
|
63
|
+
expect(parseInlineRich('<p><strong>A</strong></p><p>b</p>')).toEqual([
|
|
64
|
+
{ text: 'A', bold: true },
|
|
65
|
+
{ text: ' b' },
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('decodes HTML entities', () => {
|
|
70
|
+
expect(parseInlineRich('a & <strong>b c</strong>')).toEqual([
|
|
71
|
+
{ text: 'a & ' },
|
|
72
|
+
{ text: 'b c', bold: true },
|
|
73
|
+
]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('drops unknown tags but keeps their text', () => {
|
|
77
|
+
expect(parseInlineRich('<span class="x">keep</span>')).toEqual([{ text: 'keep' }]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('never touches structured JSON payloads', () => {
|
|
81
|
+
const json = '{"type":"array","items":["a","b"]}';
|
|
82
|
+
expect(parseInlineRich(json)).toEqual([{ text: json }]);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('hasInlineFormatting', () => {
|
|
87
|
+
it('is true only when a supported inline tag is present', () => {
|
|
88
|
+
expect(hasInlineFormatting('<strong>x</strong>')).toBe(true);
|
|
89
|
+
expect(hasInlineFormatting('<em>x</em>')).toBe(true);
|
|
90
|
+
expect(hasInlineFormatting('<a href="#">x</a>')).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('is false for plain text, block-only markup, and JSON', () => {
|
|
94
|
+
expect(hasInlineFormatting('plain')).toBe(false);
|
|
95
|
+
expect(hasInlineFormatting('<p>plain</p>')).toBe(false);
|
|
96
|
+
expect(hasInlineFormatting('{"a":1}')).toBe(false);
|
|
97
|
+
expect(hasInlineFormatting(null)).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('stripHtmlToText', () => {
|
|
102
|
+
it('strips tags to readable plain text', () => {
|
|
103
|
+
expect(stripHtmlToText('<p>a</p><p>b</p>')).toBe('a b');
|
|
104
|
+
expect(stripHtmlToText('<strong>bold</strong> text')).toBe('bold text');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('leaves tag-free strings and JSON untouched', () => {
|
|
108
|
+
expect(stripHtmlToText('plain')).toBe('plain');
|
|
109
|
+
const json = '{"a":1}';
|
|
110
|
+
expect(stripHtmlToText(json)).toBe(json);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('decodes entities', () => {
|
|
114
|
+
expect(stripHtmlToText('a & b')).toBe('a & b');
|
|
115
|
+
});
|
|
116
|
+
});
|