Files
tolaria/src/utils/url.ts
lucaronin 3f79d1631b fix: use Tauri opener plugin for URL property clicks
Replace window.open() with Tauri's opener plugin (openUrl) so that
clicking a URL property in the Properties panel opens the system
browser instead of failing silently or triggering edit mode.

- Install @tauri-apps/plugin-opener (npm + Cargo + capabilities)
- Add openExternalUrl() utility with Tauri/browser fallback
- Add stopPropagation to prevent accidental edit mode activation
- Add double-click guard (500ms debounce via ref)
- Update tests to mock openExternalUrl instead of window.open
- Add explicit test that URL click does not trigger onStartEdit

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 00:02:09 +01:00

25 lines
765 B
TypeScript

import { isTauri } from '../mock-tauri'
const URL_PATTERN = /^https?:\/\//i
const BARE_DOMAIN_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z]{2,})+([/?#]|$)/i
export function isUrlValue(value: string): boolean {
if (!value) return false
return URL_PATTERN.test(value) || BARE_DOMAIN_PATTERN.test(value)
}
export function normalizeUrl(url: string): string {
if (URL_PATTERN.test(url)) return url
return `https://${url}`
}
/** Open a URL in the system browser. Uses Tauri opener plugin in native mode, window.open in browser. */
export async function openExternalUrl(url: string): Promise<void> {
if (isTauri()) {
const { openUrl } = await import('@tauri-apps/plugin-opener')
await openUrl(url)
} else {
window.open(url, '_blank')
}
}