tycho-components 0.28.6 → 0.28.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.
|
@@ -8,6 +8,7 @@ declare const EditionTierUtils: {
|
|
|
8
8
|
getAbbreviationTiers: (corpus?: Corpus | null) => string[];
|
|
9
9
|
getParserTier: (corpus?: Corpus | null) => EditionTierDefinition | undefined;
|
|
10
10
|
getEditionTierName: (symbol: string) => string;
|
|
11
|
+
getTierLabelKey: (symbol: string) => string;
|
|
11
12
|
getTierLabel: (symbol: string, corpus?: Corpus | null, t?: (key: string) => string) => string;
|
|
12
13
|
isUnderSelected: (selected: string, tier: string, corpus?: Corpus | null) => boolean;
|
|
13
14
|
buildEditionGroups: (corpus?: Corpus | null) => EditionGroup[];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_EDITION_TIERS, EditionTiers, StructuralEditionTiers, isStructuralEditionTier, } from '../configs/types/EditionTiers';
|
|
2
2
|
const DEFAULT_SYMBOLS = new Set(DEFAULT_EDITION_TIERS.map((tier) => tier.symbol));
|
|
3
|
+
const isDefaultTierSymbol = (symbol) => DEFAULT_SYMBOLS.has(symbol);
|
|
3
4
|
const getCorpusEditionTiers = (corpus) => {
|
|
4
5
|
if (!corpus?.editionTiers?.length) {
|
|
5
6
|
return DEFAULT_EDITION_TIERS.map((tier) => ({ ...tier }));
|
|
@@ -19,16 +20,30 @@ const getEditionTierName = (symbol) => {
|
|
|
19
20
|
const entry = Object.entries(EditionTiers).find(([, value]) => value === symbol);
|
|
20
21
|
return entry?.[0] || symbol;
|
|
21
22
|
};
|
|
23
|
+
const getTierLabelKey = (symbol) => {
|
|
24
|
+
const key = getEditionTierName(symbol).toLowerCase();
|
|
25
|
+
return `sentence:label.tier.${key}`;
|
|
26
|
+
};
|
|
27
|
+
const usesI18nLabel = (symbol) => isDefaultTierSymbol(symbol) || isStructuralEditionTier(symbol);
|
|
28
|
+
const getStaticFallbackLabel = (symbol) => {
|
|
29
|
+
const defaultDef = DEFAULT_EDITION_TIERS.find((tier) => tier.symbol === symbol);
|
|
30
|
+
if (defaultDef?.label) {
|
|
31
|
+
return defaultDef.label;
|
|
32
|
+
}
|
|
33
|
+
return getEditionTierName(symbol).toLowerCase();
|
|
34
|
+
};
|
|
22
35
|
const getTierLabel = (symbol, corpus, t) => {
|
|
36
|
+
if (usesI18nLabel(symbol)) {
|
|
37
|
+
if (t) {
|
|
38
|
+
return t(getTierLabelKey(symbol));
|
|
39
|
+
}
|
|
40
|
+
return getStaticFallbackLabel(symbol);
|
|
41
|
+
}
|
|
23
42
|
const definition = getCorpusEditionTiers(corpus).find((tier) => tier.symbol === symbol);
|
|
24
|
-
if (definition?.label) {
|
|
43
|
+
if (definition?.label?.trim()) {
|
|
25
44
|
return definition.label;
|
|
26
45
|
}
|
|
27
|
-
|
|
28
|
-
if (t) {
|
|
29
|
-
return t(`sentence:label.tier.${key}`);
|
|
30
|
-
}
|
|
31
|
-
return key;
|
|
46
|
+
return symbol;
|
|
32
47
|
};
|
|
33
48
|
const isUnderSelected = (selected, tier, corpus) => {
|
|
34
49
|
const tiers = getIterateTiers(corpus);
|
|
@@ -97,7 +112,6 @@ const validateEditionTiers = (tiers) => {
|
|
|
97
112
|
}
|
|
98
113
|
return null;
|
|
99
114
|
};
|
|
100
|
-
const isDefaultTierSymbol = (symbol) => DEFAULT_SYMBOLS.has(symbol);
|
|
101
115
|
const getEditionForToken = (token) => {
|
|
102
116
|
if (token.eid)
|
|
103
117
|
return token.edition;
|
|
@@ -122,6 +136,7 @@ const EditionTierUtils = {
|
|
|
122
136
|
getAbbreviationTiers,
|
|
123
137
|
getParserTier,
|
|
124
138
|
getEditionTierName,
|
|
139
|
+
getTierLabelKey,
|
|
125
140
|
getTierLabel,
|
|
126
141
|
isUnderSelected,
|
|
127
142
|
buildEditionGroups,
|