tycho-components 0.36.6 → 0.36.8
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.
- package/dist/common/AppClarity/AppClarity.d.ts +16 -0
- package/dist/common/AppClarity/AppClarity.js +48 -0
- package/dist/common/AppClarity/index.d.ts +2 -0
- package/dist/common/AppClarity/index.js +2 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +1 -0
- package/dist/features/TreeView/TreeView.d.ts +3 -3
- package/dist/features/TreeView/TreeView.js +38 -38
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
clarity?: (...args: unknown[]) => void;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Microsoft Clarity loader — mirrors {@link AppAnalytics} (null render, injects
|
|
8
|
+
* the vendor tag on mount from a Vite env var). Set `VITE_APP_CLARITY_ID`.
|
|
9
|
+
*
|
|
10
|
+
* On top of the plain snippet it stitches every session of the logged-in Tycho
|
|
11
|
+
* user under their stable `uid` (decoded client-side from the `jwt_token_tycho`
|
|
12
|
+
* cookie) via `clarity('identify', …)`, so cross-module full-page navigations
|
|
13
|
+
* count as ONE identified user instead of N anonymous ones. The friendly name is
|
|
14
|
+
* PII — drop the last `identify` argument for a stricter privacy posture.
|
|
15
|
+
*/
|
|
16
|
+
export default function AppClarity(): null;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Microsoft Clarity loader — mirrors {@link AppAnalytics} (null render, injects
|
|
4
|
+
* the vendor tag on mount from a Vite env var). Set `VITE_APP_CLARITY_ID`.
|
|
5
|
+
*
|
|
6
|
+
* On top of the plain snippet it stitches every session of the logged-in Tycho
|
|
7
|
+
* user under their stable `uid` (decoded client-side from the `jwt_token_tycho`
|
|
8
|
+
* cookie) via `clarity('identify', …)`, so cross-module full-page navigations
|
|
9
|
+
* count as ONE identified user instead of N anonymous ones. The friendly name is
|
|
10
|
+
* PII — drop the last `identify` argument for a stricter privacy posture.
|
|
11
|
+
*/
|
|
12
|
+
export default function AppClarity() {
|
|
13
|
+
const CLARITY_ID = import.meta.env.VITE_APP_CLARITY_ID;
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!CLARITY_ID) {
|
|
16
|
+
console.warn('Microsoft Clarity project ID not set.');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// Inject the official Clarity loader (same shape as Clarity's install snippet).
|
|
20
|
+
const loader = document.createElement('script');
|
|
21
|
+
loader.innerHTML =
|
|
22
|
+
`(function(c,l,a,r,i,t,y){c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};` +
|
|
23
|
+
`t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;` +
|
|
24
|
+
`y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y)})` +
|
|
25
|
+
`(window,document,"clarity","script","${CLARITY_ID}");`;
|
|
26
|
+
document.head.appendChild(loader);
|
|
27
|
+
// Identify the logged-in Tycho user so sessions stitch under one real id.
|
|
28
|
+
try {
|
|
29
|
+
const match = document.cookie.match(/(?:^|;\s*)jwt_token_tycho=([^;]+)/);
|
|
30
|
+
if (match) {
|
|
31
|
+
let b64 = match[1].split('.')[1].replace(/-/g, '+').replace(/_/g, '/');
|
|
32
|
+
b64 += '==='.slice((b64.length + 3) % 4);
|
|
33
|
+
const payload = JSON.parse(decodeURIComponent(atob(b64)
|
|
34
|
+
.split('')
|
|
35
|
+
.map((ch) => '%' + ('00' + ch.charCodeAt(0).toString(16)).slice(-2))
|
|
36
|
+
.join('')));
|
|
37
|
+
if (payload?.uid) {
|
|
38
|
+
window.clarity?.('identify', payload.uid, undefined, undefined, payload.name || undefined);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
window.clarity?.('consent');
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
/* not logged in / unparseable — track anonymously */
|
|
45
|
+
}
|
|
46
|
+
}, [CLARITY_ID]);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as AppAnalytics } from './AppAnalytics';
|
|
2
|
+
export { default as AppClarity } from './AppClarity';
|
|
2
3
|
export { default as AppCard } from './AppCard/AppCard';
|
|
3
4
|
export { default as AppClipboard } from './AppClipboard';
|
|
4
5
|
export { default as AppColorpicker } from './AppColorpicker';
|
package/dist/common/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as AppAnalytics } from './AppAnalytics';
|
|
2
|
+
export { default as AppClarity } from './AppClarity';
|
|
2
3
|
export { default as AppCard } from './AppCard/AppCard';
|
|
3
4
|
export { default as AppClipboard } from './AppClipboard';
|
|
4
5
|
export { default as AppColorpicker } from './AppColorpicker';
|
|
@@ -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
|
];
|