Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/vkui/.storybook/challenge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
declare global {
interface Window {
__challengeGuardInstalled?: boolean;
}
}

function install() {
if (window.__challengeGuardInstalled) {
return;
}
window.__challengeGuardInstalled = true;

const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (!(entry instanceof PerformanceResourceTiming)) {
return;
}

entry.serverTiming.forEach((serverEntry) => {
if (serverEntry.name !== 'challenge') {
return;
}

const urlEntry = new URL(entry.name);

const redirect = window.location.pathname + window.location.search;
const challenge =
urlEntry.origin + serverEntry.description + '?redirect=' + encodeURIComponent(redirect);

window.location.href = challenge;
});
});
});

['navigation', 'resource'].forEach((type) => observer.observe({ type, buffered: true }));
}

install();

export {};
34 changes: 34 additions & 0 deletions packages/vkui/.storybook/manager-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script>
(function () {
if (window.__challengeGuardInstalled) {
return;
}
window.__challengeGuardInstalled = true;

const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (!(entry instanceof PerformanceResourceTiming)) {
return;
}

entry.serverTiming.forEach((serverEntry) => {
if (serverEntry.name !== 'challenge') {
return;
}

const urlEntry = new URL(entry.name);

const redirect = window.location.pathname + window.location.search;
const challenge = urlEntry.origin + serverEntry.description +
'?redirect=' + encodeURIComponent(redirect);

window.location.href = challenge;
});
});
});

["navigation", "resource"].forEach((type) =>
observer.observe({ type, buffered: true }),
);
})();
</script>
1 change: 1 addition & 0 deletions packages/vkui/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './challenge';
import { spyOn } from 'storybook/test';
import type { Preview } from '@storybook/react';
import { BREAKPOINTS } from '../src/lib/adaptivity';
Expand Down
26 changes: 20 additions & 6 deletions website/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,28 @@ import type { Metadata } from 'next';
import type { PageMapItem } from 'nextra';
import { getPageMap } from 'nextra/page-map';
import { PlaygroundStoreProvider } from '@/providers/playgroundStoreProvider';
import uwuCode from '../uwu.js?raw';
import challengeCode from '../inline/challange.js?raw';
import uwuCode from '../inline/uwu.js?raw';
import { FooterLinks, RedirectHandler, Versions } from './_components';
import '@vkontakte/vkui-docs-theme/styles.css';

const inlineCodeArray = [challengeCode, uwuCode];

function InlineCode() {
return (
<>
{inlineCodeArray.map((code, index) => (
<script
key={index}
dangerouslySetInnerHTML={{
__html: code,
}}
/>
))}
</>
);
}

export const metadata: Metadata = {
title: {
default: 'VKUI – React UI Kit',
Expand Down Expand Up @@ -84,11 +102,7 @@ const RootLayout: React.FC<{ children: React.ReactNode }> = async ({ children })
<html lang="ru" dir="ltr" suppressHydrationWarning>
<Head />
<body>
<script
dangerouslySetInnerHTML={{
__html: uwuCode,
}}
/>
<InlineCode />
<RedirectHandler />
<Layout
pageMap={pageMap}
Expand Down
30 changes: 30 additions & 0 deletions website/inline/challange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(function () {
if (window.__challengeGuardInstalled) {
return;
}
window.__challengeGuardInstalled = true;

const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
if (!(entry instanceof PerformanceResourceTiming)) {
return;
}

entry.serverTiming.forEach((serverEntry) => {
if (serverEntry.name !== 'challenge') {
return;
}

const urlEntry = new URL(entry.name);

const redirect = window.location.pathname + window.location.search;
const challenge =
urlEntry.origin + serverEntry.description + '?redirect=' + encodeURIComponent(redirect);

window.location.href = challenge;
});
});
});

['navigation', 'resource'].forEach((type) => observer.observe({ type, buffered: true }));
})();
File renamed without changes.