@startsimpli/ui 0.4.143 → 0.4.145

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/ui",
3
- "version": "0.4.143",
3
+ "version": "0.4.145",
4
4
  "description": "Shared UI components package for StartSimpli applications",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -22,6 +22,23 @@ export interface MarkdownRendererProps {
22
22
  /** Syntax-highlighting style for fenced code blocks. Default `"light"`. */
23
23
  theme?: 'light' | 'dark'
24
24
  className?: string
25
+ /**
26
+ * Extra rehype plugins, run after GFM. The seam the track-changes Read view
27
+ * uses to draw marks by source position (bd startsim-whwxd.3); absent, the
28
+ * renderer is exactly what it was.
29
+ */
30
+ rehypePlugins?: React.ComponentProps<typeof ReactMarkdown>['rehypePlugins']
31
+ }
32
+
33
+ /** The plain text of rendered children. With a rehype plugin wrapping text
34
+ * runs (track-changes marks), a heading's children are elements, and
35
+ * `String(children)` would give every heading the id `object-object`. */
36
+ function textOf(node: React.ReactNode): string {
37
+ if (node == null || typeof node === 'boolean') return ''
38
+ if (typeof node === 'string' || typeof node === 'number') return String(node)
39
+ if (Array.isArray(node)) return node.map(textOf).join('')
40
+ if (React.isValidElement(node)) return textOf((node.props as { children?: React.ReactNode }).children)
41
+ return ''
25
42
  }
26
43
 
27
44
  function slugify(text: string): string {
@@ -31,7 +48,7 @@ function slugify(text: string): string {
31
48
  .replace(/(^-|-$)/g, '')
32
49
  }
33
50
 
34
- export function MarkdownRenderer({ content, theme = 'light', className }: MarkdownRendererProps) {
51
+ export function MarkdownRenderer({ content, theme = 'light', className, rehypePlugins }: MarkdownRendererProps) {
35
52
  // Wide GFM tables and long code lines both scroll sideways, and on macOS
36
53
  // neither said so (startsim-5pq7h.1).
37
54
  useScrollAffordance()
@@ -47,25 +64,26 @@ export function MarkdownRenderer({ content, theme = 'light', className }: Markdo
47
64
  <div className={cn('prose prose-lg max-w-none', className)}>
48
65
  <ReactMarkdown
49
66
  remarkPlugins={[remarkGfm]}
67
+ {...(rehypePlugins ? { rehypePlugins } : {})}
50
68
  components={{
51
69
  // h1 in content renders as h2 — the page template owns the real <h1>.
52
70
  h1: ({ children, ...props }) => (
53
- <h2 id={slugify(String(children ?? ''))} className="text-3xl font-heading font-semibold mb-4 mt-10 first:mt-0 text-foreground scroll-mt-8" {...props}>
71
+ <h2 id={slugify(textOf(children))} className="text-3xl font-heading font-semibold mb-4 mt-10 first:mt-0 text-foreground scroll-mt-8" {...props}>
54
72
  {children}
55
73
  </h2>
56
74
  ),
57
75
  h2: ({ children, ...props }) => (
58
- <h2 id={slugify(String(children ?? ''))} className="text-3xl font-heading font-semibold mb-4 mt-10 first:mt-0 text-foreground scroll-mt-8" {...props}>
76
+ <h2 id={slugify(textOf(children))} className="text-3xl font-heading font-semibold mb-4 mt-10 first:mt-0 text-foreground scroll-mt-8" {...props}>
59
77
  {children}
60
78
  </h2>
61
79
  ),
62
80
  h3: ({ children, ...props }) => (
63
- <h3 id={slugify(String(children ?? ''))} className="text-2xl font-heading font-semibold mb-3 mt-8 first:mt-0 text-foreground scroll-mt-8" {...props}>
81
+ <h3 id={slugify(textOf(children))} className="text-2xl font-heading font-semibold mb-3 mt-8 first:mt-0 text-foreground scroll-mt-8" {...props}>
64
82
  {children}
65
83
  </h3>
66
84
  ),
67
85
  h4: ({ children, ...props }) => (
68
- <h4 id={slugify(String(children ?? ''))} className="text-xl font-heading font-semibold mb-2 mt-6 first:mt-0 text-foreground scroll-mt-8" {...props}>
86
+ <h4 id={slugify(textOf(children))} className="text-xl font-heading font-semibold mb-2 mt-6 first:mt-0 text-foreground scroll-mt-8" {...props}>
69
87
  {children}
70
88
  </h4>
71
89
  ),