@diplodoc/client 4.0.2 → 4.1.0

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.
@@ -2,11 +2,12 @@ import type { NavigationData, PageContent } from '@gravity-ui/page-constructor';
2
2
  import type { SearchConfig } from '../Search';
3
3
  import type { RouterConfig } from '../Router';
4
4
  import type { ReactElement } from 'react';
5
- import type { DocContentPageData as DocContentPageDataBase, DocLeadingPageData, DocPageData } from '@diplodoc/components';
5
+ import type { DocContentPageData as DocContentPageDataBase, DocLeadingPageData, DocPageData, NeuroExpert } from '@diplodoc/components';
6
6
  import { Lang } from '@diplodoc/components';
7
7
  import '@diplodoc/transform/dist/js/yfm';
8
8
  import '../../interceptors/leading-page-links';
9
9
  import './App.scss';
10
+ export type { NeuroExpert };
10
11
  export type DocAnalytics = {
11
12
  gtm?: {
12
13
  id?: string;
@@ -20,6 +21,7 @@ export interface AppProps {
20
21
  search?: SearchConfig;
21
22
  analytics?: DocAnalytics;
22
23
  viewerInterface?: Record<string, boolean>;
24
+ neuroExpert?: NeuroExpert;
23
25
  }
24
26
  export type WithNavigation = {
25
27
  navigation?: NavigationData;
package/build/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { DocAnalytics, DocInnerProps, DocLeadingPageData, DocPageData } from './components/App';
2
- export type { DocInnerProps, DocPageData, DocLeadingPageData, DocAnalytics };
1
+ import type { DocAnalytics, DocInnerProps, DocLeadingPageData, DocPageData, NeuroExpert } from './components/App';
2
+ export type { DocInnerProps, DocPageData, DocLeadingPageData, DocAnalytics, NeuroExpert };
3
3
  export type { SearchConfig as ISearchProviderConfig, WorkerConfig as ISearchWorkerConfig, WorkerApi as ISearchWorkerApi, } from './components/Search';
@@ -24,6 +24,8 @@ var react = __webpack_require__(67294);
24
24
  var server_node = __webpack_require__(9680);
25
25
  // EXTERNAL MODULE: ./node_modules/@swc/helpers/esm/_object_spread_props.js
26
26
  var _object_spread_props = __webpack_require__(99282);
27
+ // EXTERNAL MODULE: ./node_modules/@swc/helpers/esm/_sliced_to_array.js + 3 modules
28
+ var esm_sliced_to_array = __webpack_require__(24460);
27
29
  // EXTERNAL MODULE: ./node_modules/@gravity-ui/uikit/build/esm/components/theme/ThemeProvider.js + 7 modules
28
30
  var theme_ThemeProvider = __webpack_require__(12956);
29
31
  // EXTERNAL MODULE: ./node_modules/@diplodoc/components/build/esm/constants.js
@@ -38,6 +40,10 @@ var InterfaceContext = __webpack_require__(7481);
38
40
  var RenderBodyHooksContext = __webpack_require__(65848);
39
41
  // EXTERNAL MODULE: ./node_modules/@diplodoc/components/build/esm/components/ConsentPopup/ConsentPopup.js + 47 modules
40
42
  var ConsentPopup = __webpack_require__(74311);
43
+ // EXTERNAL MODULE: ./node_modules/@diplodoc/components/build/esm/components/Widgets/Widgets.js + 1 modules
44
+ var Widgets = __webpack_require__(24362);
45
+ // EXTERNAL MODULE: ./node_modules/@diplodoc/components/build/esm/components/NeuroExpertWidget/NeuroExpertWidget.js + 1 modules
46
+ var NeuroExpertWidget = __webpack_require__(42540);
41
47
  // EXTERNAL MODULE: ./node_modules/@diplodoc/transform/dist/js/yfm.js
42
48
  var yfm = __webpack_require__(68648);
43
49
  ;// CONCATENATED MODULE: ./src/components/Router/index.ts
@@ -291,11 +297,49 @@ function scrollToHash() {
291
297
  scrollToElement(element);
292
298
  }, 10);
293
299
  }
300
+ var NEURO_EXPERT_PARENT_ID = 'neuro-expert-widget';
301
+ function getNeuroExpertSettings(lang, neuroExpert, isInternal) {
302
+ var _neuroExpert_projectId, _neuroExpert_projectId1;
303
+ var _neuroExpert_projectId_lang, _ref;
304
+ var projectId = (_ref = (_neuroExpert_projectId_lang = neuroExpert === null || neuroExpert === void 0 ? void 0 : (_neuroExpert_projectId = neuroExpert.projectId) === null || _neuroExpert_projectId === void 0 ? void 0 : _neuroExpert_projectId[lang]) !== null && _neuroExpert_projectId_lang !== void 0 ? _neuroExpert_projectId_lang : neuroExpert === null || neuroExpert === void 0 ? void 0 : (_neuroExpert_projectId1 = neuroExpert.projectId) === null || _neuroExpert_projectId1 === void 0 ? void 0 : _neuroExpert_projectId1.default) !== null && _ref !== void 0 ? _ref : undefined;
305
+ if (!projectId || projectId === 'none') {
306
+ return undefined;
307
+ }
308
+ var _neuroExpert_hasOutsideClick, _neuroExpert_parentId;
309
+ var settings = {
310
+ projectId: projectId,
311
+ hasOutsideClick: (_neuroExpert_hasOutsideClick = neuroExpert.hasOutsideClick) !== null && _neuroExpert_hasOutsideClick !== void 0 ? _neuroExpert_hasOutsideClick : true,
312
+ isInternal: isInternal,
313
+ parentId: (_neuroExpert_parentId = neuroExpert.parentId) !== null && _neuroExpert_parentId !== void 0 ? _neuroExpert_parentId : NEURO_EXPERT_PARENT_ID
314
+ };
315
+ return settings;
316
+ }
317
+ function renderNeuroExpertWidget(lang, setParentId, neuroExpert) {
318
+ var isInternal = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false;
319
+ if (!neuroExpert || neuroExpert.disabled) {
320
+ setParentId(null);
321
+ return;
322
+ }
323
+ var neScriptUrl = 'https://yastatic.net/s3/distribution/stardust/neuroexpert-widget/production/neuroexpert-widget.js';
324
+ var settings = getNeuroExpertSettings(lang, neuroExpert, isInternal);
325
+ if (!settings) {
326
+ setParentId(null);
327
+ return;
328
+ }
329
+ setParentId(settings.parentId);
330
+ var script = document.createElement('script');
331
+ script.type = 'module';
332
+ script.src = neScriptUrl;
333
+ script.onload = function() {
334
+ if (typeof window['initNeuroexpert'] === 'function') {
335
+ window['initNeuroexpert'](settings);
336
+ }
337
+ };
338
+ document.body.appendChild(script);
339
+ }
294
340
 
295
341
  // EXTERNAL MODULE: ./node_modules/@swc/helpers/esm/_define_property.js
296
342
  var _define_property = __webpack_require__(27412);
297
- // EXTERNAL MODULE: ./node_modules/@swc/helpers/esm/_sliced_to_array.js + 3 modules
298
- var esm_sliced_to_array = __webpack_require__(24460);
299
343
  ;// CONCATENATED MODULE: ./src/components/App/useSettings.ts
300
344
 
301
345
 
@@ -1438,15 +1482,17 @@ var withMdxInit = function(param) {
1438
1482
 
1439
1483
 
1440
1484
 
1485
+
1441
1486
 
1442
1487
  function App(props) {
1443
1488
  var _analytics_gtm, _analytics_gtm1;
1444
- var data = props.data, router = props.router, lang = props.lang, langs = props.langs, search = props.search, analytics = props.analytics, viewerInterface = props.viewerInterface;
1489
+ var data = props.data, router = props.router, lang = props.lang, langs = props.langs, search = props.search, analytics = props.analytics, viewerInterface = props.viewerInterface, neuroExpert = props.neuroExpert;
1445
1490
  var settings = useSettings_useSettings();
1446
1491
  var langData = useLangs(props);
1447
1492
  var mobileView = useMobile_useMobile();
1448
1493
  var availableLangs = useAvailableLangs(data, langs);
1449
1494
  var fixedLang = constants/* .SUPPORTED_LANGS.includes */.aP.includes(lang) ? lang : models/* .Lang.En */.Uo.En;
1495
+ var _useState = (0,esm_sliced_to_array._)((0,react.useState)(), 2), parentId = _useState[0], setParentId = _useState[1];
1450
1496
  (0,esm_config/* .configure */.jQ)({
1451
1497
  lang: fixedLang,
1452
1498
  localeCode: fixedLang
@@ -1506,13 +1552,16 @@ function App(props) {
1506
1552
  utils_updateThemeClassName({
1507
1553
  theme: theme
1508
1554
  });
1555
+ renderNeuroExpertWidget(lang, setParentId, neuroExpert);
1509
1556
  scrollToHash();
1510
1557
  }, [
1511
1558
  theme,
1512
1559
  mobileView,
1513
1560
  wideFormat,
1514
1561
  fullScreen,
1515
- landingPage
1562
+ landingPage,
1563
+ lang,
1564
+ neuroExpert
1516
1565
  ]);
1517
1566
  return /*#__PURE__*/ (0,jsx_runtime.jsx)("div", {
1518
1567
  className: "App",
@@ -1541,6 +1590,11 @@ function App(props) {
1541
1590
  gtmId: (analytics === null || analytics === void 0 ? void 0 : (_analytics_gtm = analytics.gtm) === null || _analytics_gtm === void 0 ? void 0 : _analytics_gtm.id) || '',
1542
1591
  consentMode: analytics === null || analytics === void 0 ? void 0 : (_analytics_gtm1 = analytics.gtm) === null || _analytics_gtm1 === void 0 ? void 0 : _analytics_gtm1.mode
1543
1592
  }),
1593
+ /*#__PURE__*/ (0,jsx_runtime.jsx)(Widgets/* ["default"] */.Z, {
1594
+ children: parentId && /*#__PURE__*/ (0,jsx_runtime.jsx)(NeuroExpertWidget/* ["default"] */.Z, {
1595
+ parentId: parentId
1596
+ })
1597
+ }),
1544
1598
  /*#__PURE__*/ (0,jsx_runtime.jsx)(Runtime, {})
1545
1599
  ]
1546
1600
  })