@uniweb/kit 0.9.3 → 0.9.5

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": "@uniweb/kit",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "Standard component library for Uniweb foundations",
5
5
  "type": "module",
6
6
  "exports": {
@@ -38,7 +38,7 @@
38
38
  "fuse.js": "^7.0.0",
39
39
  "shiki": "^3.0.0",
40
40
  "tailwind-merge": "^2.6.0",
41
- "@uniweb/core": "0.7.3"
41
+ "@uniweb/core": "0.7.5"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": "^18.0.0 || ^19.0.0",
@@ -92,6 +92,9 @@ export function Image({
92
92
  src,
93
93
  url,
94
94
  alt = "",
95
+ caption,
96
+ figureClassName,
97
+ captionClassName,
95
98
  href,
96
99
  rounded,
97
100
  filter,
@@ -184,16 +187,27 @@ export function Image({
184
187
  />
185
188
  );
186
189
 
187
- // Wrap in link if href provided
188
- if (href) {
190
+ // Wrap in link if href provided. The link wraps the bare <img>; if a
191
+ // caption is also set, the figure wraps the link below.
192
+ const linked = href
193
+ ? <Link to={href} className="inline-block">{imageElement}</Link>
194
+ : imageElement;
195
+
196
+ // Caption present → wrap in <figure>/<figcaption> for HTML/EPUB output.
197
+ // Foundations that prefer their own figure styling can pass a richer
198
+ // wrapper component instead; this is the kit-level default.
199
+ if (caption) {
189
200
  return (
190
- <Link to={href} className="inline-block">
191
- {imageElement}
192
- </Link>
201
+ <figure className={cn("uniweb-figure my-4", figureClassName)}>
202
+ {linked}
203
+ <figcaption className={cn("uniweb-figcaption text-sm text-subtle mt-2", captionClassName)}>
204
+ {caption}
205
+ </figcaption>
206
+ </figure>
193
207
  );
194
208
  }
195
209
 
196
- return imageElement;
210
+ return linked;
197
211
  }
198
212
 
199
213
  export default Image;
@@ -38,6 +38,50 @@ function generateId(text) {
38
38
  .replace(/^-|-$/g, '')
39
39
  }
40
40
 
41
+ const INLINE_INSET_RE = /<uniweb-inset data-ref-id="([^"]+)"><\/uniweb-inset>/g
42
+
43
+ /**
44
+ * Render an HTML paragraph fragment that contains inline-inset markers
45
+ * (`<uniweb-inset data-ref-id="…">`). The fragment is split at marker
46
+ * boundaries; HTML chunks render via SafeHtml, marker positions render
47
+ * via the framework's child-block renderer (the same path block-level
48
+ * insets use, scoped to a single inset block).
49
+ *
50
+ * Components rendered through this path return an inline element
51
+ * (typically a `<span>`) so the paragraph stays a single line of prose.
52
+ */
53
+ function renderParagraphWithInsets(html, block) {
54
+ if (!block) return <SafeHtml value={html} as="span" />
55
+ const InsetRenderer = getChildBlockRenderer()
56
+ const parts = []
57
+ let lastIdx = 0
58
+ INLINE_INSET_RE.lastIndex = 0
59
+ let match
60
+ while ((match = INLINE_INSET_RE.exec(html)) !== null) {
61
+ if (match.index > lastIdx) {
62
+ parts.push(
63
+ <SafeHtml
64
+ key={`t${lastIdx}`}
65
+ value={html.slice(lastIdx, match.index)}
66
+ as="span"
67
+ />
68
+ )
69
+ }
70
+ const refId = match[1]
71
+ const insetBlock = block.getInset?.(refId)
72
+ if (insetBlock && InsetRenderer) {
73
+ parts.push(<InsetRenderer key={`i${refId}`} blocks={[insetBlock]} />)
74
+ }
75
+ lastIdx = match.index + match[0].length
76
+ }
77
+ if (lastIdx < html.length) {
78
+ parts.push(
79
+ <SafeHtml key={`t${lastIdx}`} value={html.slice(lastIdx)} as="span" />
80
+ )
81
+ }
82
+ return parts
83
+ }
84
+
41
85
  /**
42
86
  * Render a single sequence element to React
43
87
  */
@@ -54,6 +98,14 @@ function SequenceElement({ element, block }) {
54
98
 
55
99
  case 'paragraph': {
56
100
  if (!element.text) return null
101
+ // Inline insets ride through the paragraph text as
102
+ // `<uniweb-inset data-ref-id="…"></uniweb-inset>` markers (see
103
+ // semantic-parser's getTextContent). When any are present, walk
104
+ // the text once and intersperse React-rendered insets at the
105
+ // marker positions; otherwise stick to the fast SafeHtml path.
106
+ if (/<uniweb-inset/.test(element.text)) {
107
+ return <p>{renderParagraphWithInsets(element.text, block)}</p>
108
+ }
57
109
  return <p><SafeHtml value={element.text} as="span" /></p>
58
110
  }
59
111