tycho-components 0.2.3-SNAPSHOT-5 → 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,7 +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);
43
+ onReadyCustom && onReadyCustom(thisCy);
44
+ renderWithInfo && applyInfo(thisCy, struct, true);
44
45
  },
45
46
  });
46
47
  };
@@ -63,19 +64,22 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
63
64
  }, 200);
64
65
  }
65
66
  };
66
- const displayInfo = () => {
67
- if (!cy || !struct)
68
- return;
69
- const newVal = !showInfo;
70
- setShowInfo(newVal);
67
+ const applyInfo = (thisCy, struct, extraInfo) => {
71
68
  struct.tokens.forEach((token) => {
72
69
  if (!token.ec) {
73
70
  const leafId = token.p?.toString();
74
- const newLabel = new CytoscapeTreeConverter().getLabelLeaf.call({ extraInfo: newVal }, token);
75
- cy.$id(leafId).data('label', newLabel);
71
+ const newLabel = new CytoscapeTreeConverter().getLabelLeaf.call({ extraInfo }, token);
72
+ thisCy.$id(leafId).data('label', newLabel);
76
73
  }
77
74
  });
78
75
  };
76
+ const toggleInfo = () => {
77
+ if (!cy || !struct)
78
+ return;
79
+ const newVal = !showInfo;
80
+ setShowInfo(newVal);
81
+ applyInfo(cy, struct, newVal);
82
+ };
79
83
  useEffect(() => {
80
84
  setInvalid(undefined);
81
85
  load();
@@ -84,7 +88,7 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
84
88
  return _jsx(AppPlaceholder, { text: t('placeholder.sentence.notparsed') });
85
89
  }
86
90
  return (_jsxs("div", { className: "tree-view-container", children: [cy &&
87
- getButtons(generateImage, reset, downloadPsd, displayInfo, onExpand, expression)
91
+ getButtons(generateImage, reset, downloadPsd, toggleInfo, onExpand, expression)
88
92
  .filter((btn) => btn.condition)
89
93
  .map((btn, i) => {
90
94
  const right = 12 + i * 44;
@@ -92,7 +96,7 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
92
96
  }), _jsx("div", { id: selector, className: "canvas-tree" }), showInfo && (_jsxs("div", { className: "info", children: [_jsx("span", { children: SentenceUtils.getAsText(struct) }), translations &&
93
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')] }))] }))] }));
94
98
  }
95
- const getButtons = (generateImage, reset, downloadPsd, displayInfo, onExpand, expression) => [
99
+ const getButtons = (generateImage, reset, downloadPsd, toggleInfo, onExpand, expression) => [
96
100
  {
97
101
  condition: true,
98
102
  title: 'button.download.tree',
@@ -121,7 +125,7 @@ const getButtons = (generateImage, reset, downloadPsd, displayInfo, onExpand, ex
121
125
  {
122
126
  condition: true,
123
127
  title: 'button.info',
124
- onClick: displayInfo,
128
+ onClick: toggleInfo,
125
129
  icon: faInfoCircle,
126
130
  },
127
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-5",
4
+ "version": "0.2.3-SNAPSHOT-7",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {