tycho-components 0.2.3-SNAPSHOT-6 → 0.2.3-SNAPSHOT-7

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.
@@ -7,9 +7,9 @@ type Props = {
7
7
  selector?: string;
8
8
  translations?: Record<string, string>;
9
9
  wheelSensitivity?: number;
10
- onRenderShowInfo?: boolean;
10
+ renderWithInfo?: boolean;
11
11
  onExpand?: () => void;
12
- onReady?: (thisCy: Core) => void;
12
+ onReadyCustom?: (thisCy: Core) => void;
13
13
  };
14
- export default function TreeView({ struct, expression, selector, translations, wheelSensitivity, onRenderShowInfo, onExpand, onReady, }: Props): import("react/jsx-runtime").JSX.Element;
14
+ export default function TreeView({ struct, expression, selector, translations, wheelSensitivity, renderWithInfo, onExpand, onReadyCustom, }: Props): import("react/jsx-runtime").JSX.Element;
15
15
  export {};
@@ -10,10 +10,10 @@ import SentenceUtils from '../functions/SentenceUtils';
10
10
  import CytoscapeTreeConverter from './cytoscape/CytoscapeTreeConverter';
11
11
  import SyntreesCytoscape from './cytoscape/SyntreesCytoscape';
12
12
  import './style.scss';
13
- export default function TreeView({ struct, expression, selector = 'canvas-tree', translations, wheelSensitivity, onRenderShowInfo = false, onExpand, onReady, }) {
13
+ export default function TreeView({ struct, expression, selector = 'canvas-tree', translations, wheelSensitivity, renderWithInfo = false, onExpand, onReadyCustom, }) {
14
14
  const { t } = useTranslation('tree');
15
15
  const [cy, setCy] = useState(null);
16
- const [showInfo, setShowInfo] = useState(onRenderShowInfo);
16
+ const [showInfo, setShowInfo] = useState(renderWithInfo);
17
17
  const [invalid, setInvalid] = useState();
18
18
  const load = () => {
19
19
  setCy(null);
@@ -40,8 +40,8 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
40
40
  wheelSensitivity,
41
41
  onReady: (thisCy) => {
42
42
  setCy(thisCy);
43
- onReady && onReady(thisCy);
44
- onRenderShowInfo && displayInfo();
43
+ onReadyCustom && onReadyCustom(thisCy);
44
+ renderWithInfo && applyInfo(thisCy, struct, true);
45
45
  },
46
46
  });
47
47
  };
@@ -64,19 +64,22 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
64
64
  }, 200);
65
65
  }
66
66
  };
67
- const displayInfo = () => {
68
- if (!cy || !struct)
69
- return;
70
- const newVal = !showInfo;
71
- setShowInfo(newVal);
67
+ const applyInfo = (thisCy, struct, extraInfo) => {
72
68
  struct.tokens.forEach((token) => {
73
69
  if (!token.ec) {
74
70
  const leafId = token.p?.toString();
75
- const newLabel = new CytoscapeTreeConverter().getLabelLeaf.call({ extraInfo: newVal }, token);
76
- cy.$id(leafId).data('label', newLabel);
71
+ const newLabel = new CytoscapeTreeConverter().getLabelLeaf.call({ extraInfo }, token);
72
+ thisCy.$id(leafId).data('label', newLabel);
77
73
  }
78
74
  });
79
75
  };
76
+ const toggleInfo = () => {
77
+ if (!cy || !struct)
78
+ return;
79
+ const newVal = !showInfo;
80
+ setShowInfo(newVal);
81
+ applyInfo(cy, struct, newVal);
82
+ };
80
83
  useEffect(() => {
81
84
  setInvalid(undefined);
82
85
  load();
@@ -85,7 +88,7 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
85
88
  return _jsx(AppPlaceholder, { text: t('placeholder.sentence.notparsed') });
86
89
  }
87
90
  return (_jsxs("div", { className: "tree-view-container", children: [cy &&
88
- getButtons(generateImage, reset, downloadPsd, displayInfo, onExpand, expression)
91
+ getButtons(generateImage, reset, downloadPsd, toggleInfo, onExpand, expression)
89
92
  .filter((btn) => btn.condition)
90
93
  .map((btn, i) => {
91
94
  const right = 12 + i * 44;
@@ -93,7 +96,7 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
93
96
  }), _jsx("div", { id: selector, className: "canvas-tree" }), showInfo && (_jsxs("div", { className: "info", children: [_jsx("span", { children: SentenceUtils.getAsText(struct) }), translations &&
94
97
  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')] }))] }))] }));
95
98
  }
96
- const getButtons = (generateImage, reset, downloadPsd, displayInfo, onExpand, expression) => [
99
+ const getButtons = (generateImage, reset, downloadPsd, toggleInfo, onExpand, expression) => [
97
100
  {
98
101
  condition: true,
99
102
  title: 'button.download.tree',
@@ -122,7 +125,7 @@ const getButtons = (generateImage, reset, downloadPsd, displayInfo, onExpand, ex
122
125
  {
123
126
  condition: true,
124
127
  title: 'button.info',
125
- onClick: displayInfo,
128
+ onClick: toggleInfo,
126
129
  icon: faInfoCircle,
127
130
  },
128
131
  ];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.2.3-SNAPSHOT-6",
4
+ "version": "0.2.3-SNAPSHOT-7",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {