tycho-components 0.8.21 → 0.8.22
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.
- package/dist/TreeView/TreeView.d.ts +4 -4
- package/dist/TreeView/TreeView.js +37 -37
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Core } from
|
|
2
|
-
import { Struct } from
|
|
3
|
-
import
|
|
1
|
+
import { Core } from "cytoscape";
|
|
2
|
+
import { Struct } from "../configs/types/Struct";
|
|
3
|
+
import "./style.scss";
|
|
4
4
|
type Props = {
|
|
5
|
-
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
|
|
3
|
-
import html2canvas from
|
|
4
|
-
import { useEffect, useState } from
|
|
5
|
-
import { useTranslation } from
|
|
6
|
-
import { IconButton } from
|
|
7
|
-
import AppPlaceholder from
|
|
8
|
-
import DateUtils from
|
|
9
|
-
import SentenceUtils from
|
|
10
|
-
import TreeViewSearch from
|
|
11
|
-
import CytoscapeTreeConverter from
|
|
12
|
-
import SyntreesCytoscape from
|
|
13
|
-
import
|
|
14
|
-
export default function TreeView({ struct, expression, selector =
|
|
15
|
-
const { t } = useTranslation(
|
|
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:
|
|
62
|
-
saveAs(blob,
|
|
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:
|
|
71
|
+
backgroundColor: "white",
|
|
72
72
|
}).then((canvas) => {
|
|
73
73
|
canvas.toBlob((blob) => {
|
|
74
74
|
if (blob === null)
|
|
75
75
|
return;
|
|
76
|
-
saveAs(blob,
|
|
77
|
-
},
|
|
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[
|
|
93
|
+
converter["extraInfo"] = extraInfo;
|
|
94
94
|
const newLabel = converter.getLabelLeaf(token);
|
|
95
|
-
thisCy.$id(leafId).data(
|
|
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(
|
|
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(
|
|
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:
|
|
130
|
+
title: "button.download.tree",
|
|
131
131
|
onClick: generateImage,
|
|
132
|
-
icon:
|
|
132
|
+
icon: "download",
|
|
133
133
|
},
|
|
134
134
|
{
|
|
135
135
|
condition: true,
|
|
136
|
-
title:
|
|
136
|
+
title: "button.recenter.tree",
|
|
137
137
|
onClick: reset,
|
|
138
|
-
icon:
|
|
138
|
+
icon: "fullscreen",
|
|
139
139
|
},
|
|
140
140
|
{
|
|
141
141
|
condition: !!expression,
|
|
142
|
-
title:
|
|
142
|
+
title: "button.download.penn",
|
|
143
143
|
onClick: downloadPsd,
|
|
144
|
-
icon:
|
|
144
|
+
icon: "graph_4",
|
|
145
145
|
},
|
|
146
146
|
{
|
|
147
147
|
condition: !!onExpand,
|
|
148
|
-
title:
|
|
148
|
+
title: "button.expand.tree",
|
|
149
149
|
onClick: onExpand || (() => { }),
|
|
150
|
-
icon:
|
|
150
|
+
icon: "open_in_full",
|
|
151
151
|
},
|
|
152
152
|
{
|
|
153
153
|
condition: true,
|
|
154
|
-
title:
|
|
154
|
+
title: "button.info",
|
|
155
155
|
onClick: toggleInfo,
|
|
156
|
-
icon:
|
|
156
|
+
icon: "info",
|
|
157
157
|
},
|
|
158
158
|
{
|
|
159
159
|
condition: true,
|
|
160
|
-
title:
|
|
160
|
+
title: "button.search",
|
|
161
161
|
onClick: openSearchModal || (() => { }),
|
|
162
|
-
icon:
|
|
162
|
+
icon: "search",
|
|
163
163
|
},
|
|
164
164
|
];
|