@uniweb/kit 0.9.2 → 0.9.4

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.2",
3
+ "version": "0.9.4",
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.2"
41
+ "@uniweb/core": "0.7.4"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": "^18.0.0 || ^19.0.0",
@@ -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
 
@@ -81,6 +133,20 @@ function SequenceElement({ element, block }) {
81
133
  case 'dataBlock':
82
134
  return null
83
135
 
136
+ case 'math_display': {
137
+ // Block math from $$...$$ on its own line or ```math fence.
138
+ // The mathml string is pre-compiled at parse time; the browser
139
+ // renders real MathML natively. Foundations that want to style
140
+ // errors can target .temml-error inside this wrapper.
141
+ if (!element.mathml) return null
142
+ return (
143
+ <div
144
+ className="math-display"
145
+ dangerouslySetInnerHTML={{ __html: element.mathml }}
146
+ />
147
+ )
148
+ }
149
+
84
150
  case 'list': {
85
151
  const Tag = element.style === 'ordered' ? 'ol' : 'ul'
86
152
  return (