import '@redneckz/uni-jsx/lib/setup.react'; import { useEffect, useState } from 'react'; import { handlerDecorator } from './external/handlerDecorator'; import { locationNavigator } from './external/locationNavigator'; import { useRouter } from './external/useRouter'; import { projectSettings } from './ProjectSettings'; import { noop } from './utils/noop'; import { joinPath } from './utils/url'; import wlc from './wlc.json'; projectSettings.setup(wlc); useRouter.setup(() => { const [href, setHref] = useState(joinPath(globalThis.location.origin)); useEffect(() => { const handleHistoryChange = () => { setHref(globalThis.location.href); }; globalThis.addEventListener('popstate', handleHistoryChange); return () => { globalThis.removeEventListener('popstate', handleHistoryChange); }; }, []); return { pathname: new URL(href as string).pathname, push: (url: string) => { globalThis.history.pushState(null, '', url); }, replace: (url: string) => { globalThis.history.replaceState(null, '', url); }, back: () => { globalThis.history.back(); }, }; }); handlerDecorator.setup((handler): any => (ev) => { const shouldNotPrevent = ev?.target?.type === 'submit'; if (!shouldNotPrevent) { ev?.preventDefault(); } handler(ev); }); locationNavigator.setup(() => ({ assign: noop, get href() { return globalThis.location.href; }, get origin() { return globalThis.location.origin; }, }));