diff --git a/package-lock.json b/package-lock.json index 23f03ca2..b8af65aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@gravity-ui/icons": "^2.5.0", - "@gravity-ui/uikit": "^6.0.0", + "@gravity-ui/uikit": "^6.2.0", "@popperjs/core": "^2.11.2", "bem-cn-lite": "4.1.0", "i18next": "^19.9.2", @@ -1787,9 +1787,9 @@ } }, "node_modules/@gravity-ui/i18n": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@gravity-ui/i18n/-/i18n-1.2.0.tgz", - "integrity": "sha512-1FNZmbxeT3arwU2bv1p77u/K7rYoX4pGrXf0SNwg45HbbgI0XV0WapXbWr/GIB7EXdjiOvQ7kzXCfVIFV4ifYw==" + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@gravity-ui/i18n/-/i18n-1.3.0.tgz", + "integrity": "sha512-xrTl0vq6L06RpsT+u5Kq5fuH5kuKT5R88lo79+9HYLtS/dPseFzw0qnN+a4q/6Rlu9ZKxtZaIv7dTQxH1/ozlQ==" }, "node_modules/@gravity-ui/icons": { "version": "2.8.1", @@ -1828,17 +1828,18 @@ "dev": true }, "node_modules/@gravity-ui/uikit": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@gravity-ui/uikit/-/uikit-6.0.0.tgz", - "integrity": "sha512-16xgkTI646tZoAT5pnw7Ge2Q4e9c8DWYZw0w11X8A9hyuYaNjd0isUxpD4Beywi4ELKeFv3t2IXCn/RTU7/qVw==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@gravity-ui/uikit/-/uikit-6.5.0.tgz", + "integrity": "sha512-xRr7xKHkdNVjz+lrbponuq7toE7f/iktVN0cJniHWVyvu/GawApvRl6ysmJCv09x2oakXC9D8kn4yRU+j4kEtA==", "dependencies": { "@bem-react/classname": "^1.6.0", - "@gravity-ui/i18n": "^1.2.0", + "@gravity-ui/i18n": "^1.3.0", "@gravity-ui/icons": "^2.8.1", "@popperjs/core": "^2.11.8", "blueimp-md5": "^2.19.0", "focus-trap": "^7.5.4", "lodash": "^4.17.21", + "rc-slider": "^10.5.0", "react-beautiful-dnd": "^13.1.1", "react-copy-to-clipboard": "^5.1.0", "react-popper": "^2.3.0", @@ -3119,6 +3120,11 @@ "node": ">= 6" } }, + "node_modules/classnames": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz", + "integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==" + }, "node_modules/clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", @@ -7638,6 +7644,41 @@ "resolved": "https://registry.npmjs.org/raf-schd/-/raf-schd-4.0.3.tgz", "integrity": "sha512-tQkJl2GRWh83ui2DiPTJz9wEiMN20syf+5oKfB03yYP7ioZcJwsIK8FjrtLwH1m7C7e+Tt2yYBlrOpdT+dyeIQ==" }, + "node_modules/rc-slider": { + "version": "10.5.0", + "resolved": "https://registry.npmjs.org/rc-slider/-/rc-slider-10.5.0.tgz", + "integrity": "sha512-xiYght50cvoODZYI43v3Ylsqiw14+D7ELsgzR40boDZaya1HFa1Etnv9MDkQE8X/UrXAffwv2AcNAhslgYuDTw==", + "dependencies": { + "@babel/runtime": "^7.10.1", + "classnames": "^2.2.5", + "rc-util": "^5.27.0" + }, + "engines": { + "node": ">=8.x" + }, + "peerDependencies": { + "react": ">=16.9.0", + "react-dom": ">=16.9.0" + } + }, + "node_modules/rc-util": { + "version": "5.39.1", + "resolved": "https://registry.npmjs.org/rc-util/-/rc-util-5.39.1.tgz", + "integrity": "sha512-OW/ERynNDgNr4y0oiFmtes3rbEamXw7GHGbkbNd9iRr7kgT03T6fT0b9WpJ3mbxKhyOcAHnGcIoh5u/cjrC2OQ==", + "dependencies": { + "@babel/runtime": "^7.18.3", + "react-is": "^18.2.0" + }, + "peerDependencies": { + "react": ">=16.9.0", + "react-dom": ">=16.9.0" + } + }, + "node_modules/rc-util/node_modules/react-is": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", + "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==" + }, "node_modules/react": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", @@ -10304,9 +10345,9 @@ } }, "@gravity-ui/i18n": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@gravity-ui/i18n/-/i18n-1.2.0.tgz", - "integrity": "sha512-1FNZmbxeT3arwU2bv1p77u/K7rYoX4pGrXf0SNwg45HbbgI0XV0WapXbWr/GIB7EXdjiOvQ7kzXCfVIFV4ifYw==" + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@gravity-ui/i18n/-/i18n-1.3.0.tgz", + "integrity": "sha512-xrTl0vq6L06RpsT+u5Kq5fuH5kuKT5R88lo79+9HYLtS/dPseFzw0qnN+a4q/6Rlu9ZKxtZaIv7dTQxH1/ozlQ==" }, "@gravity-ui/icons": { "version": "2.8.1", @@ -10339,17 +10380,18 @@ "dev": true }, "@gravity-ui/uikit": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@gravity-ui/uikit/-/uikit-6.0.0.tgz", - "integrity": "sha512-16xgkTI646tZoAT5pnw7Ge2Q4e9c8DWYZw0w11X8A9hyuYaNjd0isUxpD4Beywi4ELKeFv3t2IXCn/RTU7/qVw==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/@gravity-ui/uikit/-/uikit-6.5.0.tgz", + "integrity": "sha512-xRr7xKHkdNVjz+lrbponuq7toE7f/iktVN0cJniHWVyvu/GawApvRl6ysmJCv09x2oakXC9D8kn4yRU+j4kEtA==", "requires": { "@bem-react/classname": "^1.6.0", - "@gravity-ui/i18n": "^1.2.0", + "@gravity-ui/i18n": "^1.3.0", "@gravity-ui/icons": "^2.8.1", "@popperjs/core": "^2.11.8", "blueimp-md5": "^2.19.0", "focus-trap": "^7.5.4", "lodash": "^4.17.21", + "rc-slider": "^10.5.0", "react-beautiful-dnd": "^13.1.1", "react-copy-to-clipboard": "^5.1.0", "react-popper": "^2.3.0", @@ -11258,6 +11300,11 @@ } } }, + "classnames": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz", + "integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==" + }, "clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", @@ -14341,6 +14388,32 @@ "resolved": "https://registry.npmjs.org/raf-schd/-/raf-schd-4.0.3.tgz", "integrity": "sha512-tQkJl2GRWh83ui2DiPTJz9wEiMN20syf+5oKfB03yYP7ioZcJwsIK8FjrtLwH1m7C7e+Tt2yYBlrOpdT+dyeIQ==" }, + "rc-slider": { + "version": "10.5.0", + "resolved": "https://registry.npmjs.org/rc-slider/-/rc-slider-10.5.0.tgz", + "integrity": "sha512-xiYght50cvoODZYI43v3Ylsqiw14+D7ELsgzR40boDZaya1HFa1Etnv9MDkQE8X/UrXAffwv2AcNAhslgYuDTw==", + "requires": { + "@babel/runtime": "^7.10.1", + "classnames": "^2.2.5", + "rc-util": "^5.27.0" + } + }, + "rc-util": { + "version": "5.39.1", + "resolved": "https://registry.npmjs.org/rc-util/-/rc-util-5.39.1.tgz", + "integrity": "sha512-OW/ERynNDgNr4y0oiFmtes3rbEamXw7GHGbkbNd9iRr7kgT03T6fT0b9WpJ3mbxKhyOcAHnGcIoh5u/cjrC2OQ==", + "requires": { + "@babel/runtime": "^7.18.3", + "react-is": "^18.2.0" + }, + "dependencies": { + "react-is": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", + "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==" + } + } + }, "react": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", diff --git a/package.json b/package.json index 08058490..00584e79 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ }, "dependencies": { "@gravity-ui/icons": "^2.5.0", - "@gravity-ui/uikit": "6.0.0", + "@gravity-ui/uikit": "^6.2.0", "@popperjs/core": "^2.11.2", "bem-cn-lite": "4.1.0", "i18next": "^19.9.2", diff --git a/src/components/DocContentPage/DocContentPage.tsx b/src/components/DocContentPage/DocContentPage.tsx new file mode 100644 index 00000000..e6e83c4b --- /dev/null +++ b/src/components/DocContentPage/DocContentPage.tsx @@ -0,0 +1,59 @@ +import React from 'react'; + +import block from 'bem-cn-lite'; + +import {DEFAULT_SETTINGS} from '../../constants'; +import {DocContentPageData, Router} from '../../models'; +import {DocLayout} from '../DocLayout'; + +const b = block('dc-doc-page'); + +const {wideFormat: defaultWideFormat} = DEFAULT_SETTINGS; + +export interface DocContentPageProps extends DocContentPageData { + router: Router; + headerHeight?: number; + wideFormat?: boolean; + hideTocHeader?: boolean; + hideToc?: boolean; + tocTitleIcon?: React.ReactNode; +} + +export const DocContentPage: React.FC = ({ + data, + toc, + router, + headerHeight, + wideFormat = defaultWideFormat, + hideTocHeader, + hideToc, + tocTitleIcon, + footer, + children, +}) => { + const modes = { + 'regular-page-width': !wideFormat, + }; + + return ( + + +
+
{children}
+
+
+
+ ); +}; diff --git a/src/components/DocContentPage/index.ts b/src/components/DocContentPage/index.ts new file mode 100644 index 00000000..a165865b --- /dev/null +++ b/src/components/DocContentPage/index.ts @@ -0,0 +1 @@ +export * from './DocContentPage'; diff --git a/src/index.ts b/src/index.ts index 09e61511..32883e69 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,7 +23,9 @@ export * from './components/ErrorBoundary'; export * from './components/Paginator'; export * from './components/SearchItem'; export * from './components/SearchPage'; +export * from './components/DocContentPage'; export * from './config'; export * from './models'; export * from './constants'; +export * from './utils'; diff --git a/src/models/index.ts b/src/models/index.ts index d17a69a2..ee2b8e6c 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -48,6 +48,14 @@ export interface DocLeadingPageData extends DocBasePageData { data: DocLeadingData; } +export interface DocContentPageData extends DocBasePageData { + leading: true; + data: { + fullScreen?: boolean; + }; + children?: React.ReactNode; +} + export interface DocLeadingData { title: string; description: string | string[]; @@ -176,3 +184,9 @@ export interface SubscribeData { email: string; type: SubscribeType; } + +export enum DocumentType { + Base = 'BASE', + Leading = 'LEADING', + PageConstructor = 'PAGE_CONSTRUCTOR', +} diff --git a/src/utils/index.ts b/src/utils/index.ts index c95e0f75..ef3a21d5 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -2,8 +2,18 @@ import {parse} from 'url'; import {ThemeContextProps} from '@gravity-ui/uikit'; +import {DocContentPage} from '../components/DocContentPage'; +import {DocLeadingPage} from '../components/DocLeadingPage'; +import {DocPage} from '../components/DocPage'; import {PopperPosition} from '../hooks'; -import {Contributor, Router} from '../models'; +import { + Contributor, + DocContentPageData, + DocLeadingPageData, + DocPageData, + DocumentType, + Router, +} from '../models'; export type InnerProps, TDefaultProps> = Omit< TProps, @@ -97,3 +107,26 @@ export const getPopupPosition = ( return isVerticalView ? PopperPosition.LEFT_START : PopperPosition.BOTTOM_END; }; + +export function getPageByType(type: DocumentType) { + const PageTypes = { + [DocumentType.Base]: DocPage, + [DocumentType.Leading]: DocLeadingPage, + [DocumentType.PageConstructor]: DocContentPage, + }; + + return PageTypes[type] || null; +} + +export function getPageType({ + data, + leading, +}: DocLeadingPageData | (DocPageData & {data?: undefined}) | DocContentPageData): DocumentType { + if (leading && data) { + return Object.prototype.hasOwnProperty.call(data, 'links') + ? DocumentType.Leading + : DocumentType.PageConstructor; + } + + return DocumentType.Base; +}