Skip to content

Commit

Permalink
Merge branch 'master' into static-build-langs
Browse files Browse the repository at this point in the history
  • Loading branch information
makamekm authored Mar 25, 2024
2 parents c26fcb6 + ef9e98c commit 05c9ed1
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 33 deletions.
29 changes: 14 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 72 additions & 18 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ import {
NavigationItemModel,
PageConstructor,
PageConstructorProvider,
PageContent,
} from '@gravity-ui/page-constructor';
import {ThemeProvider} from '@gravity-ui/uikit';
import {
DocLeadingPage,
DocContentPageData,
DocLeadingPageData,
DocPage,
DocPageData,
DocumentType,
Lang,
Router,
Theme,
getLangPath,
getPageByType,
getPageType,
} from '@diplodoc/components';

import {HeaderControls} from '../HeaderControls';
import {getDirection, updateRootClassName} from '../../utils';
import {Layout} from '../Layout';
Expand All @@ -32,14 +36,20 @@ import {LatexRuntime} from '@diplodoc/latex-extension/react';
import {Runtime as OpenapiSandbox} from '@diplodoc/openapi-extension/runtime';

import './App.scss';
import {ConstructorPage} from '../ConstructorPage';

export interface AppProps {
lang: Lang;
langs: Lang[];
router: Router;
type: DocumentType;
}

export interface PageContentData extends DocContentPageData {
data: PageContent & {fullScreen?: boolean};
}

export type DocInnerProps<Data = DocLeadingPageData | DocPageData> = {
export type DocInnerProps<Data = DocLeadingPageData | DocPageData | PageContentData> = {
data: Data;
} & AppProps;

Expand Down Expand Up @@ -67,9 +77,9 @@ function Runtime(props: RuntimeProps) {
);
}

function Page(props: DocInnerProps) {
export function Page(props: DocInnerProps) {
const {data, ...pageProps} = props;
const Page = data.leading ? DocLeadingPage : DocPage;
const Page = getPageByType(props?.type);

return (
<Layout>
Expand Down Expand Up @@ -117,6 +127,8 @@ export function App(props: DocInnerProps): ReactElement {
const {theme, textSize, wideFormat, fullScreen, showMiniToc, onChangeFullScreen} = settings;
const fullHeader = !fullScreen && Boolean(navigation);
const headerHeight = fullHeader ? 64 : 0;
const type = getPageType(data);

const pageProps = {
headerHeight,
data,
Expand All @@ -129,8 +141,14 @@ export function App(props: DocInnerProps): ReactElement {
textSize,
fullScreen,
onChangeFullScreen,
type,
};
const direction = getDirection(lang);
const fullScreenPC =
type === DocumentType.PageConstructor &&
'data' in data &&
'fullScreen' in data.data &&
data.data.fullScreen;

useEffect(() => {
updateRootClassName({
Expand All @@ -145,13 +163,40 @@ export function App(props: DocInnerProps): ReactElement {
...settings,
onChangeLang,
}

Check failure on line 165 in src/components/App/App.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `;`
console.log("here", router);

if (!navigation) {
return (
<div className="App">
<ThemeProvider theme={theme} direction={direction}>
<Page {...pageProps} {...pageContext} />
<Page {...pageProps} {...pageContext}>
{type === DocumentType.PageConstructor && (
<PageConstructorProvider theme={theme}>
<PageConstructor
custom={{
blocks: {
page: () => (
<ConstructorPage
data={data as PageContentData}
theme={theme}
/>
),
},
}}
content={
fullScreenPC
? (data.data as PageContent)
: {
blocks: [
{
type: 'page',
},
],
}
}
/>
</PageConstructorProvider>
)}
</Page>
<Runtime theme={theme} />
</ThemeProvider>
</div>
Expand All @@ -175,20 +220,29 @@ console.log("here", router);
},
blocks: {
page: () => (
<Page
{...pageProps}
{...(headerWithControls ? {} : pageContext)}
/>
<Page {...pageProps} {...(headerWithControls ? {} : pageContext)}>

Check failure on line 223 in src/components/App/App.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Replace `·{...pageProps}·{...(headerWithControls·?·{}·:·pageContext)}` with `⏎········································{...pageProps}⏎········································{...(headerWithControls·?·{}·:·pageContext)}⏎····································`
{type === DocumentType.PageConstructor &&
'data' in data && (
<ConstructorPage
data={data as PageContentData}
theme={theme}
/>
)}
</Page>
),
},
}}
content={{
blocks: [
{
type: 'page',
},
],
}}
content={
fullScreenPC
? (data.data as PageContent)
: {
blocks: [
{
type: 'page',
},
],
}
}
navigation={
fullHeader
? {
Expand Down
44 changes: 44 additions & 0 deletions src/components/ConstructorPage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';

import block from 'bem-cn-lite';
import {
BackgroundMedia,
Col,
ConstructorBlocks,
Grid,
Row,
Theme,
getThemedValue,
} from '@gravity-ui/page-constructor';
import {PageContentData} from '../App/App';

export type WithChildren<T = {}> = T & {children?: React.ReactNode};

const bPC = block('pc-page-constructor');
const bPCRow = block('pc-constructor-row');

export const ConstructorRow = ({children}: WithChildren<{}>) =>
children ? (
<Row className={bPCRow()}>
<Col>{children}</Col>
</Row>
) : null;

export function ConstructorPage({data: {data}, theme}: {data: PageContentData; theme: Theme}) {
const themedBackground = getThemedValue(data?.background, theme);

return (
<div className={bPC('')}>
<div className={bPC('wrapper')}>
{data?.blocks && themedBackground && (
<BackgroundMedia {...themedBackground} className={bPC('background')} />
)}
<Grid>
<ConstructorRow>
<ConstructorBlocks items={data?.blocks} />
</ConstructorRow>
</Grid>
</div>
</div>
);
}
22 changes: 22 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,25 @@ export enum TextDirection {
RTL = 'rtl',
LTR = 'ltr',
}

export const LINK_KEYS_LEADING_CONFIG = ['href'];
export const LINK_KEYS_PAGE_CONSTRUCTOR_CONFIG = [
'src',
'url',
'href',
'icon',
'image',
'desktop',
'mobile',
'tablet',
'previewImg',
'image',
'avatar',
'logo',
'light',
'dark',
];

export const LINK_KEYS = [
...new Set([...LINK_KEYS_LEADING_CONFIG, ...LINK_KEYS_PAGE_CONSTRUCTOR_CONFIG]),
];
2 changes: 2 additions & 0 deletions src/index.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React from 'react';
import {renderToString} from 'react-dom/server';

import {App, DocInnerProps, DocLeadingPageData, DocPageData} from './components/App/App';
import {LINK_KEYS} from './constants';

export type {DocInnerProps, DocPageData, DocLeadingPageData};
export {LINK_KEYS};

export const render = (props: DocInnerProps) => renderToString(<App {...props} />);
14 changes: 14 additions & 0 deletions src/styles/overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
margin-top: var(--pc-first-block-indent, 96px);
}

.pc-Grid {
.container-fluid {
padding-right: 0px;
padding-left: 0px;
}
}

.pc-Grid .pc-Grid {
.container-fluid .pc-header-block__container-fluid {
padding-right: 40px;
padding-left: 40px;
}
}

.pc-block-base {
padding: 0 !important;
}
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"target": "es2020",
"moduleResolution": "node",
"resolveJsonModule": true,
"lib": ["DOM"],
"declaration": true,
"outDir": "build",
Expand Down

0 comments on commit 05c9ed1

Please sign in to comment.