@diplodoc/client 3.12.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,8 @@
1
- import type { PropsWithChildren } from 'react';
2
- import type { AppProps, PageData, WithNavigation } from './index';
1
+ import type { AppProps, PageData } from './index';
3
2
  import type { Settings } from '../../utils';
4
3
  import type { DocBasePageData } from '@diplodoc/components';
5
4
  import type { Props as HeaderControlsProps } from '../HeaderControls';
6
5
  import React from 'react';
7
- type Props = PropsWithChildren<Partial<AppProps> & {
8
- data: PageData;
9
- headerHeight: number;
10
- }>;
11
- export declare function Page({ data, ...pageProps }: Props): React.JSX.Element;
12
6
  type PageProps<T extends {} = {}> = {
13
7
  data: DocBasePageData<T> & PageData;
14
8
  props: {
@@ -16,6 +10,5 @@ type PageProps<T extends {} = {}> = {
16
10
  } & Settings;
17
11
  controls: HeaderControlsProps;
18
12
  };
19
- export declare function LegacyNavPage({ data, props, controls }: PageProps): React.JSX.Element;
20
- export declare function RichNavPage({ data, props, controls }: PageProps<WithNavigation>): React.JSX.Element;
13
+ export declare function Page({ data, props, controls }: PageProps): React.JSX.Element;
21
14
  export {};
@@ -22,7 +22,7 @@ export interface AppProps {
22
22
  viewerInterface?: Record<string, boolean>;
23
23
  }
24
24
  export type WithNavigation = {
25
- navigation: NavigationData;
25
+ navigation?: NavigationData;
26
26
  };
27
27
  export type DocContentPageData = DocContentPageDataBase<PageContent>;
28
28
  export type PageData = DocPageData | DocLeadingPageData | DocContentPageData;
@@ -16,6 +16,8 @@ export declare const useNavigation: (data: DocBasePageData<WithNavigation>, cont
16
16
  renderNavigation: () => React.JSX.Element;
17
17
  logo: {
18
18
  icon: import("@gravity-ui/page-constructor").ImageProps;
19
+ } | {
20
+ icon: import("@gravity-ui/page-constructor").ImageProps;
19
21
  text?: string;
20
22
  url?: string;
21
23
  urlTitle?: string;
@@ -28,6 +30,6 @@ export declare const useNavigation: (data: DocBasePageData<WithNavigation>, cont
28
30
  alt?: string;
29
31
  light: import("@gravity-ui/page-constructor").NavigationLogoData;
30
32
  };
31
- };
33
+ } | undefined;
32
34
  withControls: boolean;
33
35
  };
@@ -253,8 +253,18 @@ function isHeaderTag(el) {
253
253
  }
254
254
  }
255
255
  function getLangPath(lang, href) {
256
- var path = href.replace(/^https?:\/\/[^/]+/, '').replace(/^\/[a-z]{2}\//, '/');
257
- return "".concat(lang).concat(path);
256
+ var path;
257
+ var isLocal = href.match(/^file:\/\/\/(.*)$/);
258
+ if (isLocal) {
259
+ path = '/' + isLocal[1];
260
+ } else {
261
+ path = href.replace(/^https?:\/\/[^/]+/, '');
262
+ }
263
+ var newPath = path.replace(/\/[a-z]{2}\//, "/".concat(lang, "/"));
264
+ if (isLocal) {
265
+ return 'file://' + newPath;
266
+ }
267
+ return newPath;
258
268
  }
259
269
  function isInViewport(el) {
260
270
  var rect = el.getBoundingClientRect();
@@ -787,8 +797,6 @@ function useSearch() {
787
797
 
788
798
  // EXTERNAL MODULE: ./src/interceptors/leading-page-links.js
789
799
  var leading_page_links = __webpack_require__(90101);
790
- // EXTERNAL MODULE: ./node_modules/@swc/helpers/esm/_object_without_properties.js + 1 modules
791
- var _object_without_properties = __webpack_require__(98848);
792
800
  // EXTERNAL MODULE: ./node_modules/@gravity-ui/page-constructor/build/esm/containers/PageConstructor/Provider.js
793
801
  var Provider = __webpack_require__(77725);
794
802
  // EXTERNAL MODULE: ./node_modules/@gravity-ui/page-constructor/build/esm/containers/PageConstructor/PageConstructor.js + 18 modules
@@ -1067,11 +1075,15 @@ function findItem(right, left, type) {
1067
1075
  return item.type === type;
1068
1076
  });
1069
1077
  }
1078
+ var EmptyNavigation = {};
1079
+ var EmptyHeader = {};
1080
+ var EmptyLeftItems = [];
1081
+ var EmptyRightItems = [];
1070
1082
  var useNavigation = function(data, controls, CustomControls, CustomSuggest, viewerInterface) {
1071
1083
  var toc = data.toc;
1072
- var navigation = toc.navigation;
1073
- var _navigation_header = navigation.header, header = _navigation_header === void 0 ? {} : _navigation_header, logo = navigation.logo;
1074
- var _header_leftItems = header.leftItems, leftItems = _header_leftItems === void 0 ? [] : _header_leftItems, _header_rightItems = header.rightItems, rightItems = _header_rightItems === void 0 ? [] : _header_rightItems;
1084
+ var navigation = toc.navigation || EmptyNavigation;
1085
+ var _navigation_header = navigation.header, header = _navigation_header === void 0 ? EmptyHeader : _navigation_header, logo = navigation.logo;
1086
+ var _header_leftItems = header.leftItems, leftItems = _header_leftItems === void 0 ? EmptyLeftItems : _header_leftItems, _header_rightItems = header.rightItems, rightItems = _header_rightItems === void 0 ? EmptyRightItems : _header_rightItems;
1075
1087
  var withControls = findItem(rightItems, leftItems, 'controls');
1076
1088
  var withSearch = findItem(rightItems, leftItems, 'search');
1077
1089
  var search = useSearch();
@@ -1118,7 +1130,7 @@ var useNavigation = function(data, controls, CustomControls, CustomSuggest, view
1118
1130
  ]);
1119
1131
  var layout = (0,react.useMemo)(function() {
1120
1132
  var _logo_icon;
1121
- return {
1133
+ return EmptyNavigation === navigation ? undefined : {
1122
1134
  header: {
1123
1135
  leftItems: []
1124
1136
  },
@@ -1141,7 +1153,8 @@ var useNavigation = function(data, controls, CustomControls, CustomSuggest, view
1141
1153
  navigationData,
1142
1154
  navigationTocData,
1143
1155
  mobileControlsData,
1144
- logo
1156
+ logo,
1157
+ navigation
1145
1158
  ]);
1146
1159
  var config = (0,react.useMemo)(function() {
1147
1160
  return {
@@ -1175,58 +1188,11 @@ var useNavigation = function(data, controls, CustomControls, CustomSuggest, view
1175
1188
 
1176
1189
 
1177
1190
 
1178
-
1179
- function App_Page_Page(_param) {
1180
- var data = _param.data, pageProps = (0,_object_without_properties._)(_param, [
1181
- "data"
1182
- ]);
1183
- var type = (0,utils/* .getPageType */.C2)(data);
1184
- var Page = (0,utils/* .getPageByType */.N7)(type);
1185
- return /*#__PURE__*/ (0,jsx_runtime.jsx)(Layout, {
1186
- headerHeight: pageProps.headerHeight,
1187
- children: /*#__PURE__*/ (0,jsx_runtime.jsx)(Layout.Content, {
1188
- children: /*#__PURE__*/ (0,jsx_runtime.jsx)(Page, (0,_object_spread._)({}, data, pageProps))
1189
- })
1190
- });
1191
- }
1192
- function LegacyNavPage(param) {
1193
- var data = param.data, props = param.props, controls = param.controls;
1194
- var theme = props.theme;
1195
- var CustomPage = (0,react.useCallback)(function() {
1196
- return /*#__PURE__*/ (0,jsx_runtime.jsx)(ConstructorPage, (0,_object_spread._)({}, data.data));
1197
- }, [
1198
- data
1199
- ]);
1200
- var content = useContent(data, CustomPage);
1201
- var custom = (0,react.useMemo)(function() {
1202
- return {
1203
- blocks: content.custom
1204
- };
1205
- }, [
1206
- content
1207
- ]);
1208
- return /*#__PURE__*/ (0,jsx_runtime.jsx)(App_Page_Page, (0,_object_spread_props._)((0,_object_spread._)({
1209
- data: data,
1210
- headerHeight: 0
1211
- }, props, controls), {
1212
- children: /*#__PURE__*/ (0,jsx_runtime.jsx)(Provider/* .PageConstructorProvider */.W, {
1213
- theme: theme,
1214
- projectSettings: {
1215
- disableCompress: true
1216
- },
1217
- ssrConfig: {
1218
- isServer: Boolean(false)
1219
- },
1220
- children: /*#__PURE__*/ (0,jsx_runtime.jsx)(PageConstructor/* .PageConstructor */.C, {
1221
- custom: custom,
1222
- content: content.layout
1223
- })
1224
- })
1225
- }));
1226
- }
1227
- function RichNavPage(param) {
1191
+ function App_Page_Page(param) {
1228
1192
  var data = param.data, props = param.props, controls = param.controls;
1229
1193
  var theme = props.theme, fullScreen = props.fullScreen;
1194
+ var type = (0,utils/* .getPageType */.C2)(data);
1195
+ var Page = (0,utils/* .getPageByType */.N7)(type);
1230
1196
  var CustomSuggest = (0,react.useCallback)(function() {
1231
1197
  return /*#__PURE__*/ (0,jsx_runtime.jsx)(Suggest, {});
1232
1198
  }, []);
@@ -1237,29 +1203,32 @@ function RichNavPage(param) {
1237
1203
  ]);
1238
1204
  var navigation = useNavigation(data, controls, CustomControls, CustomSuggest);
1239
1205
  var CustomPage = (0,react.useCallback)(function() {
1240
- return /*#__PURE__*/ (0,jsx_runtime.jsx)(App_Page_Page, (0,_object_spread_props._)((0,_object_spread._)({
1241
- data: data,
1242
- headerHeight: fullScreen ? 0 : 64
1243
- }, props, navigation.withControls ? filterControls(controls, [
1244
- 'theme',
1245
- 'onChangeTheme',
1246
- 'textSize',
1247
- 'onChangeTextSize',
1248
- 'wideFormat',
1249
- 'onChangeWideFormat',
1250
- 'showMiniToc',
1251
- 'onChangeShowMiniToc',
1252
- 'langs',
1253
- 'onChangeLang'
1254
- ]) : controls), {
1255
- children: /*#__PURE__*/ (0,jsx_runtime.jsx)(ConstructorPage, (0,_object_spread._)({}, data.data))
1256
- }));
1206
+ return /*#__PURE__*/ (0,jsx_runtime.jsx)(Layout, {
1207
+ headerHeight: fullScreen || !navigation.layout ? 0 : 64,
1208
+ children: /*#__PURE__*/ (0,jsx_runtime.jsx)(Layout.Content, {
1209
+ children: /*#__PURE__*/ (0,jsx_runtime.jsx)(Page, (0,_object_spread_props._)((0,_object_spread._)({}, data, props, navigation.withControls ? filterControls(controls, [
1210
+ 'theme',
1211
+ 'onChangeTheme',
1212
+ 'textSize',
1213
+ 'onChangeTextSize',
1214
+ 'wideFormat',
1215
+ 'onChangeWideFormat',
1216
+ 'showMiniToc',
1217
+ 'onChangeShowMiniToc',
1218
+ 'langs',
1219
+ 'onChangeLang'
1220
+ ]) : controls), {
1221
+ children: /*#__PURE__*/ (0,jsx_runtime.jsx)(ConstructorPage, (0,_object_spread._)({}, data.data))
1222
+ }))
1223
+ })
1224
+ });
1257
1225
  }, [
1258
1226
  data,
1259
1227
  navigation,
1260
1228
  props,
1261
1229
  controls,
1262
- fullScreen
1230
+ fullScreen,
1231
+ Page
1263
1232
  ]);
1264
1233
  var content = useContent(data, CustomPage);
1265
1234
  var custom = (0,react.useMemo)(function() {
@@ -1470,9 +1439,6 @@ var withMdxInit = function(param) {
1470
1439
 
1471
1440
 
1472
1441
 
1473
- function hasNavigation(data) {
1474
- return Boolean(data.toc.navigation);
1475
- }
1476
1442
  function App(props) {
1477
1443
  var _analytics_gtm, _analytics_gtm1;
1478
1444
  var data = props.data, router = props.router, lang = props.lang, langs = props.langs, search = props.search, analytics = props.analytics, viewerInterface = props.viewerInterface;
@@ -1564,11 +1530,7 @@ function App(props) {
1564
1530
  children: [
1565
1531
  /*#__PURE__*/ (0,jsx_runtime.jsx)(RenderBodyHooksContext/* .RenderBodyHooksContext.Provider */.Y.Provider, {
1566
1532
  value: renderHooks,
1567
- children: hasNavigation(data) ? /*#__PURE__*/ (0,jsx_runtime.jsx)(RichNavPage, {
1568
- data: data,
1569
- props: page,
1570
- controls: controls
1571
- }) : /*#__PURE__*/ (0,jsx_runtime.jsx)(LegacyNavPage, {
1533
+ children: /*#__PURE__*/ (0,jsx_runtime.jsx)(App_Page_Page, {
1572
1534
  data: data,
1573
1535
  props: page,
1574
1536
  controls: controls