tycho-components 0.2.4-SNAPSHOT-4 → 0.2.4-SNAPSHOT-6
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.
|
@@ -9,9 +9,10 @@ type Props = {
|
|
|
9
9
|
wheelSensitivity?: number;
|
|
10
10
|
renderWithInfo?: boolean;
|
|
11
11
|
placeholder?: string;
|
|
12
|
+
cyRef?: React.MutableRefObject<Core | null>;
|
|
12
13
|
onClickExpression?: () => void;
|
|
13
|
-
onExpand?: (
|
|
14
|
+
onExpand?: () => void;
|
|
14
15
|
onReadyCustom?: (thisCy: Core) => void;
|
|
15
16
|
};
|
|
16
|
-
export default function TreeView({ struct, expression, selector, translations, wheelSensitivity, renderWithInfo, placeholder, onClickExpression, onExpand, onReadyCustom, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export default function TreeView({ struct, expression, selector, translations, wheelSensitivity, renderWithInfo, placeholder, cyRef, onClickExpression, onExpand, onReadyCustom, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
17
18
|
export {};
|
|
@@ -11,12 +11,11 @@ import SentenceUtils from '../functions/SentenceUtils';
|
|
|
11
11
|
import CytoscapeTreeConverter from './cytoscape/CytoscapeTreeConverter';
|
|
12
12
|
import SyntreesCytoscape from './cytoscape/SyntreesCytoscape';
|
|
13
13
|
import './style.scss';
|
|
14
|
-
export default function TreeView({ struct, expression, selector = 'canvas-tree', translations, wheelSensitivity, renderWithInfo = false, placeholder, onClickExpression, onExpand, onReadyCustom, }) {
|
|
14
|
+
export default function TreeView({ struct, expression, selector = 'canvas-tree', translations, wheelSensitivity, renderWithInfo = false, placeholder, cyRef, onClickExpression, onExpand, onReadyCustom, }) {
|
|
15
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();
|
|
19
|
-
const [expandedExternally, setExpandedExternally] = useState(false);
|
|
20
19
|
const load = () => {
|
|
21
20
|
setCy(null);
|
|
22
21
|
const element = document.getElementById(selector);
|
|
@@ -42,6 +41,8 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
|
|
|
42
41
|
wheelSensitivity,
|
|
43
42
|
onReady: (thisCy) => {
|
|
44
43
|
setCy(thisCy);
|
|
44
|
+
if (cyRef)
|
|
45
|
+
cyRef.current = thisCy;
|
|
45
46
|
onReadyCustom && onReadyCustom(thisCy);
|
|
46
47
|
renderWithInfo && applyInfo(thisCy, struct, true);
|
|
47
48
|
},
|
|
@@ -93,28 +94,15 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
|
|
|
93
94
|
setShowInfo(newVal);
|
|
94
95
|
applyInfo(cy, struct, newVal);
|
|
95
96
|
};
|
|
96
|
-
const handleExpand = () => {
|
|
97
|
-
setExpandedExternally(true);
|
|
98
|
-
onExpand && onExpand(reset);
|
|
99
|
-
};
|
|
100
97
|
useEffect(() => {
|
|
101
98
|
setInvalid(undefined);
|
|
102
99
|
load();
|
|
103
100
|
}, [struct]);
|
|
104
|
-
useEffect(() => {
|
|
105
|
-
if (expandedExternally) {
|
|
106
|
-
const id = setTimeout(() => {
|
|
107
|
-
reset();
|
|
108
|
-
setExpandedExternally(false);
|
|
109
|
-
}, 50);
|
|
110
|
-
return () => clearTimeout(id);
|
|
111
|
-
}
|
|
112
|
-
}, [expandedExternally]);
|
|
113
101
|
if (invalid) {
|
|
114
102
|
return (_jsx(AppPlaceholder, { text: placeholder || t('placeholder.sentence.notparsed') }));
|
|
115
103
|
}
|
|
116
104
|
return (_jsxs("div", { className: "tree-view-container", children: [cy &&
|
|
117
|
-
getButtons(generateImage, reset, onClickExpression || downloadPsd, toggleInfo,
|
|
105
|
+
getButtons(generateImage, reset, onClickExpression || downloadPsd, toggleInfo, onExpand, expression)
|
|
118
106
|
.filter((btn) => btn.condition)
|
|
119
107
|
.map((btn, i) => {
|
|
120
108
|
const right = 12 + i * 44;
|
|
@@ -122,7 +110,7 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
|
|
|
122
110
|
}), _jsx("div", { id: selector, className: "canvas-tree" }), showInfo && (_jsxs("div", { className: "info", children: [_jsx("span", { children: SentenceUtils.getAsText(struct) }), translations &&
|
|
123
111
|
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')] }))] }))] }));
|
|
124
112
|
}
|
|
125
|
-
const getButtons = (generateImage, reset, downloadPsd, toggleInfo,
|
|
113
|
+
const getButtons = (generateImage, reset, downloadPsd, toggleInfo, onExpand, expression) => [
|
|
126
114
|
{
|
|
127
115
|
condition: true,
|
|
128
116
|
title: 'button.download.tree',
|
|
@@ -145,7 +133,7 @@ const getButtons = (generateImage, reset, downloadPsd, toggleInfo, handleExpand,
|
|
|
145
133
|
{
|
|
146
134
|
condition: !!onExpand,
|
|
147
135
|
title: 'button.expand.tree',
|
|
148
|
-
onClick:
|
|
136
|
+
onClick: onExpand,
|
|
149
137
|
icon: faUpRightAndDownLeftFromCenter,
|
|
150
138
|
},
|
|
151
139
|
{
|