tycho-components 0.46.0 → 0.46.2
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.
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import './style.scss';
|
|
2
|
-
import { CollapsedPageRenderElement, PageRenderViewProps } from './types';
|
|
3
|
-
|
|
2
|
+
import { CollapsedPageRenderElement, PageRenderElement, PageRenderViewProps } from './types';
|
|
3
|
+
/** Ensure PARTICIPANT elements carry a sentence uid (API or next-token look-ahead). */
|
|
4
|
+
export declare function withParticipantSentenceUids(elements: PageRenderElement[]): PageRenderElement[];
|
|
5
|
+
export default function PageRenderView({ elements, selectedTier, corpus, displayTags, showLineNumbers, highlightSentenceUid, activeTokenKey, selectedTokenKeys, tokenSelectionKey, getDisplayValue, getTokenStyle, getTokenClassName, isTokenEdited, getParticipantName, getParticipantColor, onTokenClick, onTokenHover, onParticipantHover, onParticipantClick, wrapToken, renderTokenSuffix, }: PageRenderViewProps): import("react").JSX.Element;
|
|
4
6
|
export declare function findPunctuationAfterCollapsedJunction(items: CollapsedPageRenderElement[], junctionIndex: number): number | undefined;
|
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { Fragment } from 'react';
|
|
2
|
+
import { Fragment, useMemo } from 'react';
|
|
3
3
|
import cx from 'classnames';
|
|
4
4
|
import './style.scss';
|
|
5
5
|
import collapseElementsForTier from './collapseElementsForTier';
|
|
6
6
|
import isTokenRefVisible, { tokenRefToToken } from './tokenUtils';
|
|
7
7
|
import { PageRenderElementType, } from './types';
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/** Ensure PARTICIPANT elements carry a sentence uid (API or next-token look-ahead). */
|
|
9
|
+
export function withParticipantSentenceUids(elements) {
|
|
10
|
+
return elements.map((element, index) => {
|
|
11
|
+
if (element.type !== PageRenderElementType.PARTICIPANT ||
|
|
12
|
+
!element.participant ||
|
|
13
|
+
element.uid) {
|
|
14
|
+
return element;
|
|
15
|
+
}
|
|
16
|
+
for (let i = index + 1; i < elements.length; i++) {
|
|
17
|
+
const next = elements[i];
|
|
18
|
+
if (next.type === PageRenderElementType.PARTICIPANT)
|
|
19
|
+
break;
|
|
20
|
+
if (next.token?.uid) {
|
|
21
|
+
return { ...element, uid: next.token.uid };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return element;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export default function PageRenderView({ elements, selectedTier, corpus, displayTags = false, showLineNumbers = true, highlightSentenceUid, activeTokenKey, selectedTokenKeys, tokenSelectionKey, getDisplayValue, getTokenStyle, getTokenClassName, isTokenEdited, getParticipantName, getParticipantColor, onTokenClick, onTokenHover, onParticipantHover, onParticipantClick, wrapToken, renderTokenSuffix, }) {
|
|
28
|
+
const elementsWithUids = useMemo(() => withParticipantSentenceUids(elements), [elements]);
|
|
29
|
+
const collapsed = collapseElementsForTier(elementsWithUids, selectedTier, corpus);
|
|
10
30
|
const punctuationBeforeBreak = new Map();
|
|
11
31
|
const punctuationIndexes = new Set();
|
|
12
32
|
collapsed.forEach((item, index) => {
|
|
@@ -17,7 +37,7 @@ export default function PageRenderView({ elements, selectedTier, corpus, display
|
|
|
17
37
|
punctuationIndexes.add(punctuationIndex);
|
|
18
38
|
});
|
|
19
39
|
const renderItem = (item) => (_jsx(PageRenderElementItem, { item: item, highlight: highlightSentenceUid != null &&
|
|
20
|
-
sentenceUidForItem(item) === highlightSentenceUid, showLineNumbers: showLineNumbers, displayTags: displayTags, activeTokenKey: activeTokenKey, selectedTokenKeys: selectedTokenKeys, tokenSelectionKey: tokenSelectionKey, getDisplayValue: getDisplayValue, getTokenStyle: getTokenStyle, getTokenClassName: getTokenClassName, isTokenEdited: isTokenEdited, getParticipantName: getParticipantName, getParticipantColor: getParticipantColor, onTokenClick: onTokenClick, onTokenHover: onTokenHover, onParticipantHover: onParticipantHover, wrapToken: wrapToken, renderTokenSuffix: renderTokenSuffix }, item.key));
|
|
40
|
+
sentenceUidForItem(item) === highlightSentenceUid, showLineNumbers: showLineNumbers, displayTags: displayTags, activeTokenKey: activeTokenKey, selectedTokenKeys: selectedTokenKeys, tokenSelectionKey: tokenSelectionKey, getDisplayValue: getDisplayValue, getTokenStyle: getTokenStyle, getTokenClassName: getTokenClassName, isTokenEdited: isTokenEdited, getParticipantName: getParticipantName, getParticipantColor: getParticipantColor, onTokenClick: onTokenClick, onTokenHover: onTokenHover, onParticipantHover: onParticipantHover, onParticipantClick: onParticipantClick, wrapToken: wrapToken, renderTokenSuffix: renderTokenSuffix }, item.key));
|
|
21
41
|
return (_jsx("div", { className: "page-render-elements", children: collapsed.map((item, index) => {
|
|
22
42
|
if (punctuationIndexes.has(index))
|
|
23
43
|
return null;
|
|
@@ -58,9 +78,11 @@ function sentenceUidForItem(item) {
|
|
|
58
78
|
return item.token.uid;
|
|
59
79
|
if (item.kind === 'single' && item.element.token)
|
|
60
80
|
return item.element.token.uid;
|
|
81
|
+
if (item.kind === 'single' && item.element.uid)
|
|
82
|
+
return item.element.uid;
|
|
61
83
|
return undefined;
|
|
62
84
|
}
|
|
63
|
-
function PageRenderElementItem({ item, highlight, showLineNumbers, displayTags, activeTokenKey, selectedTokenKeys, tokenSelectionKey, getDisplayValue, getTokenStyle, getTokenClassName, isTokenEdited, getParticipantName, getParticipantColor, onTokenClick, onTokenHover, onParticipantHover, wrapToken, renderTokenSuffix, }) {
|
|
85
|
+
function PageRenderElementItem({ item, highlight, showLineNumbers, displayTags, activeTokenKey, selectedTokenKeys, tokenSelectionKey, getDisplayValue, getTokenStyle, getTokenClassName, isTokenEdited, getParticipantName, getParticipantColor, onTokenClick, onTokenHover, onParticipantHover, onParticipantClick, wrapToken, renderTokenSuffix, }) {
|
|
64
86
|
if (item.kind === 'collapsedJunction') {
|
|
65
87
|
return (_jsx(TokenNode, { refToken: item.token, splitIdx: item.splitIdx ?? 0, isSplit: true, isCollapsedJunction: true, highlight: highlight, displayTags: displayTags, activeTokenKey: activeTokenKey, selectedTokenKeys: selectedTokenKeys, tokenSelectionKey: tokenSelectionKey, getDisplayValue: getDisplayValue, getTokenStyle: getTokenStyle, getTokenClassName: getTokenClassName, isTokenEdited: isTokenEdited, onTokenClick: onTokenClick, onTokenHover: onTokenHover, wrapToken: wrapToken, renderTokenSuffix: renderTokenSuffix }));
|
|
66
88
|
}
|
|
@@ -71,7 +93,14 @@ function PageRenderElementItem({ item, highlight, showLineNumbers, displayTags,
|
|
|
71
93
|
return null;
|
|
72
94
|
return (_jsx("span", { className: "participant", style: getParticipantColor
|
|
73
95
|
? { backgroundColor: getParticipantColor(element.participant) }
|
|
74
|
-
: undefined, onMouseEnter: () => onParticipantHover?.(element.participant), onMouseLeave: () => onParticipantHover?.(undefined),
|
|
96
|
+
: undefined, onMouseEnter: () => onParticipantHover?.(element.participant), onMouseLeave: () => onParticipantHover?.(undefined), onClick: (event) => {
|
|
97
|
+
if (!onParticipantClick)
|
|
98
|
+
return;
|
|
99
|
+
event.stopPropagation();
|
|
100
|
+
if (!element.uid)
|
|
101
|
+
return;
|
|
102
|
+
onParticipantClick(element.participant, element.uid);
|
|
103
|
+
}, children: getParticipantName
|
|
75
104
|
? getParticipantName(element.participant)
|
|
76
105
|
: element.participant }));
|
|
77
106
|
case PageRenderElementType.LINE_BREAK:
|
|
@@ -33,6 +33,8 @@ export type PageRenderElement = {
|
|
|
33
33
|
line?: number;
|
|
34
34
|
mstart?: boolean;
|
|
35
35
|
participant?: string;
|
|
36
|
+
/** Sentence uid for PARTICIPANT labels. */
|
|
37
|
+
uid?: string;
|
|
36
38
|
token?: TokenRef;
|
|
37
39
|
};
|
|
38
40
|
export type CollapsedPageRenderElement = {
|
|
@@ -79,6 +81,7 @@ export type PageRenderViewProps = {
|
|
|
79
81
|
onTokenClick?: (ref: TokenRef, splitIdx: number | undefined, source: TokenClickSource, modifiers: TokenClickModifiers) => void;
|
|
80
82
|
onTokenHover?: (sentenceUid: string | undefined) => void;
|
|
81
83
|
onParticipantHover?: (code: string | undefined) => void;
|
|
84
|
+
onParticipantClick?: (code: string, sentenceUid: string) => void;
|
|
82
85
|
wrapToken?: (ref: TokenRef, token: Token, content: ReactNode, ctx: PageRenderTokenContext) => ReactNode;
|
|
83
86
|
renderTokenSuffix?: (ref: TokenRef, token: Token, ctx: PageRenderTokenContext) => ReactNode;
|
|
84
87
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tycho-components",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.46.
|
|
4
|
+
"version": "0.46.2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"react-i18next": "^13.0.2",
|
|
91
91
|
"react-router-dom": "^6.14.2",
|
|
92
92
|
"react-toastify": "^9.1.3",
|
|
93
|
-
"tycho-storybook": "0.12.
|
|
93
|
+
"tycho-storybook": "0.12.8",
|
|
94
94
|
"wavesurfer-react": "^2.2.2",
|
|
95
95
|
"wavesurfer.js": "^6.6.3"
|
|
96
96
|
},
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
"react-toastify": "^9.1.3",
|
|
121
121
|
"sass-embedded": "^1.97.2",
|
|
122
122
|
"storybook": "^10.1.11",
|
|
123
|
-
"tycho-storybook": "^0.12.
|
|
123
|
+
"tycho-storybook": "^0.12.8",
|
|
124
124
|
"typescript": "^5.7.3",
|
|
125
125
|
"vite": "^7.0.0",
|
|
126
126
|
"vitest": "^3.2.6",
|