tycho-components 0.1.0-SNAPSHOT-8 → 0.2.0-SNAPSHOT

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.
Files changed (59) hide show
  1. package/dist/Comments/CommentAdd.d.ts +1 -1
  2. package/dist/Comments/types/CommentService.d.ts +1 -1
  3. package/dist/Header/types/CorpusService.d.ts +1 -1
  4. package/dist/TreeView/TreeView.d.ts +11 -0
  5. package/dist/TreeView/TreeView.js +104 -0
  6. package/dist/TreeView/cytoscape/Configuration.d.ts +18 -0
  7. package/dist/TreeView/cytoscape/Configuration.js +22 -0
  8. package/dist/TreeView/cytoscape/CytoscapePositionCalculator.d.ts +10 -0
  9. package/dist/TreeView/cytoscape/CytoscapePositionCalculator.js +63 -0
  10. package/dist/TreeView/cytoscape/CytoscapeStylesheet.d.ts +2 -0
  11. package/dist/TreeView/cytoscape/CytoscapeStylesheet.js +104 -0
  12. package/dist/TreeView/cytoscape/CytoscapeTreeConverter.d.ts +29 -0
  13. package/dist/TreeView/cytoscape/CytoscapeTreeConverter.js +331 -0
  14. package/dist/TreeView/cytoscape/NodeBounds.d.ts +7 -0
  15. package/dist/TreeView/cytoscape/NodeBounds.js +1 -0
  16. package/dist/TreeView/cytoscape/NodeCalculation.d.ts +14 -0
  17. package/dist/TreeView/cytoscape/NodeCalculation.js +1 -0
  18. package/dist/TreeView/cytoscape/NormalizedPosition.d.ts +8 -0
  19. package/dist/TreeView/cytoscape/NormalizedPosition.js +13 -0
  20. package/dist/TreeView/cytoscape/SyntreesCytoscape.d.ts +6 -0
  21. package/dist/TreeView/cytoscape/SyntreesCytoscape.js +49 -0
  22. package/dist/TreeView/cytoscape/TreeLayout.d.ts +64 -0
  23. package/dist/TreeView/cytoscape/TreeLayout.js +353 -0
  24. package/dist/TreeView/index.d.ts +2 -0
  25. package/dist/TreeView/index.js +2 -0
  26. package/dist/TreeView/style.scss +36 -0
  27. package/dist/TreeView/types/TreeViewExample.d.ts +2 -0
  28. package/dist/TreeView/types/TreeViewExample.js +261 -0
  29. package/dist/configs/Localization.d.ts +195 -86
  30. package/dist/configs/Localization.js +12 -4
  31. package/dist/configs/localization/CommentsTexts.d.ts +31 -0
  32. package/dist/configs/localization/CommentsTexts.js +31 -0
  33. package/dist/configs/localization/ParticipantsTexts.d.ts +26 -0
  34. package/dist/configs/localization/ParticipantsTexts.js +26 -0
  35. package/dist/configs/localization/TreeTexts.d.ts +21 -0
  36. package/dist/configs/localization/TreeTexts.js +21 -0
  37. package/dist/configs/store/actions.d.ts +2 -2
  38. package/dist/configs/store/types.d.ts +2 -2
  39. package/dist/configs/types/Struct.d.ts +44 -0
  40. package/dist/configs/types/Struct.js +1 -0
  41. package/dist/configs/types/Tree.d.ts +12 -0
  42. package/dist/configs/types/Tree.js +1 -0
  43. package/dist/configs/useCorpusUtils.d.ts +1 -1
  44. package/dist/configs/useCorpusUtils.js +1 -1
  45. package/dist/configs/useLoggedUtils.d.ts +1 -1
  46. package/dist/configs/useLoggedUtils.js +1 -1
  47. package/dist/functions/SecurityUtils.d.ts +1 -1
  48. package/dist/functions/SecurityUtils.js +1 -1
  49. package/dist/functions/SentenceUtils.d.ts +6 -0
  50. package/dist/functions/SentenceUtils.js +32 -0
  51. package/dist/index.d.ts +9 -5
  52. package/dist/index.js +4 -2
  53. package/package.json +5 -1
  54. /package/dist/configs/{Corpus.d.ts → types/Corpus.d.ts} +0 -0
  55. /package/dist/configs/{Corpus.js → types/Corpus.js} +0 -0
  56. /package/dist/configs/{CorpusImage.d.ts → types/CorpusImage.d.ts} +0 -0
  57. /package/dist/configs/{CorpusImage.js → types/CorpusImage.js} +0 -0
  58. /package/dist/configs/{User.d.ts → types/User.d.ts} +0 -0
  59. /package/dist/configs/{User.js → types/User.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { User } from '../configs/User';
1
+ import { User } from '../configs/types/User';
2
2
  import './style.scss';
3
3
  import { Comment } from './types/Comment';
4
4
  type Props = {
@@ -1,4 +1,4 @@
1
- import { User } from '../../configs/User';
1
+ import { User } from '../../configs/types/User';
2
2
  import { Comment, CommentRequest } from './Comment';
3
3
  declare function findNotifications(uid: string, mode: string): Promise<import("axios").AxiosResponse<Comment[], any>>;
4
4
  declare function findReadNotifications(uid: string, mode: string): Promise<import("axios").AxiosResponse<Comment[], any>>;
@@ -1,4 +1,4 @@
1
- import { Corpus } from '../../configs/Corpus';
1
+ import { Corpus } from '../../configs/types/Corpus';
2
2
  declare function available(): Promise<import("axios").AxiosResponse<Corpus[], any>>;
3
3
  declare const CorpusService: {
4
4
  available: typeof available;
@@ -0,0 +1,11 @@
1
+ import { Struct } from '../configs/types/Struct';
2
+ import './style.scss';
3
+ type Props = {
4
+ struct: Struct;
5
+ expression?: string;
6
+ selector?: string;
7
+ onExpand?: () => void;
8
+ translations?: Record<string, string>;
9
+ };
10
+ export default function TreeView({ struct, expression, onExpand, selector, translations, }: Props): import("react/jsx-runtime").JSX.Element;
11
+ export {};
@@ -0,0 +1,104 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { faDiagramProject, faDownload, faExpand, faInfoCircle, faUpRightAndDownLeftFromCenter, } from '@fortawesome/free-solid-svg-icons';
3
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4
+ import { saveAs } from 'file-saver';
5
+ import { useEffect, useState } from 'react';
6
+ import { useTranslation } from 'react-i18next';
7
+ import SentenceUtils from '../functions/SentenceUtils';
8
+ import CytoscapeTreeConverter from './cytoscape/CytoscapeTreeConverter';
9
+ import SyntreesCytoscape from './cytoscape/SyntreesCytoscape';
10
+ import './style.scss';
11
+ export default function TreeView({ struct, expression, onExpand, selector = 'canvas-tree', translations, }) {
12
+ const { t } = useTranslation('tree');
13
+ const [cy, setCy] = useState(null);
14
+ const [showInfo, setShowInfo] = useState(false);
15
+ const load = () => {
16
+ setCy(null);
17
+ const element = document.getElementById(selector);
18
+ if (element)
19
+ element.innerHTML = '';
20
+ if (!struct)
21
+ return;
22
+ const tree = new CytoscapeTreeConverter().execute(struct, showInfo);
23
+ tree &&
24
+ SyntreesCytoscape.init(selector, tree, (thisCy) => {
25
+ setCy(thisCy);
26
+ });
27
+ };
28
+ const downloadPsd = () => {
29
+ if (!expression)
30
+ return;
31
+ const blob = new Blob([expression], { type: 'text/plain;charset=utf-8' });
32
+ saveAs(blob, 'sentence.psd');
33
+ };
34
+ const generateImage = () => {
35
+ if (cy) {
36
+ saveAs(cy.jpg({ full: true }), 'tree.jpg');
37
+ }
38
+ };
39
+ const reset = () => {
40
+ if (cy) {
41
+ setTimeout(() => {
42
+ cy.fit();
43
+ cy.center();
44
+ }, 200);
45
+ }
46
+ };
47
+ const displayInfo = () => {
48
+ if (!cy || !struct)
49
+ return;
50
+ const newVal = !showInfo;
51
+ setShowInfo(newVal);
52
+ struct.tokens.forEach((token) => {
53
+ if (!token.ec) {
54
+ const leafId = token.p?.toString();
55
+ const newLabel = new CytoscapeTreeConverter().getLabelLeaf.call({ extraInfo: newVal }, token);
56
+ cy.$id(leafId).data('label', newLabel);
57
+ }
58
+ });
59
+ };
60
+ useEffect(() => {
61
+ load();
62
+ }, [struct]);
63
+ return (_jsxs("div", { className: "tree-view-container", children: [cy &&
64
+ getButtons(generateImage, reset, downloadPsd, displayInfo, onExpand, expression)
65
+ .filter((btn) => btn.condition)
66
+ .map((btn, i) => {
67
+ const right = 12 + i * 44;
68
+ return (_jsx("button", { className: "floating-button", type: "button", title: t(btn.title), onClick: btn.onClick, style: { right: `${right}px` }, children: _jsx(FontAwesomeIcon, { icon: btn.icon, className: btn.extraClass }) }, i));
69
+ }), _jsx("div", { id: selector, className: "canvas-tree" }), showInfo && (_jsxs("div", { className: "info", children: [_jsx("span", { children: SentenceUtils.getAsText(struct) }), translations &&
70
+ Object.entries(translations).map(([k, v]) => (_jsxs("div", { className: "translation", children: [_jsxs("b", { children: [k, ":"] }), _jsx("span", { children: v })] }, k)))] }))] }));
71
+ }
72
+ const getButtons = (generateImage, reset, downloadPsd, displayInfo, onExpand, expression) => [
73
+ {
74
+ condition: true,
75
+ title: 'button.download.tree',
76
+ onClick: generateImage,
77
+ icon: faDownload,
78
+ },
79
+ {
80
+ condition: true,
81
+ title: 'button.recenter.tree',
82
+ onClick: reset,
83
+ icon: faExpand,
84
+ },
85
+ {
86
+ condition: !!expression,
87
+ title: 'button.download.penn',
88
+ onClick: downloadPsd,
89
+ icon: faDiagramProject,
90
+ extraClass: 'fa-rotate-90',
91
+ },
92
+ {
93
+ condition: !!onExpand,
94
+ title: 'button.expand.tree',
95
+ onClick: onExpand,
96
+ icon: faUpRightAndDownLeftFromCenter,
97
+ },
98
+ {
99
+ condition: true,
100
+ title: 'button.info',
101
+ onClick: displayInfo,
102
+ icon: faInfoCircle,
103
+ },
104
+ ];
@@ -0,0 +1,18 @@
1
+ declare enum Location {
2
+ Top = "Top",
3
+ Left = "Left",
4
+ Bottom = "Bottom",
5
+ Right = "Right"
6
+ }
7
+ declare enum AlignmentInLevel {
8
+ Center = "Center",
9
+ TowardsRoot = "TowardsRoot",
10
+ AwayFromRoot = "AwayFromRoot"
11
+ }
12
+ declare class Configuration {
13
+ gapBetweenLevels: number;
14
+ gapBetweenNodes: number;
15
+ location: Location;
16
+ alignmentInLevel: AlignmentInLevel;
17
+ }
18
+ export { AlignmentInLevel, Configuration, Location };
@@ -0,0 +1,22 @@
1
+ var Location;
2
+ (function (Location) {
3
+ Location["Top"] = "Top";
4
+ Location["Left"] = "Left";
5
+ Location["Bottom"] = "Bottom";
6
+ Location["Right"] = "Right";
7
+ })(Location || (Location = {}));
8
+ var AlignmentInLevel;
9
+ (function (AlignmentInLevel) {
10
+ AlignmentInLevel["Center"] = "Center";
11
+ AlignmentInLevel["TowardsRoot"] = "TowardsRoot";
12
+ AlignmentInLevel["AwayFromRoot"] = "AwayFromRoot";
13
+ })(AlignmentInLevel || (AlignmentInLevel = {}));
14
+ class Configuration {
15
+ constructor() {
16
+ this.gapBetweenLevels = 50.0;
17
+ this.gapBetweenNodes = 50.0;
18
+ this.location = Location.Top;
19
+ this.alignmentInLevel = AlignmentInLevel.Center;
20
+ }
21
+ }
22
+ export { AlignmentInLevel, Configuration, Location };
@@ -0,0 +1,10 @@
1
+ import NodeBounds from './NodeBounds';
2
+ import { CytoscapeTreeCalculation } from './NodeCalculation';
3
+ declare class CytoscapePositionCalculator {
4
+ calculatePositions(cytoscape: CytoscapeTreeCalculation): Map<string, NodeBounds>;
5
+ private convert;
6
+ private getChildren;
7
+ private addNode;
8
+ private order;
9
+ }
10
+ export default CytoscapePositionCalculator;
@@ -0,0 +1,63 @@
1
+ import TreeLayout from './TreeLayout';
2
+ class CytoscapePositionCalculator {
3
+ calculatePositions(cytoscape) {
4
+ this.convert(cytoscape);
5
+ const layout = new TreeLayout(cytoscape.root);
6
+ return layout.getNodeBounds();
7
+ }
8
+ convert(cytoscape) {
9
+ this.order(cytoscape);
10
+ const root = cytoscape.root;
11
+ const mapNodes = new Map();
12
+ for (const node of cytoscape.nodes) {
13
+ mapNodes.set(node.id, node);
14
+ }
15
+ const rootKey = root.id;
16
+ if (rootKey)
17
+ for (const childKey of this.getChildren(cytoscape, rootKey)) {
18
+ this.addNode(cytoscape, mapNodes, childKey, root);
19
+ }
20
+ }
21
+ getChildren(cytoscape, key) {
22
+ // Gets all connected children IDs from the edges
23
+ const list = cytoscape.edges
24
+ .filter((e) => e.data.source === key)
25
+ .map((e) => e.data.target);
26
+ // Creates a new list to add the IDs in the order of the nodes
27
+ const children = [];
28
+ for (const node of cytoscape.nodes) {
29
+ if (!list.includes(node.id))
30
+ continue;
31
+ children.push(node.id);
32
+ }
33
+ return children;
34
+ }
35
+ addNode(cytoscape, mapNodes, key, fatherNode) {
36
+ const node = mapNodes.get(key);
37
+ if (!node)
38
+ return;
39
+ if (!fatherNode.children)
40
+ fatherNode.children = [];
41
+ fatherNode.children.push(node);
42
+ node.parent = fatherNode;
43
+ const children = this.getChildren(cytoscape, key);
44
+ if (children.length === 1 && children.includes(key))
45
+ return;
46
+ for (const child of children) {
47
+ this.addNode(cytoscape, mapNodes, child, node);
48
+ }
49
+ }
50
+ order(cytoscape) {
51
+ cytoscape.nodes.sort((nodeA, nodeB) => {
52
+ const valueA = nodeA.data.chunk ? nodeA.data.chunk.i : nodeA.data.token.p;
53
+ const valueB = nodeB.data.chunk ? nodeB.data.chunk.i : nodeB.data.token.p;
54
+ return valueA - valueB;
55
+ });
56
+ cytoscape.edges.sort((edge1, edge2) => {
57
+ const index1 = cytoscape.nodes.findIndex((node) => node.id === edge1.data.target);
58
+ const index2 = cytoscape.nodes.findIndex((node) => node.id === edge2.data.target);
59
+ return index1 - index2;
60
+ });
61
+ }
62
+ }
63
+ export default CytoscapePositionCalculator;
@@ -0,0 +1,2 @@
1
+ declare const stylesheet: Array<cytoscape.StylesheetCSS>;
2
+ export default stylesheet;
@@ -0,0 +1,104 @@
1
+ const stylesheet = [
2
+ {
3
+ selector: 'core',
4
+ style: {
5
+ 'selection-box-color': '#ddd',
6
+ 'selection-box-opacity': 0.65,
7
+ 'selection-box-border-color': '#aaa',
8
+ 'selection-box-border-width': 1,
9
+ 'active-bg-color': 'black',
10
+ 'active-bg-opacity': 0.15,
11
+ },
12
+ },
13
+ {
14
+ selector: 'node',
15
+ style: {
16
+ content: 'data(label)',
17
+ 'background-color': '#FFF',
18
+ width: '50px',
19
+ height: '40px',
20
+ 'text-wrap': 'wrap',
21
+ 'text-max-width': 120,
22
+ 'text-valign': 'center',
23
+ 'text-halign': 'center',
24
+ 'font-size': 18,
25
+ shape: 'rectangle',
26
+ cursor: 'pointer',
27
+ },
28
+ },
29
+ {
30
+ selector: 'node.highlight',
31
+ style: {
32
+ width: '100px',
33
+ 'background-color': 'yellow',
34
+ },
35
+ },
36
+ {
37
+ selector: 'edge',
38
+ style: {
39
+ 'control-point-distance': 30,
40
+ 'control-point-weight': 0.5,
41
+ opacity: 0.9,
42
+ 'overlay-padding': '3px',
43
+ 'overlay-opacity': 0,
44
+ width: 1,
45
+ },
46
+ },
47
+ {
48
+ selector: ':selected',
49
+ style: {
50
+ 'background-color': '#FFF',
51
+ 'line-color': 'red',
52
+ 'source-arrow-color': 'red',
53
+ 'target-arrow-color': 'red',
54
+ },
55
+ },
56
+ {
57
+ selector: '.eh-handle',
58
+ style: {
59
+ 'background-color': 'red',
60
+ width: 12,
61
+ height: 12,
62
+ shape: 'ellipse',
63
+ 'overlay-opacity': 0,
64
+ 'border-width': 12, // makes the handle easier to hit
65
+ 'border-opacity': 0,
66
+ },
67
+ },
68
+ {
69
+ selector: '.eh-hover',
70
+ style: {
71
+ 'background-color': 'red',
72
+ },
73
+ },
74
+ {
75
+ selector: '.eh-source',
76
+ style: {
77
+ 'border-width': 2,
78
+ 'border-color': 'red',
79
+ },
80
+ },
81
+ {
82
+ selector: '.eh-target',
83
+ style: {
84
+ 'border-width': 2,
85
+ 'border-color': 'red',
86
+ },
87
+ },
88
+ {
89
+ selector: '.eh-preview, .eh-ghost-edge',
90
+ style: {
91
+ 'background-color': 'red',
92
+ 'line-color': 'red',
93
+ 'target-arrow-color': 'red',
94
+ 'source-arrow-color': 'red',
95
+ },
96
+ },
97
+ {
98
+ selector: '.eh-ghost-edge.eh-preview-active',
99
+ css: {
100
+ opacity: 0,
101
+ },
102
+ },
103
+ ];
104
+ export default stylesheet;
@@ -0,0 +1,29 @@
1
+ import { Struct, Token } from '../../configs/types/Struct';
2
+ import { CytoscapeTreeCalculation } from './NodeCalculation';
3
+ declare class CytoscapeTreeConverter {
4
+ private ID_SPLITTER;
5
+ private extraInfo;
6
+ execute(struct: Struct, extraInfo: boolean): CytoscapeTreeCalculation | undefined;
7
+ getLabelLeaf(token: Token): string;
8
+ private validate;
9
+ private calculatePositions;
10
+ private checkLastTokenPosition;
11
+ private inflate;
12
+ private isEmptyCategoryInChunk;
13
+ private convertEmptyCategory;
14
+ private convertChunk;
15
+ private removeTemporaryEdges;
16
+ private generateChunkId;
17
+ private generateTokenId;
18
+ private generateLeafId;
19
+ private findParent;
20
+ private initTree;
21
+ private sortChunks;
22
+ private convertToken;
23
+ private getTokens;
24
+ private getLabelValue;
25
+ private getChunksByLevel;
26
+ private sortTokens;
27
+ private uuid;
28
+ }
29
+ export default CytoscapeTreeConverter;