tycho-components 0.2.4-SNAPSHOT-2 → 0.2.4-SNAPSHOT-3

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.
@@ -3,7 +3,6 @@
3
3
  flex-direction: column;
4
4
  justify-content: center;
5
5
  align-items: center;
6
- cursor: pointer;
7
6
  width: 100%;
8
7
 
9
8
  > span {
@@ -10,7 +10,7 @@ type Props = {
10
10
  renderWithInfo?: boolean;
11
11
  placeholder?: string;
12
12
  onClickExpression?: () => void;
13
- onExpand?: () => void;
13
+ onExpand?: (reset: () => void) => void;
14
14
  onReadyCustom?: (thisCy: Core) => void;
15
15
  };
16
16
  export default function TreeView({ struct, expression, selector, translations, wheelSensitivity, renderWithInfo, placeholder, onClickExpression, onExpand, onReadyCustom, }: Props): import("react/jsx-runtime").JSX.Element;
@@ -2,6 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { faDiagramProject, faDownload, faExpand, faInfoCircle, faUpRightAndDownLeftFromCenter, } from '@fortawesome/free-solid-svg-icons';
3
3
  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4
4
  import { saveAs } from 'file-saver';
5
+ import html2canvas from 'html2canvas';
5
6
  import { useEffect, useState } from 'react';
6
7
  import { useTranslation } from 'react-i18next';
7
8
  import AppPlaceholder from '../AppPlaceholder';
@@ -52,9 +53,20 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
52
53
  saveAs(blob, 'sentence.psd');
53
54
  };
54
55
  const generateImage = () => {
55
- if (cy) {
56
- saveAs(cy.jpg({ full: true }), 'tree.jpg');
57
- }
56
+ if (!cy)
57
+ return;
58
+ const cyContainer = cy.container();
59
+ if (!cyContainer)
60
+ return;
61
+ html2canvas(cyContainer, {
62
+ backgroundColor: 'white',
63
+ }).then((canvas) => {
64
+ canvas.toBlob((blob) => {
65
+ if (blob === null)
66
+ return;
67
+ saveAs(blob, 'tree.jpg');
68
+ }, 'image/jpeg', 1.0);
69
+ });
58
70
  };
59
71
  const reset = () => {
60
72
  if (cy) {
@@ -119,7 +131,7 @@ const getButtons = (generateImage, reset, downloadPsd, toggleInfo, onExpand, exp
119
131
  {
120
132
  condition: !!onExpand,
121
133
  title: 'button.expand.tree',
122
- onClick: onExpand,
134
+ onClick: () => onExpand && onExpand(reset),
123
135
  icon: faUpRightAndDownLeftFromCenter,
124
136
  },
125
137
  {
@@ -1,2 +1,3 @@
1
+ import cytoscape from 'cytoscape';
1
2
  declare const defaultStylesheet: Array<cytoscape.StylesheetCSS>;
2
3
  export default defaultStylesheet;
@@ -13,7 +13,6 @@ const defaultStylesheet = [
13
13
  {
14
14
  selector: 'node',
15
15
  style: {
16
- content: 'data(label)',
17
16
  'background-color': '#FFF',
18
17
  width: '50px',
19
18
  height: '40px',
@@ -21,7 +20,6 @@ const defaultStylesheet = [
21
20
  'text-max-width': 120,
22
21
  'text-valign': 'center',
23
22
  'text-halign': 'center',
24
- 'font-size': 18,
25
23
  shape: 'rectangle',
26
24
  cursor: 'pointer',
27
25
  },
@@ -31,9 +31,9 @@ export default class CytoscapeTreeConverter {
31
31
  const attrLines = Object.values(token.attributes)
32
32
  .map((v) => v)
33
33
  .join('\n');
34
- return `${token.v}\n${attrLines}`;
34
+ return `<span class="token-value">${token.v}</span><span class="token-attributes">${attrLines}</span>`;
35
35
  }
36
- return token.v;
36
+ return `<span class="token-value">${token.v}</span>`;
37
37
  }
38
38
  validate(struct) {
39
39
  if (!struct.chunks || struct.chunks.length === 0) {
@@ -1,5 +1,7 @@
1
1
  import cytoscape from 'cytoscape';
2
2
  import defaultStylesheet from './CytoscapeStylesheet';
3
+ import nodeHtmlLabel from 'cytoscape-node-edge-html-label';
4
+ nodeHtmlLabel(cytoscape);
3
5
  const init = ({ selector, tree, dagre = false, stylesheet = defaultStylesheet, wheelSensitivity = 1.5, onReady, }) => {
4
6
  destroy(selector);
5
7
  const cy = cytoscape({
@@ -32,6 +34,18 @@ const init = ({ selector, tree, dagre = false, stylesheet = defaultStylesheet, w
32
34
  pixelRatio: 1,
33
35
  });
34
36
  cy.ready(() => {
37
+ if (!cy._htmlLabelsApplied) {
38
+ // @ts-ignore (no types)
39
+ cy.nodeHtmlLabel([
40
+ {
41
+ query: 'node',
42
+ halign: 'center',
43
+ valign: 'center',
44
+ tpl: (data) => `<div class="token-data">${data.label}</div>`,
45
+ },
46
+ ]);
47
+ cy._htmlLabelsApplied = true; // mark as applied
48
+ }
35
49
  cy.fit();
36
50
  cy.center();
37
51
  dagre && cy.layout({ name: 'dagre' }).run();
@@ -40,4 +40,18 @@
40
40
  @include helper-medium-1;
41
41
  }
42
42
  }
43
+
44
+ .token-data {
45
+ text-align: center;
46
+ .token-value {
47
+ display: block;
48
+ font-weight: bolder;
49
+ font-size: 18px;
50
+ }
51
+
52
+ .token-attributes {
53
+ display: block;
54
+ color: red;
55
+ }
56
+ }
43
57
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.2.4-SNAPSHOT-2",
4
+ "version": "0.2.4-SNAPSHOT-3",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
@@ -24,17 +24,19 @@
24
24
  "axios": "^1.7.7",
25
25
  "classnames": "^2.5.1",
26
26
  "cytoscape": "^3.28.1",
27
+ "cytoscape-node-edge-html-label": "^1.0.6",
27
28
  "date-fns": "^2.29.1",
28
29
  "date-fns-tz": "^1.3.6",
29
30
  "file-saver": "^2.0.5",
31
+ "html2canvas": "^1.4.1",
30
32
  "js-cookie": "^3.0.5",
31
33
  "react-colorful": "^5.6.1",
32
34
  "react-easy-edit": "^2.0.0",
33
- "react-simple-keyboard": "^3.8.66",
34
- "simple-keyboard-layouts": "^3.4.82",
35
35
  "react-loading": "^2.0.3",
36
+ "react-simple-keyboard": "^3.8.66",
36
37
  "react-switch": "^7.1.0",
37
- "react-toastify": "^9.1.3"
38
+ "react-toastify": "^9.1.3",
39
+ "simple-keyboard-layouts": "^3.4.82"
38
40
  },
39
41
  "peerDependencies": {
40
42
  "@emotion/react": "^11.13.3",
@@ -64,7 +66,7 @@
64
66
  "@storybook/react": "^7.5.3",
65
67
  "@storybook/react-vite": "^7.5.3",
66
68
  "@storybook/testing-library": "^0.2.2",
67
- "@types/cytoscape": "^3.19.15",
69
+ "@types/cytoscape": "^3.21.9",
68
70
  "@types/file-saver": "^2.0.5",
69
71
  "@types/js-cookie": "^3.0.6",
70
72
  "@types/react": "^18.2.0",