tycho-components 0.8.21 → 0.8.23

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.
@@ -17,7 +17,8 @@ type Props = {
17
17
  navigateHome?: () => void;
18
18
  navigateCorpora?: (uid: string) => void;
19
19
  navigateLogout?: () => void;
20
+ navigateNotLogged?: () => void;
20
21
  helpActions?: HelpAction[];
21
22
  };
22
- export default function Header({ tool, redirect, autoload, freeAccess, hideKeyboard, hideReplaceAll, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, helpActions, }: Props): import("react/jsx-runtime").JSX.Element;
23
+ export default function Header({ tool, redirect, autoload, freeAccess, hideKeyboard, hideReplaceAll, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, navigateNotLogged, helpActions, }: Props): import("react/jsx-runtime").JSX.Element;
23
24
  export {};
@@ -14,16 +14,15 @@ import HeaderReplaceAll from './HeaderReplaceAll';
14
14
  import HeaderUser from './HeaderUser';
15
15
  import HelpButton from './HelpButton';
16
16
  import './styles.scss';
17
- export default function Header({ tool, redirect, autoload, freeAccess, hideKeyboard, hideReplaceAll, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, helpActions, }) {
17
+ export default function Header({ tool, redirect, autoload, freeAccess, hideKeyboard, hideReplaceAll, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, navigateNotLogged = () => {
18
+ location.href = '/auth';
19
+ }, helpActions, }) {
18
20
  const { t } = useTranslation('header');
19
21
  const { getCorpus, hasCorpus } = useCorpusUtils();
20
22
  const { isLogged } = useLoggedUtils();
21
23
  const [openKeyboard, setOpenKeyboard] = useState(false);
22
- const profileClass = cx('header-profile', {
23
- 'corpora-free': freeAccess && !hasCorpus(),
24
- });
25
24
  const homeTextsClass = cx('app-title', {
26
25
  pointer: navigateHome !== undefined,
27
26
  });
28
- return (_jsxs("div", { className: "ds-header", children: [_jsxs("div", { className: "header-left", children: [_jsx(HeaderApps, { freeAccess: freeAccess }), _jsxs("div", { className: homeTextsClass, onClick: () => navigateHome && navigateHome(), children: [_jsx("span", { className: "title", children: t('label.platform') }), _jsx("span", { className: "subtitle", children: tool })] })] }), customHeader, !customHeader && (_jsx(HeaderCorpora, { redirect: redirect, autoload: autoload, freeAccess: freeAccess, navigateCorpora: navigateCorpora })), _jsxs("div", { className: profileClass, children: [!hideReplaceAll && _jsx(HeaderReplaceAll, {}), !hideKeyboard && (_jsx(IconButton, { onClick: () => setOpenKeyboard(!openKeyboard), name: "keyboard", size: "medium", title: t('tooltip.keyboard') })), _jsx(HelpButton, { helpActions: helpActions }), notifications && isLogged() && (_jsx(HeaderNotifications, { uid: notifications.ref, mode: notifications.mode })), _jsx(LanguageSelector, {}), !freeAccess && _jsx(HeaderUser, { navigateLogout: navigateLogout })] }), openKeyboard && (_jsx(VirtualKeyboard, { onClose: () => setOpenKeyboard(false), closeLabel: t('button.close'), defaultLayout: keyboardLayout || getCorpus().keyboardLayout || 'english' }))] }));
27
+ return (_jsxs("div", { className: "ds-header", children: [_jsxs("div", { className: "header-left", children: [_jsx(HeaderApps, { freeAccess: freeAccess }), _jsxs("div", { className: homeTextsClass, onClick: () => navigateHome && navigateHome(), children: [_jsx("span", { className: "title", children: t('label.platform') }), _jsx("span", { className: "subtitle", children: tool })] })] }), customHeader, !customHeader && (_jsx(HeaderCorpora, { redirect: redirect, autoload: autoload, freeAccess: freeAccess, navigateCorpora: navigateCorpora })), _jsxs("div", { className: "header-right", children: [!hideReplaceAll && _jsx(HeaderReplaceAll, {}), !hideKeyboard && (_jsx(IconButton, { onClick: () => setOpenKeyboard(!openKeyboard), name: "keyboard", size: "medium", title: t('tooltip.keyboard') })), _jsx(HelpButton, { helpActions: helpActions }), notifications && isLogged() && (_jsx(HeaderNotifications, { uid: notifications.ref, mode: notifications.mode })), _jsx(LanguageSelector, {}), !freeAccess && (_jsx(HeaderUser, { navigateLogout: navigateLogout, navigateNotLogged: navigateNotLogged }))] }), openKeyboard && (_jsx(VirtualKeyboard, { onClose: () => setOpenKeyboard(false), closeLabel: t('button.close'), defaultLayout: keyboardLayout || getCorpus().keyboardLayout || 'english' }))] }));
29
28
  }
@@ -15,12 +15,17 @@ export default function HeaderCorpora({ navigateCorpora, redirect, autoload, fre
15
15
  const [corpora, setCorpora] = useState([]);
16
16
  const [openCorpora, setOpenCorpora] = useState(false);
17
17
  const load = () => {
18
- CorpusService.available().then((r) => {
18
+ CorpusService.available()
19
+ .then((r) => {
19
20
  setCorpora(r.data);
21
+ })
22
+ .catch(() => {
23
+ setCorpora([]);
20
24
  });
21
25
  };
22
26
  const loadAndApply = () => {
23
- CorpusService.available().then((r) => {
27
+ CorpusService.available()
28
+ .then((r) => {
24
29
  setCorpora(r.data);
25
30
  if (uid) {
26
31
  const selectedCorpus = r.data.find((c) => c.uid === uid);
@@ -35,6 +40,9 @@ export default function HeaderCorpora({ navigateCorpora, redirect, autoload, fre
35
40
  navigateCorpora && navigateCorpora(r.data[0].uid);
36
41
  setCorpus(r.data[0]);
37
42
  }
43
+ })
44
+ .catch(() => {
45
+ setCorpora([]);
38
46
  });
39
47
  };
40
48
  const handleChooseCorpus = (thisCorpus) => {
@@ -1,6 +1,7 @@
1
1
  import './style.scss';
2
2
  type Props = {
3
3
  navigateLogout?: () => void;
4
+ navigateNotLogged: () => void;
4
5
  };
5
- export default function HeaderUser({ navigateLogout }: Props): import("react/jsx-runtime").JSX.Element;
6
+ export default function HeaderUser({ navigateLogout, navigateNotLogged, }: Props): import("react/jsx-runtime").JSX.Element;
6
7
  export {};
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
4
4
  import { Avatar, Icon, ProfileDropdown } from 'tycho-storybook';
5
5
  import { useLoggedUtils } from '../../configs/useLoggedUtils';
6
6
  import './style.scss';
7
- export default function HeaderUser({ navigateLogout }) {
7
+ export default function HeaderUser({ navigateLogout, navigateNotLogged, }) {
8
8
  const { t } = useTranslation('header');
9
9
  const { isLogged, getLogged } = useLoggedUtils();
10
10
  const [open, setOpen] = useState(false);
@@ -12,7 +12,7 @@ export default function HeaderUser({ navigateLogout }) {
12
12
  setOpen(false);
13
13
  window.open(import.meta.env.VITE_APP_RESERVED_URL, '_blank');
14
14
  };
15
- return (_jsxs("div", { className: "header-user-container", children: [isLogged() ? (_jsx(ProfileDropdown, { src: getLogged()?.picture, title: getLogged()?.name || getLogged()?.sub, onClick: (b) => setOpen(b) })) : (_jsx(Avatar, { size: "small", onClick: () => (location.href = '/auth') })), open && isLogged() && (_jsxs("div", { className: "ds-dropdown-list", children: [_jsx("div", { className: "ds-dropdown-itemlist", children: _jsx("span", { className: "label", children: `${t('profile.label.hello')} ${getLogged()?.name || getLogged()?.sub}` }) }), _jsxs("div", { className: "ds-dropdown-itemlist d-none", children: [_jsx(Icon, { name: "colors", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.theme') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: handleProfile, children: [_jsx(Icon, { name: "person", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.home') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", children: [_jsx(Icon, { name: "live_help", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.help') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: () => {
15
+ return (_jsxs("div", { className: "header-user-container", children: [isLogged() ? (_jsx(ProfileDropdown, { src: getLogged()?.picture, title: getLogged()?.name || getLogged()?.sub, onClick: (b) => setOpen(b) })) : (_jsx(Avatar, { size: "small", onClick: navigateNotLogged })), open && isLogged() && (_jsxs("div", { className: "ds-dropdown-list", children: [_jsx("div", { className: "ds-dropdown-itemlist", children: _jsx("span", { className: "label", children: `${t('profile.label.hello')} ${getLogged()?.name || getLogged()?.sub}` }) }), _jsxs("div", { className: "ds-dropdown-itemlist d-none", children: [_jsx(Icon, { name: "colors", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.theme') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: handleProfile, children: [_jsx(Icon, { name: "person", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.home') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", children: [_jsx(Icon, { name: "live_help", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.help') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: () => {
16
16
  setOpen(false);
17
17
  navigateLogout && navigateLogout();
18
18
  }, children: [_jsx(Icon, { name: "logout", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.logout') })] })] }))] }));
@@ -31,13 +31,10 @@
31
31
  }
32
32
  }
33
33
 
34
- > .header-profile {
34
+ .header-right {
35
35
  display: flex;
36
36
  align-items: center;
37
37
  padding-right: var(--spacing-150);
38
-
39
- &.corpora-free {
40
- margin-left: auto;
41
- }
38
+ gap: 8px;
42
39
  }
43
40
  }
@@ -1,10 +1,8 @@
1
1
  .language-container {
2
2
  > .ds-dropdown-container {
3
3
  .ds-dropdown-button {
4
- padding-left: 8px;
5
-
6
4
  .label {
7
- margin-right: var(--spacing-100);
5
+ margin: 0px var(--spacing-100);
8
6
  }
9
7
  }
10
8
 
@@ -1,8 +1,8 @@
1
- import { Core } from 'cytoscape';
2
- import { Struct } from '../configs/types/Struct';
3
- import './style.scss';
1
+ import { Core } from "cytoscape";
2
+ import { Struct } from "../configs/types/Struct";
3
+ import "./style.scss";
4
4
  type Props = {
5
- struct: Struct;
5
+ struct?: Struct;
6
6
  expression?: string;
7
7
  selector?: string;
8
8
  translations?: Record<string, string>;
@@ -1,18 +1,18 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { saveAs } from 'file-saver';
3
- import html2canvas from 'html2canvas';
4
- import { useEffect, useState } from 'react';
5
- import { useTranslation } from 'react-i18next';
6
- import { IconButton } from 'tycho-storybook';
7
- import AppPlaceholder from '../AppPlaceholder';
8
- import DateUtils from '../functions/DateUtils';
9
- import SentenceUtils from '../functions/SentenceUtils';
10
- import TreeViewSearch from './TreeViewSearch/TreeViewSearch';
11
- import CytoscapeTreeConverter from './cytoscape/CytoscapeTreeConverter';
12
- import SyntreesCytoscape from './cytoscape/SyntreesCytoscape';
13
- import './style.scss';
14
- export default function TreeView({ struct, expression, selector = 'canvas-tree', translations, wheelSensitivity, renderWithInfo = false, placeholder, cyRef, onClickExpression, onExpand, onReadyCustom, }) {
15
- const { t } = useTranslation('tree');
2
+ import { saveAs } from "file-saver";
3
+ import html2canvas from "html2canvas";
4
+ import { useEffect, useState } from "react";
5
+ import { useTranslation } from "react-i18next";
6
+ import { IconButton } from "tycho-storybook";
7
+ import AppPlaceholder from "../AppPlaceholder";
8
+ import DateUtils from "../functions/DateUtils";
9
+ import SentenceUtils from "../functions/SentenceUtils";
10
+ import TreeViewSearch from "./TreeViewSearch/TreeViewSearch";
11
+ import CytoscapeTreeConverter from "./cytoscape/CytoscapeTreeConverter";
12
+ import SyntreesCytoscape from "./cytoscape/SyntreesCytoscape";
13
+ import "./style.scss";
14
+ export default function TreeView({ struct, expression, selector = "canvas-tree", translations, wheelSensitivity, renderWithInfo = false, placeholder, cyRef, onClickExpression, onExpand, onReadyCustom, }) {
15
+ const { t } = useTranslation("tree");
16
16
  const [cy, setCy] = useState(null);
17
17
  const [showInfo, setShowInfo] = useState(renderWithInfo);
18
18
  const [invalid, setInvalid] = useState();
@@ -27,7 +27,7 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
27
27
  setCy(null);
28
28
  const element = document.getElementById(selector);
29
29
  if (element)
30
- element.innerHTML = '';
30
+ element.innerHTML = "";
31
31
  if (!struct)
32
32
  return;
33
33
  let tree;
@@ -58,8 +58,8 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
58
58
  const downloadPsd = () => {
59
59
  if (!expression)
60
60
  return;
61
- const blob = new Blob([expression], { type: 'text/plain;charset=utf-8' });
62
- saveAs(blob, 'sentence.psd');
61
+ const blob = new Blob([expression], { type: "text/plain;charset=utf-8" });
62
+ saveAs(blob, "sentence.psd");
63
63
  };
64
64
  const generateImage = () => {
65
65
  if (!cy)
@@ -68,13 +68,13 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
68
68
  if (!cyContainer)
69
69
  return;
70
70
  html2canvas(cyContainer, {
71
- backgroundColor: 'white',
71
+ backgroundColor: "white",
72
72
  }).then((canvas) => {
73
73
  canvas.toBlob((blob) => {
74
74
  if (blob === null)
75
75
  return;
76
- saveAs(blob, 'tree.jpg');
77
- }, 'image/jpeg', 1.0);
76
+ saveAs(blob, "tree.jpg");
77
+ }, "image/jpeg", 1.0);
78
78
  });
79
79
  };
80
80
  const reset = () => {
@@ -90,9 +90,9 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
90
90
  if (!token.ec) {
91
91
  const leafId = token.p?.toString();
92
92
  const converter = new CytoscapeTreeConverter();
93
- converter['extraInfo'] = extraInfo;
93
+ converter["extraInfo"] = extraInfo;
94
94
  const newLabel = converter.getLabelLeaf(token);
95
- thisCy.$id(leafId).data('label', newLabel);
95
+ thisCy.$id(leafId).data("label", newLabel);
96
96
  }
97
97
  });
98
98
  };
@@ -113,8 +113,8 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
113
113
  setInvalid(undefined);
114
114
  load();
115
115
  }, [struct]);
116
- if (invalid) {
117
- return (_jsx(AppPlaceholder, { text: placeholder || t('placeholder.sentence.notparsed') }));
116
+ if (invalid || !struct) {
117
+ return (_jsx(AppPlaceholder, { text: placeholder || t("placeholder.sentence.notparsed") }));
118
118
  }
119
119
  return (_jsxs("div", { className: "tree-view-container", children: [_jsx("div", { className: "floating-buttons", children: cy &&
120
120
  getButtons(generateImage, reset, onClickExpression || downloadPsd, toggleInfo, onExpand, expression, openSearchModal)
@@ -122,43 +122,43 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
122
122
  .map((btn, i) => {
123
123
  return (_jsx(IconButton, { name: btn.icon, title: t(btn.title), onClick: btn.onClick, size: "small", mode: "ghost" }, i));
124
124
  }) }), showSearchModal && cy && (_jsx(TreeViewSearch, { struct: struct, cy: cy, onClose: closeSearchModal, searchCriteria: searchCriteria, setSearchCriteria: setSearchCriteria })), _jsx("div", { id: selector, className: "canvas-tree" }), showInfo && (_jsxs("div", { className: "info", children: [_jsx("span", { children: SentenceUtils.getAsText(struct) }), translations &&
125
- Object.entries(translations).map(([k, v]) => (_jsxs("div", { className: "translation", children: [_jsxs("b", { children: [k, ":"] }), _jsx("span", { children: v })] }, k))), struct.parsed && (_jsxs("span", { className: "date", children: [t('date.parsed'), ' ', DateUtils.formatDateTime(struct.parsed, 'dd/MM/yyyy HH:mm:ss')] }))] }))] }));
125
+ Object.entries(translations).map(([k, v]) => (_jsxs("div", { className: "translation", children: [_jsxs("b", { children: [k, ":"] }), _jsx("span", { children: v })] }, k))), struct.parsed && (_jsxs("span", { className: "date", children: [t("date.parsed"), " ", DateUtils.formatDateTime(struct.parsed, "dd/MM/yyyy HH:mm:ss")] }))] }))] }));
126
126
  }
127
127
  const getButtons = (generateImage, reset, downloadPsd, toggleInfo, onExpand, expression, openSearchModal) => [
128
128
  {
129
129
  condition: true,
130
- title: 'button.download.tree',
130
+ title: "button.download.tree",
131
131
  onClick: generateImage,
132
- icon: 'download',
132
+ icon: "download",
133
133
  },
134
134
  {
135
135
  condition: true,
136
- title: 'button.recenter.tree',
136
+ title: "button.recenter.tree",
137
137
  onClick: reset,
138
- icon: 'fullscreen',
138
+ icon: "fullscreen",
139
139
  },
140
140
  {
141
141
  condition: !!expression,
142
- title: 'button.download.penn',
142
+ title: "button.download.penn",
143
143
  onClick: downloadPsd,
144
- icon: 'graph_4',
144
+ icon: "graph_4",
145
145
  },
146
146
  {
147
147
  condition: !!onExpand,
148
- title: 'button.expand.tree',
148
+ title: "button.expand.tree",
149
149
  onClick: onExpand || (() => { }),
150
- icon: 'open_in_full',
150
+ icon: "open_in_full",
151
151
  },
152
152
  {
153
153
  condition: true,
154
- title: 'button.info',
154
+ title: "button.info",
155
155
  onClick: toggleInfo,
156
- icon: 'info',
156
+ icon: "info",
157
157
  },
158
158
  {
159
159
  condition: true,
160
- title: 'button.search',
160
+ title: "button.search",
161
161
  onClick: openSearchModal || (() => { }),
162
- icon: 'search',
162
+ icon: "search",
163
163
  },
164
164
  ];
@@ -9,14 +9,18 @@ const api = axios.create({
9
9
  },
10
10
  baseURL: import.meta.env.VITE_APP_URL_API,
11
11
  });
12
+ const isStorybook = () => typeof window !== 'undefined' &&
13
+ (window.location.port === '6006' || window.__STORYBOOK__);
12
14
  api.interceptors.response.use((response) => response, async (error) => {
13
15
  if (error.response?.status === 401) {
14
16
  CookieStorage.removeJwtToken();
15
17
  sessionStorage.clear();
16
18
  localStorage.clear();
17
- window.location.replace(import.meta.env.VITE_APP_AUTH_URL);
19
+ if (!isStorybook()) {
20
+ window.location.replace(import.meta.env.VITE_APP_AUTH_URL);
21
+ }
18
22
  }
19
- else if (error.response?.status === 403) {
23
+ else if (error.response?.status === 403 && !isStorybook()) {
20
24
  window.location.href = `${import.meta.env.VITE_APP_PUBLIC_URL}/unauthorized`;
21
25
  }
22
26
  else if (error.status === null) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.8.21",
4
+ "version": "0.8.23",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {