tycho-components 0.37.0 → 0.37.1
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/features/PageRender/PageRenderView.d.ts +1 -1
- package/dist/features/PageRender/PageRenderView.js +43 -19
- package/dist/features/PageRender/index.d.ts +1 -1
- package/dist/features/PageRender/index.js +1 -1
- package/dist/features/PageRender/types.d.ts +26 -4
- package/dist/features/index.d.ts +2 -2
- package/dist/features/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { PageRenderViewProps } from './types';
|
|
2
|
-
export default function PageRenderView({ elements, selectedTier, corpus,
|
|
2
|
+
export default function PageRenderView({ elements, selectedTier, corpus, displayTags, showLineNumbers, highlightSentenceUid, activeTokenKey, selectedTokenKeys, tokenSelectionKey, getDisplayValue, getTokenStyle, getTokenClassName, isTokenEdited, getParticipantName, getParticipantColor, onTokenClick, onTokenHover, onParticipantHover, wrapToken, renderTokenSuffix, }: PageRenderViewProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import cx from 'classnames';
|
|
3
3
|
import collapseElementsForTier from './collapseElementsForTier';
|
|
4
4
|
import isTokenRefVisible, { tokenRefToToken } from './tokenUtils';
|
|
5
5
|
import { PageRenderElementType, } from './types';
|
|
6
|
-
export default function PageRenderView({ elements, selectedTier, corpus,
|
|
6
|
+
export default function PageRenderView({ elements, selectedTier, corpus, displayTags = false, showLineNumbers = true, highlightSentenceUid, activeTokenKey, selectedTokenKeys, tokenSelectionKey, getDisplayValue, getTokenStyle, getTokenClassName, isTokenEdited, getParticipantName, getParticipantColor, onTokenClick, onTokenHover, onParticipantHover, wrapToken, renderTokenSuffix, }) {
|
|
7
7
|
const collapsed = collapseElementsForTier(elements, selectedTier, corpus);
|
|
8
8
|
return (_jsx("div", { className: "page-render-elements", children: collapsed.map((item) => (_jsx(PageRenderElementItem, { item: item, highlight: highlightSentenceUid != null &&
|
|
9
|
-
sentenceUidForItem(item) === highlightSentenceUid, showLineNumbers: showLineNumbers, displayTags: displayTags, getDisplayValue: getDisplayValue, getTokenStyle: getTokenStyle, isTokenEdited: isTokenEdited, getParticipantName: getParticipantName, getParticipantColor: getParticipantColor, onTokenClick: onTokenClick,
|
|
9
|
+
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))) }));
|
|
10
10
|
}
|
|
11
11
|
function sentenceUidForItem(item) {
|
|
12
12
|
if (item.kind === 'collapsedJunction')
|
|
@@ -15,9 +15,9 @@ function sentenceUidForItem(item) {
|
|
|
15
15
|
return item.element.token.uid;
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
|
18
|
-
function PageRenderElementItem({ item, highlight, showLineNumbers, displayTags,
|
|
18
|
+
function PageRenderElementItem({ item, highlight, showLineNumbers, displayTags, activeTokenKey, selectedTokenKeys, tokenSelectionKey, getDisplayValue, getTokenStyle, getTokenClassName, isTokenEdited, getParticipantName, getParticipantColor, onTokenClick, onTokenHover, onParticipantHover, wrapToken, renderTokenSuffix, }) {
|
|
19
19
|
if (item.kind === 'collapsedJunction') {
|
|
20
|
-
return
|
|
20
|
+
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 }));
|
|
21
21
|
}
|
|
22
22
|
const { element } = item;
|
|
23
23
|
switch (element.type) {
|
|
@@ -26,7 +26,7 @@ function PageRenderElementItem({ item, highlight, showLineNumbers, displayTags,
|
|
|
26
26
|
return null;
|
|
27
27
|
return (_jsx("span", { className: "participant", style: getParticipantColor
|
|
28
28
|
? { backgroundColor: getParticipantColor(element.participant) }
|
|
29
|
-
: undefined, children: getParticipantName
|
|
29
|
+
: undefined, onMouseEnter: () => onParticipantHover?.(element.participant), onMouseLeave: () => onParticipantHover?.(undefined), children: getParticipantName
|
|
30
30
|
? getParticipantName(element.participant)
|
|
31
31
|
: element.participant }));
|
|
32
32
|
case PageRenderElementType.LINE_BREAK:
|
|
@@ -38,30 +38,54 @@ function PageRenderElementItem({ item, highlight, showLineNumbers, displayTags,
|
|
|
38
38
|
case PageRenderElementType.MARK:
|
|
39
39
|
if (!element.token)
|
|
40
40
|
return null;
|
|
41
|
-
return
|
|
41
|
+
return (_jsx(TokenNode, { refToken: element.token, splitIdx: 0, isMark: 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 }));
|
|
42
42
|
case PageRenderElementType.JUNCTION_SPLIT:
|
|
43
43
|
if (!element.token)
|
|
44
44
|
return null;
|
|
45
|
-
return
|
|
45
|
+
return (_jsx(TokenNode, { refToken: element.token, splitIdx: element.idx ?? 0, isSplit: 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 }));
|
|
46
46
|
case PageRenderElementType.TOKEN:
|
|
47
47
|
if (!element.token)
|
|
48
48
|
return null;
|
|
49
|
-
return
|
|
49
|
+
return (_jsx(TokenNode, { refToken: element.token, splitIdx: 0, 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 }));
|
|
50
50
|
default:
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
const token = tokenRefToToken(
|
|
56
|
-
const displaySplits = token.ec && token.split && !displayTags;
|
|
57
|
-
const visible = isMark || isTokenRefVisible(
|
|
58
|
-
const
|
|
54
|
+
function TokenNode({ refToken, splitIdx, isSplit = false, isMark = false, isCollapsedJunction = false, highlight, displayTags, activeTokenKey, selectedTokenKeys, tokenSelectionKey, getDisplayValue, getTokenStyle, getTokenClassName, isTokenEdited, onTokenClick, onTokenHover, wrapToken, renderTokenSuffix, }) {
|
|
55
|
+
const token = tokenRefToToken(refToken);
|
|
56
|
+
const displaySplits = Boolean(token.ec && token.split && !displayTags);
|
|
57
|
+
const visible = isMark || isTokenRefVisible(refToken);
|
|
58
|
+
const key = tokenSelectionKey?.(refToken);
|
|
59
|
+
const selected = (key != null && activeTokenKey === key) ||
|
|
60
|
+
(key != null && selectedTokenKeys?.has(key));
|
|
61
|
+
const ctx = {
|
|
62
|
+
isSplit,
|
|
63
|
+
isMark,
|
|
64
|
+
isCollapsedJunction,
|
|
65
|
+
splitIdx,
|
|
66
|
+
highlight,
|
|
67
|
+
selected: Boolean(selected),
|
|
68
|
+
};
|
|
69
|
+
const tokenClass = cx(isMark ? 'mark' : 'token', {
|
|
59
70
|
split: isSplit,
|
|
60
|
-
'd-none': !visible ||
|
|
61
|
-
edited: isTokenEdited ? isTokenEdited(token) : !!
|
|
71
|
+
'd-none': !visible || displaySplits,
|
|
72
|
+
edited: isTokenEdited ? isTokenEdited(token) : !!refToken.edited,
|
|
62
73
|
highlight,
|
|
63
|
-
|
|
74
|
+
selected: ctx.selected,
|
|
75
|
+
}, getTokenClassName?.(refToken, token, ctx));
|
|
76
|
+
const source = isMark ? 'mark' : 'word';
|
|
77
|
+
const clickModifiers = (event) => ({
|
|
78
|
+
ctrlKey: event.ctrlKey,
|
|
79
|
+
altKey: event.altKey,
|
|
80
|
+
metaKey: event.metaKey,
|
|
64
81
|
});
|
|
65
|
-
const
|
|
66
|
-
|
|
82
|
+
const content = (_jsxs("div", { id: highlight && refToken.p === 1 ? 'selected' : undefined, className: tokenClass, style: getTokenStyle?.(refToken, token, ctx), onClick: onTokenClick
|
|
83
|
+
? (event) => onTokenClick(refToken, splitIdx, source, clickModifiers(event))
|
|
84
|
+
: undefined, onContextMenu: onTokenClick
|
|
85
|
+
? (event) => {
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
onTokenClick(refToken, splitIdx, 'sentence', clickModifiers(event));
|
|
88
|
+
}
|
|
89
|
+
: undefined, onMouseEnter: () => onTokenHover?.(refToken.uid), onMouseLeave: () => onTokenHover?.(undefined), children: [getDisplayValue(token, splitIdx), displayTags && (_jsxs("b", { className: "tag", children: ["/", token.split ? token.split.t : token.t] })), renderTokenSuffix?.(refToken, token, ctx)] }));
|
|
90
|
+
return (_jsx(_Fragment, { children: wrapToken ? wrapToken(refToken, token, content, ctx) : content }));
|
|
67
91
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as PageRenderView } from './PageRenderView';
|
|
2
|
-
export { default as collapseElementsForTier } from './collapseElementsForTier';
|
|
2
|
+
export { default as collapseElementsForTier, shouldSkipJunctionContinuationElement, shouldSkipSegmentationElement, shouldSkipSegmentationToken, findSegmentationGroupBounds, isTokenBearingCollapsed, } from './collapseElementsForTier';
|
|
3
3
|
export { tokenRefToToken, default as isTokenRefVisible } from './tokenUtils';
|
|
4
4
|
export * from './types';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as PageRenderView } from './PageRenderView';
|
|
2
|
-
export { default as collapseElementsForTier } from './collapseElementsForTier';
|
|
2
|
+
export { default as collapseElementsForTier, shouldSkipJunctionContinuationElement, shouldSkipSegmentationElement, shouldSkipSegmentationToken, findSegmentationGroupBounds, isTokenBearingCollapsed, } from './collapseElementsForTier';
|
|
3
3
|
export { tokenRefToToken, default as isTokenRefVisible } from './tokenUtils';
|
|
4
4
|
export * from './types';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
2
|
import type { Corpus } from '../../configs/types/Corpus';
|
|
3
3
|
import type Document from '../../configs/types/Document';
|
|
4
4
|
import type { Edition, Format, Split, Token } from '../../configs/types/Struct';
|
|
@@ -45,6 +45,20 @@ export type CollapsedPageRenderElement = {
|
|
|
45
45
|
splitIdx?: number;
|
|
46
46
|
key: string;
|
|
47
47
|
};
|
|
48
|
+
export type TokenClickSource = 'word' | 'sentence' | 'mark';
|
|
49
|
+
export type TokenClickModifiers = {
|
|
50
|
+
ctrlKey: boolean;
|
|
51
|
+
altKey: boolean;
|
|
52
|
+
metaKey: boolean;
|
|
53
|
+
};
|
|
54
|
+
export type PageRenderTokenContext = {
|
|
55
|
+
isSplit: boolean;
|
|
56
|
+
isMark: boolean;
|
|
57
|
+
isCollapsedJunction: boolean;
|
|
58
|
+
splitIdx: number;
|
|
59
|
+
highlight: boolean;
|
|
60
|
+
selected: boolean;
|
|
61
|
+
};
|
|
48
62
|
export type PageRenderViewProps = {
|
|
49
63
|
elements: PageRenderElement[];
|
|
50
64
|
selectedTier: string;
|
|
@@ -53,10 +67,18 @@ export type PageRenderViewProps = {
|
|
|
53
67
|
displayTags?: boolean;
|
|
54
68
|
showLineNumbers?: boolean;
|
|
55
69
|
highlightSentenceUid?: string;
|
|
70
|
+
activeTokenKey?: string;
|
|
71
|
+
selectedTokenKeys?: Set<string>;
|
|
72
|
+
tokenSelectionKey?: (ref: TokenRef) => string;
|
|
56
73
|
getDisplayValue: (token: Token, splitIdx?: number) => ReactNode;
|
|
57
|
-
getTokenStyle?: (token: Token) =>
|
|
74
|
+
getTokenStyle?: (ref: TokenRef, token: Token, ctx: PageRenderTokenContext) => CSSProperties | undefined;
|
|
75
|
+
getTokenClassName?: (ref: TokenRef, token: Token, ctx: PageRenderTokenContext) => string | undefined;
|
|
58
76
|
isTokenEdited?: (token: Token) => boolean;
|
|
59
77
|
getParticipantName?: (code: string) => string;
|
|
60
|
-
getParticipantColor?: (code: string) => string;
|
|
61
|
-
onTokenClick?: (ref: TokenRef, splitIdx
|
|
78
|
+
getParticipantColor?: (code: string) => string | undefined;
|
|
79
|
+
onTokenClick?: (ref: TokenRef, splitIdx: number | undefined, source: TokenClickSource, modifiers: TokenClickModifiers) => void;
|
|
80
|
+
onTokenHover?: (sentenceUid: string | undefined) => void;
|
|
81
|
+
onParticipantHover?: (code: string | undefined) => void;
|
|
82
|
+
wrapToken?: (ref: TokenRef, token: Token, content: ReactNode, ctx: PageRenderTokenContext) => ReactNode;
|
|
83
|
+
renderTokenSuffix?: (ref: TokenRef, token: Token, ctx: PageRenderTokenContext) => ReactNode;
|
|
62
84
|
};
|
package/dist/features/index.d.ts
CHANGED
|
@@ -13,5 +13,5 @@ export type { SearchCriteria } from "./TreeView/TreeViewSearch/TreeViewSearch";
|
|
|
13
13
|
export { default as CytoscapeMenuCanvas } from "./CytoscapeMenu/CytoscapeMenuCanvas";
|
|
14
14
|
export { registerCytoscapeContextMenus, contextMenus } from "./CytoscapeMenu";
|
|
15
15
|
export type { CytoscapeContextMenuOptions, MenuItemOption, ContextMenusInstance, } from "./CytoscapeMenu";
|
|
16
|
-
export { PageRenderView, collapseElementsForTier, tokenRefToToken, isTokenRefVisible, } from "./PageRender";
|
|
17
|
-
export type { PageRenderElement, PageRenderElementType, PageRenderViewProps, TokenRef, CollapsedPageRenderElement, } from "./PageRender";
|
|
16
|
+
export { PageRenderView, collapseElementsForTier, shouldSkipJunctionContinuationElement, shouldSkipSegmentationElement, shouldSkipSegmentationToken, findSegmentationGroupBounds, isTokenBearingCollapsed, tokenRefToToken, isTokenRefVisible, } from "./PageRender";
|
|
17
|
+
export type { PageRenderElement, PageRenderElementType, PageRenderViewProps, PageRenderTokenContext, TokenRef, CollapsedPageRenderElement, TokenClickSource, TokenClickModifiers, } from "./PageRender";
|
package/dist/features/index.js
CHANGED
|
@@ -9,4 +9,4 @@ export { default as SyntreesCytoscape } from "./TreeView/cytoscape/SyntreesCytos
|
|
|
9
9
|
export { default as TreeViewSearch } from "./TreeView/TreeViewSearch/TreeViewSearch";
|
|
10
10
|
export { default as CytoscapeMenuCanvas } from "./CytoscapeMenu/CytoscapeMenuCanvas";
|
|
11
11
|
export { registerCytoscapeContextMenus, contextMenus } from "./CytoscapeMenu";
|
|
12
|
-
export { PageRenderView, collapseElementsForTier, tokenRefToToken, isTokenRefVisible, } from "./PageRender";
|
|
12
|
+
export { PageRenderView, collapseElementsForTier, shouldSkipJunctionContinuationElement, shouldSkipSegmentationElement, shouldSkipSegmentationToken, findSegmentationGroupBounds, isTokenBearingCollapsed, tokenRefToToken, isTokenRefVisible, } from "./PageRender";
|