corpushub-design-system 0.1.4 → 0.1.5

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.
@@ -4,10 +4,15 @@ export declare const TreeTexts: {
4
4
  'button.recenter.tree': string;
5
5
  'button.download.tree': string;
6
6
  'button.download.penn': string;
7
+ 'button.import.penn': string;
8
+ 'button.import': string;
9
+ 'button.revision.tree': string;
7
10
  'button.info': string;
8
11
  'placeholder.sentence.notparsed': string;
9
12
  'date.parsed': string;
10
13
  'button.search': string;
14
+ 'modal.import.penn.title': string;
15
+ 'modal.import.penn.placeholder': string;
11
16
  'label.syntactic.category': string;
12
17
  'label.pos.tag': string;
13
18
  'label.token.addTag': string;
@@ -19,10 +24,15 @@ export declare const TreeTexts: {
19
24
  'button.recenter.tree': string;
20
25
  'button.download.tree': string;
21
26
  'button.download.penn': string;
27
+ 'button.import.penn': string;
28
+ 'button.import': string;
29
+ 'button.revision.tree': string;
22
30
  'button.info': string;
23
31
  'placeholder.sentence.notparsed': string;
24
32
  'date.parsed': string;
25
33
  'button.search': string;
34
+ 'modal.import.penn.title': string;
35
+ 'modal.import.penn.placeholder': string;
26
36
  'label.syntactic.category': string;
27
37
  'label.pos.tag': string;
28
38
  'label.token.addTag': string;
@@ -34,9 +44,14 @@ export declare const TreeTexts: {
34
44
  'button.recenter.tree': string;
35
45
  'button.download.tree': string;
36
46
  'button.download.penn': string;
47
+ 'button.import.penn': string;
48
+ 'button.import': string;
49
+ 'button.revision.tree': string;
37
50
  'button.info': string;
38
51
  'date.parsed': string;
39
52
  'button.search': string;
53
+ 'modal.import.penn.title': string;
54
+ 'modal.import.penn.placeholder': string;
40
55
  'label.syntactic.category': string;
41
56
  'label.pos.tag': string;
42
57
  'label.token.addTag': string;
@@ -4,10 +4,15 @@ export const TreeTexts = {
4
4
  'button.recenter.tree': 'Recenter tree',
5
5
  'button.download.tree': 'Download tree as image',
6
6
  'button.download.penn': 'Download in Penn Tree format',
7
+ 'button.import.penn': 'Import Penn Tree format',
8
+ 'button.import': 'Import',
9
+ 'button.revision.tree': 'Open revision tree',
7
10
  'button.info': 'Display translations and glosses',
8
11
  'placeholder.sentence.notparsed': 'This sentence has not been parsed.',
9
12
  'date.parsed': 'Parsing executed at:',
10
13
  'button.search': 'Search',
14
+ 'modal.import.penn.title': 'Import Penn Treebank',
15
+ 'modal.import.penn.placeholder': 'Paste a Penn Treebank expression…',
11
16
  'label.syntactic.category': 'Syntactic Category',
12
17
  'label.pos.tag': 'POS Tag',
13
18
  'label.token.addTag': 'add tag',
@@ -19,10 +24,15 @@ export const TreeTexts = {
19
24
  'button.recenter.tree': 'Recentralizar árvore',
20
25
  'button.download.tree': 'Baixar árvore como imagem',
21
26
  'button.download.penn': 'Baixar no formato Penn Tree',
27
+ 'button.import.penn': 'Importar formato Penn Tree',
28
+ 'button.import': 'Importar',
29
+ 'button.revision.tree': 'Abrir árvore de revisão',
22
30
  'button.info': 'Mostrar traduções e glosas',
23
31
  'placeholder.sentence.notparsed': 'O parser não foi realizado nesta sentença.',
24
32
  'date.parsed': 'Parser executado às:',
25
33
  'button.search': 'Buscar',
34
+ 'modal.import.penn.title': 'Importar Penn Treebank',
35
+ 'modal.import.penn.placeholder': 'Cole uma expressão Penn Treebank…',
26
36
  'label.syntactic.category': 'Categoria Sintática',
27
37
  'label.pos.tag': 'Etiqueta POS',
28
38
  'label.token.addTag': 'adicionar etiqueta',
@@ -34,9 +44,14 @@ export const TreeTexts = {
34
44
  'button.recenter.tree': 'Ricentra albero',
35
45
  'button.download.tree': 'Scarica albero come immagine',
36
46
  'button.download.penn': 'Scarica in formato Penn Tree',
47
+ 'button.import.penn': 'Importa formato Penn Tree',
48
+ 'button.import': 'Importa',
49
+ 'button.revision.tree': 'Apri albero di revisione',
37
50
  'button.info': 'Visualizza traduzioni e glosse',
38
51
  'date.parsed': 'Parser eseguito alle:',
39
52
  'button.search': 'Cerca',
53
+ 'modal.import.penn.title': 'Importa Penn Treebank',
54
+ 'modal.import.penn.placeholder': 'Incolla un’espressione Penn Treebank…',
40
55
  'label.syntactic.category': 'Categoria Sintattica',
41
56
  'label.pos.tag': 'Etichetta POS',
42
57
  'label.token.addTag': 'aggiungi etichetta',
@@ -1,6 +1,10 @@
1
1
  import { Core } from 'cytoscape';
2
2
  import { Struct } from '../../configs/types/Struct';
3
3
  import './style.scss';
4
+ type RevisionTreeLink = {
5
+ url: string;
6
+ openInNewTab?: boolean;
7
+ };
4
8
  type Props = {
5
9
  struct?: Struct;
6
10
  expression?: string;
@@ -12,7 +16,9 @@ type Props = {
12
16
  cyRef?: React.MutableRefObject<Core | null>;
13
17
  onClickExpression?: () => void;
14
18
  onExpand?: () => void;
19
+ onImportPenn?: (expression: string) => Promise<void> | void;
15
20
  onReadyCustom?: (thisCy: Core) => void;
21
+ revisionTreeLink?: RevisionTreeLink;
16
22
  };
17
- export default function TreeView({ struct, expression, selector, translations, wheelSensitivity, renderWithInfo, placeholder, cyRef, onClickExpression, onExpand, onReadyCustom, }: Props): import("react").JSX.Element;
23
+ export default function TreeView({ struct, expression, selector, translations, wheelSensitivity, renderWithInfo, placeholder, cyRef, onClickExpression, onExpand, onImportPenn, onReadyCustom, revisionTreeLink, }: Props): import("react").JSX.Element;
18
24
  export {};
@@ -3,20 +3,22 @@ import { saveAs } from 'file-saver';
3
3
  import html2canvas from 'html2canvas';
4
4
  import { useEffect, useState } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
- import { IconButton } from '../../primitives';
7
6
  import AppPlaceholder from '../../common/AppPlaceholder';
8
7
  import DateUtils from '../../functions/DateUtils';
9
8
  import SentenceUtils from '../../functions/SentenceUtils';
9
+ import { IconButton } from '../../primitives';
10
+ import TreeViewImportPenn from './TreeViewImportPenn';
10
11
  import TreeViewSearch from './TreeViewSearch/TreeViewSearch';
11
12
  import CytoscapeTreeConverter from './cytoscape/CytoscapeTreeConverter';
12
13
  import SyntreesCytoscape from './cytoscape/SyntreesCytoscape';
13
14
  import './style.scss';
14
- export default function TreeView({ struct, expression, selector = 'canvas-tree', translations, wheelSensitivity, renderWithInfo = false, placeholder, cyRef, onClickExpression, onExpand, onReadyCustom, }) {
15
+ export default function TreeView({ struct, expression, selector = 'canvas-tree', translations, wheelSensitivity, renderWithInfo = false, placeholder, cyRef, onClickExpression, onExpand, onImportPenn, onReadyCustom, revisionTreeLink, }) {
15
16
  const { t } = useTranslation('tree');
16
17
  const [cy, setCy] = useState(null);
17
18
  const [showInfo, setShowInfo] = useState(renderWithInfo);
18
19
  const [invalid, setInvalid] = useState();
19
20
  const [showSearchModal, setShowSearchModal] = useState(false);
21
+ const [showImportModal, setShowImportModal] = useState(false);
20
22
  const [searchCriteria, setSearchCriteria] = useState({
21
23
  syntacticCategory: [],
22
24
  posTag: [],
@@ -111,6 +113,21 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
111
113
  const closeSearchModal = () => {
112
114
  setShowSearchModal(false);
113
115
  };
116
+ const openImportModal = () => {
117
+ setShowImportModal(true);
118
+ };
119
+ const closeImportModal = () => {
120
+ setShowImportModal(false);
121
+ };
122
+ const goToRevisionTree = () => {
123
+ if (!revisionTreeLink?.url)
124
+ return;
125
+ if (revisionTreeLink.openInNewTab) {
126
+ window.open(revisionTreeLink.url, '_blank', 'noopener,noreferrer');
127
+ return;
128
+ }
129
+ window.location.assign(revisionTreeLink.url);
130
+ };
114
131
  useEffect(() => {
115
132
  setInvalid(undefined);
116
133
  load();
@@ -119,38 +136,50 @@ export default function TreeView({ struct, expression, selector = 'canvas-tree',
119
136
  return (_jsx(AppPlaceholder, { text: placeholder || t('placeholder.sentence.notparsed') }));
120
137
  }
121
138
  return (_jsxs("div", { className: "tree-view-container", children: [invalid && (_jsx("div", { className: "tree-placeholder-overlay", children: _jsx(AppPlaceholder, { text: placeholder || t('placeholder.sentence.notparsed') }) })), _jsx("div", { className: "floating-buttons", children: cy &&
122
- getButtons(generateImage, reset, onClickExpression || downloadPsd, toggleInfo, onExpand, expression, openSearchModal)
139
+ getButtons(generateImage, reset, onClickExpression || downloadPsd, toggleInfo, onExpand, expression, openSearchModal, goToRevisionTree, revisionTreeLink, onImportPenn ? openImportModal : undefined)
123
140
  .filter((btn) => btn.condition)
124
141
  .map((btn, i) => {
125
142
  return (_jsx(IconButton, { name: btn.icon, title: t(btn.title), onClick: btn.onClick, size: "medium", iconSize: "medium", mode: "ghost" }, i));
126
- }) }), showSearchModal && cy && (_jsx(TreeViewSearch, { struct: struct, cy: cy, onClose: closeSearchModal, searchCriteria: searchCriteria, setSearchCriteria: setSearchCriteria })), _jsx("div", { id: selector, className: "canvas-tree" }), showInfo && (_jsxs("div", { className: "info", children: [_jsx("span", { children: SentenceUtils.getAsText(struct) }), translations &&
143
+ }) }), showSearchModal && cy && (_jsx(TreeViewSearch, { struct: struct, cy: cy, onClose: closeSearchModal, searchCriteria: searchCriteria, setSearchCriteria: setSearchCriteria })), showImportModal && onImportPenn && (_jsx(TreeViewImportPenn, { onClose: closeImportModal, onImport: onImportPenn })), _jsx("div", { id: selector, className: "canvas-tree" }), showInfo && (_jsxs("div", { className: "info", children: [_jsx("span", { children: SentenceUtils.getAsText(struct) }), translations &&
127
144
  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')] }))] }))] }));
128
145
  }
129
- const getButtons = (generateImage, reset, downloadPsd, toggleInfo, onExpand, expression, openSearchModal) => [
146
+ const getButtons = (generateImage, reset, downloadPsd, toggleInfo, onExpand, expression, openSearchModal, goToRevisionTree, revisionTreeLink, openImportModal) => [
130
147
  {
131
148
  condition: true,
132
149
  title: 'button.download.tree',
133
150
  onClick: generateImage,
134
151
  icon: 'download',
135
152
  },
136
- {
137
- condition: true,
138
- title: 'button.recenter.tree',
139
- onClick: reset,
140
- icon: 'center_focus_weak',
141
- },
142
153
  {
143
154
  condition: !!expression,
144
155
  title: 'button.download.penn',
145
156
  onClick: downloadPsd,
146
157
  icon: 'graph_4',
147
158
  },
159
+ {
160
+ condition: !!openImportModal,
161
+ title: 'button.import.penn',
162
+ onClick: openImportModal || (() => { }),
163
+ icon: 'upload',
164
+ },
165
+ {
166
+ condition: true,
167
+ title: 'button.recenter.tree',
168
+ onClick: reset,
169
+ icon: 'center_focus_weak',
170
+ },
148
171
  {
149
172
  condition: !!onExpand,
150
173
  title: 'button.expand.tree',
151
174
  onClick: onExpand || (() => { }),
152
175
  icon: 'open_in_full',
153
176
  },
177
+ {
178
+ condition: !!revisionTreeLink?.url,
179
+ title: 'button.revision.tree',
180
+ onClick: goToRevisionTree || (() => { }),
181
+ icon: 'edit_square',
182
+ },
154
183
  {
155
184
  condition: true,
156
185
  title: 'button.info',
@@ -0,0 +1,7 @@
1
+ import './style.scss';
2
+ type Props = {
3
+ onClose: () => void;
4
+ onImport: (expression: string) => Promise<void> | void;
5
+ };
6
+ export default function TreeViewImportPenn({ onClose, onImport }: Props): import("react").JSX.Element;
7
+ export {};
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import AppModal from '../../../common/AppModal';
5
+ import './style.scss';
6
+ export default function TreeViewImportPenn({ onClose, onImport }) {
7
+ const { t } = useTranslation('tree');
8
+ const [expression, setExpression] = useState('');
9
+ const [importing, setImporting] = useState(false);
10
+ const handleImport = async () => {
11
+ const value = expression.trim();
12
+ if (!value || importing)
13
+ return;
14
+ setImporting(true);
15
+ try {
16
+ await onImport(value);
17
+ onClose();
18
+ }
19
+ finally {
20
+ setImporting(false);
21
+ }
22
+ };
23
+ return (_jsx(AppModal, { title: t('modal.import.penn.title'), close: onClose, confirm: () => {
24
+ void handleImport();
25
+ }, confirmLabel: t('button.import'), disableConfirm: !expression.trim() || importing, disableClose: importing, className: "modal-import-penn", children: _jsx("textarea", { name: "penn-expression", value: expression, rows: 15, placeholder: t('modal.import.penn.placeholder'), disabled: importing, onChange: (e) => setExpression(e.target.value) }) }));
26
+ }
@@ -0,0 +1,2 @@
1
+ import TreeViewImportPenn from './TreeViewImportPenn';
2
+ export default TreeViewImportPenn;
@@ -0,0 +1,2 @@
1
+ import TreeViewImportPenn from './TreeViewImportPenn';
2
+ export default TreeViewImportPenn;
@@ -0,0 +1,22 @@
1
+ .modal-import-penn {
2
+ height: 80vh;
3
+ top: 45% !important;
4
+
5
+ .body {
6
+ display: flex;
7
+ flex: 1 1 auto;
8
+
9
+ textarea {
10
+ flex: 1;
11
+ width: 100%;
12
+ resize: none;
13
+ font-family: var(--font-mono, monospace);
14
+ padding: 12px;
15
+ border: var(--border-default);
16
+ border-radius: var(--radius-100);
17
+ background-color: var(--background-default);
18
+ color: var(--text-primary);
19
+ font-size: 14px;
20
+ }
21
+ }
22
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corpushub-design-system",
3
3
  "private": false,
4
- "version": "0.1.4",
4
+ "version": "0.1.5",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {