tycho-components 0.41.2 → 0.41.4
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,3 +1,4 @@
|
|
|
1
1
|
import './style.scss';
|
|
2
|
-
import { PageRenderViewProps } from './types';
|
|
2
|
+
import { CollapsedPageRenderElement, PageRenderViewProps } from './types';
|
|
3
3
|
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.Element;
|
|
4
|
+
export declare function findPunctuationAfterCollapsedJunction(items: CollapsedPageRenderElement[], junctionIndex: number): number | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from 'react';
|
|
2
3
|
import cx from 'classnames';
|
|
3
4
|
import './style.scss';
|
|
4
5
|
import collapseElementsForTier from './collapseElementsForTier';
|
|
@@ -6,8 +7,51 @@ import isTokenRefVisible, { tokenRefToToken } from './tokenUtils';
|
|
|
6
7
|
import { PageRenderElementType, } from './types';
|
|
7
8
|
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, }) {
|
|
8
9
|
const collapsed = collapseElementsForTier(elements, selectedTier, corpus);
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const punctuationBeforeBreak = new Map();
|
|
11
|
+
const punctuationIndexes = new Set();
|
|
12
|
+
collapsed.forEach((item, index) => {
|
|
13
|
+
const punctuationIndex = findPunctuationAfterCollapsedJunction(collapsed, index);
|
|
14
|
+
if (punctuationIndex === undefined)
|
|
15
|
+
return;
|
|
16
|
+
punctuationBeforeBreak.set(index, punctuationIndex);
|
|
17
|
+
punctuationIndexes.add(punctuationIndex);
|
|
18
|
+
});
|
|
19
|
+
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));
|
|
21
|
+
return (_jsx("div", { className: "page-render-elements", children: collapsed.map((item, index) => {
|
|
22
|
+
if (punctuationIndexes.has(index))
|
|
23
|
+
return null;
|
|
24
|
+
const punctuationIndex = punctuationBeforeBreak.get(index);
|
|
25
|
+
return (_jsxs(Fragment, { children: [renderItem(item), punctuationIndex !== undefined &&
|
|
26
|
+
renderItem(collapsed[punctuationIndex])] }, item.key));
|
|
27
|
+
}) }));
|
|
28
|
+
}
|
|
29
|
+
export function findPunctuationAfterCollapsedJunction(items, junctionIndex) {
|
|
30
|
+
const junction = items[junctionIndex];
|
|
31
|
+
if (junction?.kind !== 'collapsedJunction')
|
|
32
|
+
return undefined;
|
|
33
|
+
let hasLineBreak = false;
|
|
34
|
+
for (let index = junctionIndex + 1; index < items.length; index += 1) {
|
|
35
|
+
const item = items[index];
|
|
36
|
+
if (item.kind === 'single') {
|
|
37
|
+
if (item.element.type === PageRenderElementType.LINE_BREAK) {
|
|
38
|
+
hasLineBreak = true;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (item.element.type === PageRenderElementType.LINE_NUMBER) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (hasLineBreak &&
|
|
45
|
+
item.element.type === PageRenderElementType.TOKEN &&
|
|
46
|
+
item.element.token?.t === 'PUNC' &&
|
|
47
|
+
item.element.token.uid === junction.token.uid &&
|
|
48
|
+
item.element.token.p > junction.token.p) {
|
|
49
|
+
return index;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
11
55
|
}
|
|
12
56
|
function sentenceUidForItem(item) {
|
|
13
57
|
if (item.kind === 'collapsedJunction')
|