tycho-components 0.36.5 → 0.36.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.
|
@@ -59,7 +59,7 @@ export default function AppForm({ fields, form, prefix, onChangeFunctions = {},
|
|
|
59
59
|
return (_jsx(TextField, { attr: name, label: field.name, createdForm: form, disabled: field.disabled, required: field.required, onChange: (value) => handleChange?.(value), multiline: true, rows: field.rows, height: "100%", infoText: field.infoText, defaultEndAdornments: field.infoText ? ['info'] : ['close'] }, name));
|
|
60
60
|
}
|
|
61
61
|
if (field.type === 'color') {
|
|
62
|
-
return (_jsx(FormColorField, { attr: name, label: field.name, form: form, disabled: field.disabled, tooltipText: field.tooltipText }, name));
|
|
62
|
+
return (_jsx(FormColorField, { attr: name, label: field.name, form: form, disabled: field.disabled, tooltipText: field.tooltipText, onChange: (value) => handleChange?.(value) }, name));
|
|
63
63
|
}
|
|
64
64
|
const handleBlur = getOnBlurFn(field.attr);
|
|
65
65
|
return (_jsx(TextField, { attr: name, label: field.size === 'small' ? undefined : field.name, placeholder: field.size === 'small' ? field.name : undefined, createdForm: form, mask: field.mask, blurMask: field.blurMask, disabled: field.disabled, required: field.required, onChange: (value) => handleChange?.(value), height: field.size === 'small' ? '32px' : undefined, onBlur: handleBlur, infoText: field.infoText, defaultEndAdornments: field.infoText ? ['info'] : ['close'] }, name));
|
|
@@ -6,6 +6,7 @@ type Props<TFieldValues extends FieldValues = FieldValues, TContext = any, TTran
|
|
|
6
6
|
form: UseFormReturn<TFieldValues, TContext, TTransformedValues>;
|
|
7
7
|
disabled?: boolean;
|
|
8
8
|
tooltipText?: string;
|
|
9
|
+
onChange?: (value: string) => void;
|
|
9
10
|
};
|
|
10
|
-
export default function FormColorField<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues>({ attr, label, form, disabled, tooltipText, }: Props<TFieldValues, TContext, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export default function FormColorField<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues>({ attr, label, form, disabled, tooltipText, onChange, }: Props<TFieldValues, TContext, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
11
12
|
export {};
|
|
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
5
5
|
import { Button, Icon, Tooltip } from 'tycho-storybook';
|
|
6
6
|
import '../AppColorpicker/style.scss';
|
|
7
7
|
const defaultColor = '#FFFFFF';
|
|
8
|
-
export default function FormColorField({ attr, label, form, disabled, tooltipText, }) {
|
|
8
|
+
export default function FormColorField({ attr, label, form, disabled, tooltipText, onChange, }) {
|
|
9
9
|
const fieldName = attr;
|
|
10
10
|
const { t } = useTranslation('common');
|
|
11
11
|
const formValue = form.watch(fieldName);
|
|
@@ -16,6 +16,7 @@ export default function FormColorField({ attr, label, form, disabled, tooltipTex
|
|
|
16
16
|
}, [formValue]);
|
|
17
17
|
const handleConfirm = () => {
|
|
18
18
|
form.setValue(fieldName, color, { shouldDirty: true });
|
|
19
|
+
onChange?.(color);
|
|
19
20
|
setOpenColor(false);
|
|
20
21
|
};
|
|
21
22
|
return (_jsxs("div", { className: "form-color-field", children: [_jsxs("div", { className: "form-color-field-label", children: [_jsx("span", { children: label }), tooltipText && (_jsx(Tooltip, { title: tooltipText, children: _jsx("span", { children: _jsx(Icon, { name: "help", className: "info", size: "x-small" }) }) }))] }), _jsxs("div", { className: "color-picker-container", children: [_jsx("div", { className: "swatch", style: { backgroundColor: color }, onClick: () => !disabled && setOpenColor(!openColor), onKeyDown: () => !disabled && setOpenColor(!openColor), role: "link", "aria-label": "open color picker", tabIndex: disabled ? -1 : 0 }), openColor && !disabled && (_jsxs(_Fragment, { children: [_jsx(HexColorPicker, { color: color, onChange: setColor }), _jsxs("div", { className: "buttons", children: [_jsx(Button, { text: t('button.confirm'), onClick: handleConfirm, size: "x-small" }), _jsx(Button, { text: t('button.cancel'), onClick: () => setOpenColor(false), color: "danger", size: "x-small" })] })] }))] })] }));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Core } from
|
|
2
|
-
import { Struct } from
|
|
3
|
-
import
|
|
1
|
+
import { Core } from 'cytoscape';
|
|
2
|
+
import { Struct } from '../../configs/types/Struct';
|
|
3
|
+
import './style.scss';
|
|
4
4
|
type Props = {
|
|
5
5
|
struct?: Struct;
|
|
6
6
|
expression?: string;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { saveAs } from
|
|
3
|
-
import html2canvas from
|
|
4
|
-
import { useEffect, useState } from
|
|
5
|
-
import { useTranslation } from
|
|
6
|
-
import { IconButton } from
|
|
7
|
-
import AppPlaceholder from
|
|
8
|
-
import DateUtils from
|
|
9
|
-
import SentenceUtils from
|
|
10
|
-
import TreeViewSearch from
|
|
11
|
-
import CytoscapeTreeConverter from
|
|
12
|
-
import SyntreesCytoscape from
|
|
13
|
-
import
|
|
14
|
-
export default function TreeView({ struct, expression, selector =
|
|
15
|
-
const { t } = useTranslation(
|
|
2
|
+
import { saveAs } from 'file-saver';
|
|
3
|
+
import html2canvas from 'html2canvas';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { IconButton } from 'tycho-storybook';
|
|
7
|
+
import AppPlaceholder from '../../common/AppPlaceholder';
|
|
8
|
+
import DateUtils from '../../functions/DateUtils';
|
|
9
|
+
import SentenceUtils from '../../functions/SentenceUtils';
|
|
10
|
+
import TreeViewSearch from './TreeViewSearch/TreeViewSearch';
|
|
11
|
+
import CytoscapeTreeConverter from './cytoscape/CytoscapeTreeConverter';
|
|
12
|
+
import SyntreesCytoscape from './cytoscape/SyntreesCytoscape';
|
|
13
|
+
import './style.scss';
|
|
14
|
+
export default function TreeView({ struct, expression, selector = 'canvas-tree', translations, wheelSensitivity, renderWithInfo = false, placeholder, cyRef, onClickExpression, onExpand, onReadyCustom, }) {
|
|
15
|
+
const { t } = useTranslation('tree');
|
|
16
16
|
const [cy, setCy] = useState(null);
|
|
17
17
|
const [showInfo, setShowInfo] = useState(renderWithInfo);
|
|
18
18
|
const [invalid, setInvalid] = useState();
|
|
@@ -27,7 +27,7 @@ export default function TreeView({ struct, expression, selector = "canvas-tree",
|
|
|
27
27
|
setCy(null);
|
|
28
28
|
const element = document.getElementById(selector);
|
|
29
29
|
if (element)
|
|
30
|
-
element.innerHTML =
|
|
30
|
+
element.innerHTML = '';
|
|
31
31
|
if (!struct)
|
|
32
32
|
return;
|
|
33
33
|
let tree;
|
|
@@ -60,8 +60,8 @@ export default function TreeView({ struct, expression, selector = "canvas-tree",
|
|
|
60
60
|
const downloadPsd = () => {
|
|
61
61
|
if (!expression)
|
|
62
62
|
return;
|
|
63
|
-
const blob = new Blob([expression], { type:
|
|
64
|
-
saveAs(blob,
|
|
63
|
+
const blob = new Blob([expression], { type: 'text/plain;charset=utf-8' });
|
|
64
|
+
saveAs(blob, 'sentence.psd');
|
|
65
65
|
};
|
|
66
66
|
const generateImage = () => {
|
|
67
67
|
if (!cy)
|
|
@@ -70,13 +70,13 @@ export default function TreeView({ struct, expression, selector = "canvas-tree",
|
|
|
70
70
|
if (!cyContainer)
|
|
71
71
|
return;
|
|
72
72
|
html2canvas(cyContainer, {
|
|
73
|
-
backgroundColor:
|
|
73
|
+
backgroundColor: 'white',
|
|
74
74
|
}).then((canvas) => {
|
|
75
75
|
canvas.toBlob((blob) => {
|
|
76
76
|
if (blob === null)
|
|
77
77
|
return;
|
|
78
|
-
saveAs(blob,
|
|
79
|
-
},
|
|
78
|
+
saveAs(blob, 'tree.jpg');
|
|
79
|
+
}, 'image/jpeg', 1.0);
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
82
|
const reset = () => {
|
|
@@ -92,9 +92,9 @@ export default function TreeView({ struct, expression, selector = "canvas-tree",
|
|
|
92
92
|
if (!token.ec) {
|
|
93
93
|
const leafId = token.p?.toString();
|
|
94
94
|
const converter = new CytoscapeTreeConverter();
|
|
95
|
-
converter[
|
|
95
|
+
converter['extraInfo'] = extraInfo;
|
|
96
96
|
const newLabel = converter.getLabelLeaf(token);
|
|
97
|
-
thisCy.$id(leafId).data(
|
|
97
|
+
thisCy.$id(leafId).data('label', newLabel);
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
};
|
|
@@ -116,51 +116,51 @@ export default function TreeView({ struct, expression, selector = "canvas-tree",
|
|
|
116
116
|
load();
|
|
117
117
|
}, [struct]);
|
|
118
118
|
if (!struct) {
|
|
119
|
-
return (_jsx(AppPlaceholder, { text: placeholder || t(
|
|
119
|
+
return (_jsx(AppPlaceholder, { text: placeholder || t('placeholder.sentence.notparsed') }));
|
|
120
120
|
}
|
|
121
|
-
return (_jsxs("div", { className: "tree-view-container", children: [invalid && (_jsx("div", { className: "tree-placeholder-overlay", children: _jsx(AppPlaceholder, { text: placeholder || t(
|
|
121
|
+
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
122
|
getButtons(generateImage, reset, onClickExpression || downloadPsd, toggleInfo, onExpand, expression, openSearchModal)
|
|
123
123
|
.filter((btn) => btn.condition)
|
|
124
124
|
.map((btn, i) => {
|
|
125
|
-
return (_jsx(IconButton, { name: btn.icon, title: t(btn.title), onClick: btn.onClick, size: "
|
|
125
|
+
return (_jsx(IconButton, { name: btn.icon, title: t(btn.title), onClick: btn.onClick, size: "medium", iconSize: "medium", mode: "ghost" }, i));
|
|
126
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 &&
|
|
127
|
-
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(
|
|
127
|
+
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
128
|
}
|
|
129
129
|
const getButtons = (generateImage, reset, downloadPsd, toggleInfo, onExpand, expression, openSearchModal) => [
|
|
130
130
|
{
|
|
131
131
|
condition: true,
|
|
132
|
-
title:
|
|
132
|
+
title: 'button.download.tree',
|
|
133
133
|
onClick: generateImage,
|
|
134
|
-
icon:
|
|
134
|
+
icon: 'download',
|
|
135
135
|
},
|
|
136
136
|
{
|
|
137
137
|
condition: true,
|
|
138
|
-
title:
|
|
138
|
+
title: 'button.recenter.tree',
|
|
139
139
|
onClick: reset,
|
|
140
|
-
icon:
|
|
140
|
+
icon: 'center_focus_weak',
|
|
141
141
|
},
|
|
142
142
|
{
|
|
143
143
|
condition: !!expression,
|
|
144
|
-
title:
|
|
144
|
+
title: 'button.download.penn',
|
|
145
145
|
onClick: downloadPsd,
|
|
146
|
-
icon:
|
|
146
|
+
icon: 'graph_4',
|
|
147
147
|
},
|
|
148
148
|
{
|
|
149
149
|
condition: !!onExpand,
|
|
150
|
-
title:
|
|
150
|
+
title: 'button.expand.tree',
|
|
151
151
|
onClick: onExpand || (() => { }),
|
|
152
|
-
icon:
|
|
152
|
+
icon: 'open_in_full',
|
|
153
153
|
},
|
|
154
154
|
{
|
|
155
155
|
condition: true,
|
|
156
|
-
title:
|
|
156
|
+
title: 'button.info',
|
|
157
157
|
onClick: toggleInfo,
|
|
158
|
-
icon:
|
|
158
|
+
icon: 'info',
|
|
159
159
|
},
|
|
160
160
|
{
|
|
161
161
|
condition: true,
|
|
162
|
-
title:
|
|
162
|
+
title: 'button.search',
|
|
163
163
|
onClick: openSearchModal || (() => { }),
|
|
164
|
-
icon:
|
|
164
|
+
icon: 'search',
|
|
165
165
|
},
|
|
166
166
|
];
|