@uniweb/kit 0.9.28 → 0.9.29
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,18 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SafeHtml Component
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Renders an HTML string with authored-href resolution: the `page:` (stable
|
|
5
|
+
* page reference) and `topic:` (legacy) protocols, and the deployment base
|
|
6
|
+
* path — the same resolution kit's <Link> applies to a structured link, so
|
|
7
|
+
* inline link marks inside rich-text bodies resolve identically.
|
|
8
8
|
*
|
|
9
|
-
* The resolution itself lives in utils/href.js, shared with <Text>, so
|
|
10
|
-
*
|
|
9
|
+
* The resolution itself lives in utils/href.js, shared with <Text>, so both
|
|
10
|
+
* prose renderers agree on what an authored href means.
|
|
11
|
+
*
|
|
12
|
+
* WHAT "SAFE" DOES NOT MEAN
|
|
13
|
+
* This component does NOT sanitize. Nothing in the framework does. The value
|
|
14
|
+
* is rendered as-is, so it must come from a source you trust — which the
|
|
15
|
+
* framework's own content is: the author of a site's markdown also writes its
|
|
16
|
+
* foundation, so there is no privilege boundary to defend. A foundation that
|
|
17
|
+
* renders genuinely untrusted HTML (say a user-submitted string arriving
|
|
18
|
+
* through a fetcher) is responsible for that decision, and should not read
|
|
19
|
+
* this component's name as a guarantee.
|
|
11
20
|
*
|
|
12
21
|
* @module @uniweb/kit/SafeHtml
|
|
13
22
|
*/
|
|
14
23
|
|
|
15
|
-
import React, {
|
|
24
|
+
import React, { useMemo } from 'react'
|
|
16
25
|
import { useWebsite } from '../../hooks/useWebsite.js'
|
|
17
26
|
import { resolveProseHrefs } from '../../utils/href.js'
|
|
18
27
|
|
|
@@ -32,10 +41,7 @@ import { resolveProseHrefs } from '../../utils/href.js'
|
|
|
32
41
|
* <SafeHtml value='<a href="page:93dc5359">About</a>' />
|
|
33
42
|
*/
|
|
34
43
|
export function SafeHtml({ value, className, as: Component = 'div', ...props }) {
|
|
35
|
-
const { website
|
|
36
|
-
|
|
37
|
-
// Get the runtime's SafeHtml if available (handles sanitization)
|
|
38
|
-
const RuntimeSafeHtml = getRoutingComponents()?.SafeHtml
|
|
44
|
+
const { website } = useWebsite()
|
|
39
45
|
|
|
40
46
|
// Process the value
|
|
41
47
|
const processedValue = useMemo(() => {
|
|
@@ -48,16 +54,6 @@ export function SafeHtml({ value, className, as: Component = 'div', ...props })
|
|
|
48
54
|
return resolveProseHrefs(html, website)
|
|
49
55
|
}, [value, website])
|
|
50
56
|
|
|
51
|
-
// Use runtime SafeHtml if available (recommended for proper sanitization)
|
|
52
|
-
if (RuntimeSafeHtml) {
|
|
53
|
-
return (
|
|
54
|
-
<Suspense fallback={null}>
|
|
55
|
-
<RuntimeSafeHtml value={processedValue} className={className} {...props} />
|
|
56
|
-
</Suspense>
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Fallback: render directly (less safe, but works without runtime)
|
|
61
57
|
return (
|
|
62
58
|
<Component
|
|
63
59
|
className={className}
|