@heliosgraphics/ui 2.0.1-alpha.7 → 2.0.1-alpha.9
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/components/Flex/Flex.utils.ts +3 -3
- package/components/Heading/Heading.tsx +1 -3
- package/components/Icon/Icon.module.css +4 -0
- package/components/Layout/components/LayoutMain/components/LayoutMainContent/LayoutMainContent.utils.ts +4 -3
- package/components/Markdown/Markdown.meta.ts +5 -0
- package/components/Markdown/Markdown.tsx +2 -2
- package/components/Markdown/Markdown.types.ts +1 -0
- package/components/Setup/Setup.utils.ts +0 -61
- package/components/Tabs/Tabs.tsx +3 -9
- package/components/Tabs/Tabs.utils.ts +9 -0
- package/components/Text/Text.tsx +1 -1
- package/hooks/useTheme.tsx +2 -2
- package/package.json +9 -9
- package/utils/markdown.spec.ts +24 -1
- package/utils/markdown.ts +6 -2
|
@@ -73,7 +73,7 @@ export const getFlexUtility = (props?: FlexProps): string => {
|
|
|
73
73
|
export const getResponsiveScale = (value?: ResponsiveScaleType, prefix: string = "p"): string => {
|
|
74
74
|
if (!value) return ""
|
|
75
75
|
|
|
76
|
-
const isArray: boolean =
|
|
76
|
+
const isArray: boolean = Array.isArray(value)
|
|
77
77
|
const classes = new Set<string>()
|
|
78
78
|
|
|
79
79
|
if (!isArray) return `${prefix}-${value}`
|
|
@@ -92,7 +92,7 @@ export const getResponsiveScale = (value?: ResponsiveScaleType, prefix: string =
|
|
|
92
92
|
export const getPadding = (paddingValue?: ResponsiveScaleType): string => {
|
|
93
93
|
if (!paddingValue) return ""
|
|
94
94
|
|
|
95
|
-
const isArray: boolean =
|
|
95
|
+
const isArray: boolean = Array.isArray(paddingValue)
|
|
96
96
|
const paddingClasses = new Set<string>()
|
|
97
97
|
|
|
98
98
|
if (!isArray) return `p-${paddingValue}`
|
|
@@ -111,7 +111,7 @@ export const getPadding = (paddingValue?: ResponsiveScaleType): string => {
|
|
|
111
111
|
export const getRadius = (radiusValue?: ResponsiveRadiusType): string => {
|
|
112
112
|
if (!radiusValue) return ""
|
|
113
113
|
|
|
114
|
-
const isArray: boolean =
|
|
114
|
+
const isArray: boolean = Array.isArray(radiusValue)
|
|
115
115
|
const radiusClasses = new Set<string>()
|
|
116
116
|
|
|
117
117
|
if (!isArray) return `radius-${radiusValue}`
|
|
@@ -32,9 +32,7 @@ export const Heading: FC<HeadingProps> = (props) => {
|
|
|
32
32
|
const lineHeightStyle: CSSProperties | undefined = lineHeight !== undefined ? { lineHeight } : undefined
|
|
33
33
|
|
|
34
34
|
const mergedStyle: CSSProperties | undefined =
|
|
35
|
-
style || lineClampStyle || lineHeightStyle
|
|
36
|
-
? { ...(style || {}), ...(lineClampStyle || {}), ...(lineHeightStyle || {}) }
|
|
37
|
-
: undefined
|
|
35
|
+
style || lineClampStyle || lineHeightStyle ? { ...style, ...lineClampStyle, ...lineHeightStyle } : undefined
|
|
38
36
|
const safeHeadingProps: Omit<HeadingProps, "level" | "lineClamp" | "lineHeight" | "className" | "style"> =
|
|
39
37
|
stripTypographyProps(rest)
|
|
40
38
|
|
|
@@ -7,16 +7,20 @@
|
|
|
7
7
|
width: 100%;
|
|
8
8
|
|
|
9
9
|
fill: currentcolor;
|
|
10
|
+
stroke: currentcolor;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
.iconPrimary svg {
|
|
13
14
|
fill: var(--ui-text-primary);
|
|
15
|
+
stroke: var(--ui-text-primary);
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
.iconSecondary svg {
|
|
17
19
|
fill: var(--ui-text-secondary);
|
|
20
|
+
stroke: var(--ui-text-secondary);
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
.iconTertiary svg {
|
|
21
24
|
fill: var(--ui-text-tertiary);
|
|
25
|
+
stroke: var(--ui-text-tertiary);
|
|
22
26
|
}
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
let lastLocation: string | null = null
|
|
4
4
|
let isHistoryPatched: boolean = false
|
|
5
5
|
|
|
6
|
+
const dispatchLocationChange = (): void => {
|
|
7
|
+
globalThis.dispatchEvent(new Event("locationchange"))
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
const getLocationKey = (): string | null => {
|
|
7
11
|
if (!globalThis?.location) return null
|
|
8
12
|
|
|
@@ -15,9 +19,6 @@ const patchHistory = (): void => {
|
|
|
15
19
|
isHistoryPatched = true
|
|
16
20
|
|
|
17
21
|
const { pushState, replaceState } = globalThis.history
|
|
18
|
-
const dispatchLocationChange = (): void => {
|
|
19
|
-
globalThis.dispatchEvent(new Event("locationchange"))
|
|
20
|
-
}
|
|
21
22
|
|
|
22
23
|
const pushStateWrapper = (...args: Parameters<History["pushState"]>): ReturnType<History["pushState"]> => {
|
|
23
24
|
const result = pushState.apply(globalThis.history, args as Parameters<History["pushState"]>)
|
|
@@ -16,6 +16,11 @@ export const meta: HeliosAttributeMeta<MarkdownProps> = {
|
|
|
16
16
|
isOptional: true,
|
|
17
17
|
description: "Children to render inside the markdown wrapper",
|
|
18
18
|
},
|
|
19
|
+
isLinksAllowed: {
|
|
20
|
+
type: "boolean",
|
|
21
|
+
isOptional: true,
|
|
22
|
+
description: "Preserves markdown links and auto-linked URLs in sanitized output",
|
|
23
|
+
},
|
|
19
24
|
isNonSelectable: {
|
|
20
25
|
type: "boolean",
|
|
21
26
|
isOptional: true,
|
|
@@ -4,7 +4,7 @@ import styles from "./Markdown.module.css"
|
|
|
4
4
|
import type { FC } from "react"
|
|
5
5
|
import type { MarkdownProps } from "./Markdown.types"
|
|
6
6
|
|
|
7
|
-
export const Markdown: FC<MarkdownProps> = ({ text, children, isNonSelectable }) => {
|
|
7
|
+
export const Markdown: FC<MarkdownProps> = ({ text, children, isNonSelectable, isLinksAllowed }) => {
|
|
8
8
|
if (!text && !children) return null
|
|
9
9
|
|
|
10
10
|
const markdownClasses: string = getClasses(styles.markdown, {
|
|
@@ -12,7 +12,7 @@ export const Markdown: FC<MarkdownProps> = ({ text, children, isNonSelectable })
|
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
if (text) {
|
|
15
|
-
const innerHTML = { __html: renderMarkdown(text) }
|
|
15
|
+
const innerHTML = { __html: renderMarkdown(text, { allowLinks: !!isLinksAllowed }) }
|
|
16
16
|
|
|
17
17
|
return <div className={markdownClasses} dangerouslySetInnerHTML={innerHTML} data-ui-component="Markdown"></div>
|
|
18
18
|
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { HeliosFixedThemeType, HeliosThemeType } from "../../types/themes"
|
|
2
|
-
|
|
3
|
-
export const code = (theme: HeliosThemeType = "system", fixedTheme?: HeliosFixedThemeType): void => {
|
|
4
|
-
globalThis.__onThemeChange = function (_theme: HeliosFixedThemeType): void {}
|
|
5
|
-
|
|
6
|
-
const setTheme = (newTheme: HeliosFixedThemeType): void => {
|
|
7
|
-
globalThis.__theme = newTheme
|
|
8
|
-
document.documentElement.dataset["theme"] = newTheme
|
|
9
|
-
globalThis.__onThemeChange?.(newTheme)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const handleDocumentClick = (event: MouseEvent): void => {
|
|
13
|
-
if (event.x > 256 && globalThis.location.hash === "#ui-menu") {
|
|
14
|
-
globalThis.location.hash = "#ui"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
document.addEventListener("click", handleDocumentClick)
|
|
19
|
-
|
|
20
|
-
const isLocked: boolean = fixedTheme !== undefined || theme !== "system"
|
|
21
|
-
|
|
22
|
-
if (fixedTheme !== undefined && theme !== "system") {
|
|
23
|
-
console.warn("Setup: Both theme and fixedTheme props are set. fixedTheme takes precedence, theme prop is ignored.")
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (isLocked) {
|
|
27
|
-
const lockedTheme: HeliosFixedThemeType = fixedTheme ?? (theme as HeliosFixedThemeType)
|
|
28
|
-
globalThis.__setPreferredTheme = function (_newTheme: HeliosFixedThemeType): void {}
|
|
29
|
-
setTheme(lockedTheme)
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let preferredTheme: HeliosFixedThemeType | undefined
|
|
34
|
-
const darkQuery: MediaQueryList = globalThis.matchMedia("(prefers-color-scheme: dark)")
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
const storedTheme: string | null = globalThis.localStorage.getItem("theme")
|
|
38
|
-
if (storedTheme === "dark" || storedTheme === "light") {
|
|
39
|
-
preferredTheme = storedTheme
|
|
40
|
-
}
|
|
41
|
-
} catch (error: unknown) {
|
|
42
|
-
console.error("failed to read theme from localStorage:", error)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
globalThis.__setPreferredTheme = function (newTheme: HeliosFixedThemeType): void {
|
|
46
|
-
try {
|
|
47
|
-
setTheme(newTheme)
|
|
48
|
-
globalThis.localStorage.setItem("theme", newTheme)
|
|
49
|
-
} catch (error: unknown) {
|
|
50
|
-
console.error("failed to set theme:", error)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const handleDarkModeChange = (event: MediaQueryListEvent): void => {
|
|
55
|
-
globalThis.__setPreferredTheme(event.matches ? "dark" : "light")
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
darkQuery.addEventListener("change", handleDarkModeChange)
|
|
59
|
-
|
|
60
|
-
setTheme(preferredTheme ?? (darkQuery.matches ? "dark" : "light"))
|
|
61
|
-
}
|
package/components/Tabs/Tabs.tsx
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import { getClasses } from "@heliosgraphics/utils"
|
|
2
2
|
import { Text } from "../Text"
|
|
3
|
+
import { onTabKeyDown } from "./Tabs.utils"
|
|
3
4
|
import styles from "./Tabs.module.css"
|
|
4
|
-
import type { FC
|
|
5
|
+
import type { FC } from "react"
|
|
5
6
|
import type { TabItem, TabsProps } from "./Tabs.types"
|
|
6
7
|
|
|
7
8
|
export const Tabs: FC<TabsProps> = ({ items, children }) => {
|
|
8
9
|
if (!items?.length) return null
|
|
9
10
|
|
|
10
|
-
const onKeyDown = (event: KeyboardEvent<HTMLElement>, item: TabItem): void => {
|
|
11
|
-
if (event.key === " " || event.key === "Enter") {
|
|
12
|
-
event.preventDefault()
|
|
13
|
-
item.onClick?.()
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
11
|
return (
|
|
18
12
|
<div data-ui-component="Tabs">
|
|
19
13
|
<div role="tablist" className={styles.tabs__list}>
|
|
@@ -46,7 +40,7 @@ export const Tabs: FC<TabsProps> = ({ items, children }) => {
|
|
|
46
40
|
<div
|
|
47
41
|
{...commonProps}
|
|
48
42
|
onClick={item.isDisabled ? undefined : item.onClick}
|
|
49
|
-
onKeyDown={(
|
|
43
|
+
onKeyDown={(event) => onTabKeyDown(event, item)}
|
|
50
44
|
>
|
|
51
45
|
<Text type="small" fontWeight="medium">
|
|
52
46
|
{item.name}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { KeyboardEvent } from "react"
|
|
2
|
+
import type { TabItem } from "./Tabs.types"
|
|
3
|
+
|
|
4
|
+
export const onTabKeyDown = (event: KeyboardEvent<HTMLElement>, item: TabItem): void => {
|
|
5
|
+
if (event.key === " " || event.key === "Enter") {
|
|
6
|
+
event.preventDefault()
|
|
7
|
+
item.onClick?.()
|
|
8
|
+
}
|
|
9
|
+
}
|
package/components/Text/Text.tsx
CHANGED
|
@@ -28,7 +28,7 @@ export const Text: FC<TextProps> = (props) => {
|
|
|
28
28
|
: undefined
|
|
29
29
|
|
|
30
30
|
const mergedStyle: object | undefined =
|
|
31
|
-
props.style || lineClampStyle ? { ...
|
|
31
|
+
props.style || lineClampStyle ? { ...props.style, ...lineClampStyle } : undefined
|
|
32
32
|
|
|
33
33
|
const baseTextProps: Omit<TextProps, "type"> = {
|
|
34
34
|
onClick: props.onClick,
|
package/hooks/useTheme.tsx
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
import { useCallback, useEffect, useState } from "react"
|
|
4
4
|
import type { HeliosFixedThemeType } from "../types/themes"
|
|
5
5
|
|
|
6
|
+
const getTheme = (): HeliosFixedThemeType => (typeof globalThis !== "undefined" ? globalThis.__theme : "light")
|
|
7
|
+
|
|
6
8
|
export const useTheme = (): { theme: HeliosFixedThemeType; isDark: boolean; toggleTheme: () => void } => {
|
|
7
9
|
const [theme, setTheme] = useState<HeliosFixedThemeType | null>(null)
|
|
8
10
|
|
|
@@ -10,8 +12,6 @@ export const useTheme = (): { theme: HeliosFixedThemeType; isDark: boolean; togg
|
|
|
10
12
|
setTheme(getTheme())
|
|
11
13
|
}, [])
|
|
12
14
|
|
|
13
|
-
const getTheme = (): HeliosFixedThemeType => (typeof globalThis !== "undefined" ? globalThis.__theme : "light")
|
|
14
|
-
|
|
15
15
|
const toggleTheme = useCallback(() => {
|
|
16
16
|
const currentIsDark: boolean = getTheme() === "dark"
|
|
17
17
|
globalThis.__setPreferredTheme?.(currentIsDark ? "light" : "dark")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heliosgraphics/ui",
|
|
3
|
-
"version": "2.0.1-alpha.
|
|
3
|
+
"version": "2.0.1-alpha.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"ts:watch": "tsc --noEmit --incremental --watch"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@heliosgraphics/css": "^1.0.0-alpha.
|
|
44
|
-
"@heliosgraphics/icons": "^1.0.0-alpha.
|
|
45
|
-
"@heliosgraphics/utils": "^6.0.0-alpha.
|
|
46
|
-
"marked": "^17.0.
|
|
43
|
+
"@heliosgraphics/css": "^1.0.0-alpha.10",
|
|
44
|
+
"@heliosgraphics/icons": "^1.0.0-alpha.14",
|
|
45
|
+
"@heliosgraphics/utils": "^6.0.0-alpha.16",
|
|
46
|
+
"marked": "^17.0.5",
|
|
47
47
|
"marked-linkify-it": "^3.1.14",
|
|
48
48
|
"marked-xhtml": "^1.0.14",
|
|
49
49
|
"react-plock": "^3.6.1"
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@testing-library/react": "^16.3.2",
|
|
53
53
|
"@types/node": "^25",
|
|
54
|
-
"esbuild": "^0.
|
|
54
|
+
"esbuild": "^0.28.0",
|
|
55
55
|
"esbuild-css-modules-plugin": "^3.1.5",
|
|
56
56
|
"glob": "^13.0.6",
|
|
57
|
-
"jsdom": "^
|
|
58
|
-
"next": "^16.
|
|
57
|
+
"jsdom": "^29.0.1",
|
|
58
|
+
"next": "^16.2.2",
|
|
59
59
|
"prettier": "^3.8.1",
|
|
60
|
-
"typescript": "^
|
|
60
|
+
"typescript": "^6.0.2"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@types/react": "^19",
|
package/utils/markdown.spec.ts
CHANGED
|
@@ -5,6 +5,10 @@ describe("markdown", () => {
|
|
|
5
5
|
describe("renderMarkdown", () => {
|
|
6
6
|
const SAMPLE = `Hello\n\nHey`
|
|
7
7
|
const SAMPLE_OUTPUT = `<p>Hello</p>\n<p>Hey</p>\n`
|
|
8
|
+
const LINK_SAMPLE = `[x](https://example.com)`
|
|
9
|
+
const LINK_SAMPLE_OUTPUT = `<p><a href="https://example.com">x</a></p>\n`
|
|
10
|
+
const BARE_URL_SAMPLE = `Visit https://example.com/path for details.`
|
|
11
|
+
const BARE_URL_SAMPLE_OUTPUT = `<p>Visit <a href="https://example.com/path">https://example.com/path</a> for details.</p>\n`
|
|
8
12
|
const MALICIOUS_SAMPLE = `Hello <script>alert(1)</script> **world**`
|
|
9
13
|
const MALICIOUS_SAMPLE_OUTPUT = `<p>Hello <strong>world</strong></p>`
|
|
10
14
|
const MALICIOUS_LINK_SAMPLE = `[x](data:text/html,<script>alert(1)</script>)`
|
|
@@ -14,6 +18,19 @@ describe("markdown", () => {
|
|
|
14
18
|
|
|
15
19
|
it("Returns", () => expect(renderMarkdown(SAMPLE)).toEqual(SAMPLE_OUTPUT))
|
|
16
20
|
|
|
21
|
+
it("keeps explicit markdown links when links are allowed", () => {
|
|
22
|
+
expect(renderMarkdown(LINK_SAMPLE, { allowLinks: true })).toEqual(LINK_SAMPLE_OUTPUT)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it("autolinks bare urls when links are allowed", () => {
|
|
26
|
+
expect(renderMarkdown(BARE_URL_SAMPLE, { allowLinks: true })).toEqual(BARE_URL_SAMPLE_OUTPUT)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it("keeps links disabled by default", () => {
|
|
30
|
+
expect(renderMarkdown(LINK_SAMPLE)).toEqual(`<p>x</p>\n`)
|
|
31
|
+
expect(renderMarkdown(BARE_URL_SAMPLE)).toEqual(`<p>Visit https://example.com/path for details.</p>\n`)
|
|
32
|
+
})
|
|
33
|
+
|
|
17
34
|
it("strips unsafe html from markdown output", () => {
|
|
18
35
|
const result = renderMarkdown(MALICIOUS_SAMPLE)
|
|
19
36
|
|
|
@@ -23,13 +40,19 @@ describe("markdown", () => {
|
|
|
23
40
|
})
|
|
24
41
|
|
|
25
42
|
it("strips unsafe link protocols without leaving broken markup", () => {
|
|
26
|
-
const result = renderMarkdown(MALICIOUS_LINK_SAMPLE)
|
|
43
|
+
const result = renderMarkdown(MALICIOUS_LINK_SAMPLE, { allowLinks: true })
|
|
27
44
|
|
|
28
45
|
expect(result).toEqual(MALICIOUS_LINK_SAMPLE_OUTPUT)
|
|
29
46
|
expect(result).not.toContain("data:")
|
|
30
47
|
expect(result).not.toContain("<script")
|
|
31
48
|
})
|
|
32
49
|
|
|
50
|
+
it("does not autolink urls inside inline code", () => {
|
|
51
|
+
const result = renderMarkdown("`https://example.com`", { allowLinks: true })
|
|
52
|
+
|
|
53
|
+
expect(result).toEqual(`<p><code>https://example.com</code></p>\n`)
|
|
54
|
+
})
|
|
55
|
+
|
|
33
56
|
it("removes inline event handler attributes from raw html", () => {
|
|
34
57
|
const result = renderMarkdown(MALICIOUS_EVENT_HANDLER_SAMPLE)
|
|
35
58
|
|
package/utils/markdown.ts
CHANGED
|
@@ -6,6 +6,10 @@ import { sanitizeText } from "@heliosgraphics/utils"
|
|
|
6
6
|
const marked = new Marked({ breaks: true, gfm: true })
|
|
7
7
|
const SAFE_MARKDOWN_LINK_PATTERN: RegExp = /^(?:https?:|mailto:|tel:|\/|#)/i
|
|
8
8
|
|
|
9
|
+
export interface RenderMarkdownOptions {
|
|
10
|
+
allowLinks?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
marked.use(markedXhtml())
|
|
10
14
|
marked.use(markedLinkifyIt())
|
|
11
15
|
|
|
@@ -15,9 +19,9 @@ const stripUnsafeMarkdownLinks = (html: string): string => {
|
|
|
15
19
|
})
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
export const renderMarkdown = (text: string): string => {
|
|
22
|
+
export const renderMarkdown = (text: string, options: RenderMarkdownOptions = {}): string => {
|
|
19
23
|
const renderedMarkdown: string = marked.parse(text) as string
|
|
20
|
-
const sanitizedMarkdown: string = sanitizeText(stripUnsafeMarkdownLinks(renderedMarkdown))
|
|
24
|
+
const sanitizedMarkdown: string = sanitizeText(stripUnsafeMarkdownLinks(renderedMarkdown), options)
|
|
21
25
|
|
|
22
26
|
return renderedMarkdown.endsWith("\n") ? `${sanitizedMarkdown}\n` : sanitizedMarkdown
|
|
23
27
|
}
|