Skip to content

Commit 979e8eb

Browse files
committed
#1439 fixed spacing
1 parent 746bed5 commit 979e8eb

File tree

4 files changed

+85
-32
lines changed

4 files changed

+85
-32
lines changed

ext/js/dictionary/dictionary-data-util.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,18 @@ export function compareRevisions(current, latest) {
346346
*/
347347
function findExistingGroupedPronunciation(reading, pronunciation, groupedPronunciationList) {
348348
const existingGroupedPronunciation = groupedPronunciationList.find((groupedPronunciation) => {
349-
return groupedPronunciation.reading === reading && arePronunciationsEquivalent(groupedPronunciation, pronunciation);
349+
return groupedPronunciation.reading === reading && arePronunciationsEquivalent(groupedPronunciation.pronunciation, pronunciation);
350350
});
351351

352352
return existingGroupedPronunciation || null;
353353
}
354354

355355
/**
356-
* @param {import('dictionary-data-util').GroupedPronunciationInternal} groupedPronunciation
356+
* @param {import('dictionary').Pronunciation} pronunciation1
357357
* @param {import('dictionary').Pronunciation} pronunciation2
358358
* @returns {boolean}
359359
*/
360-
function arePronunciationsEquivalent({pronunciation: pronunciation1}, pronunciation2) {
360+
function arePronunciationsEquivalent(pronunciation1, pronunciation2) {
361361
if (
362362
pronunciation1.type !== pronunciation2.type ||
363363
!areTagListsEqual(pronunciation1.tags, pronunciation2.tags)
@@ -463,3 +463,33 @@ function getSetIntersection(set1, set2) {
463463
function createMapKey(array) {
464464
return JSON.stringify(array);
465465
}
466+
467+
468+
/**
469+
* @param {import('dictionary-data-util').DictionaryGroupedPronunciations[]} groupedPronunciations
470+
* @returns {import('dictionary-data-util').PronunciationsInSeveralDictionaries[]}
471+
*/
472+
export function groupByPronunciation(groupedPronunciations) {
473+
const groupedList = [];
474+
475+
for (const dictionaryGroup of groupedPronunciations) {
476+
const {dictionary, pronunciations} = dictionaryGroup;
477+
478+
for (const pronunciation of pronunciations) {
479+
const existingEntry = groupedList.find((entry) => arePronunciationsEquivalent(entry.pronunciation.pronunciation, pronunciation.pronunciation));
480+
481+
if (existingEntry) {
482+
if (!existingEntry.dictionaries.includes(dictionary)) {
483+
existingEntry.dictionaries.push(dictionary);
484+
}
485+
} else {
486+
groupedList.push({
487+
pronunciation,
488+
dictionaries: [dictionary],
489+
});
490+
}
491+
}
492+
}
493+
494+
return groupedList;
495+
}

ext/js/display/display-generator.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
import {ExtensionError} from '../core/extension-error.js';
20-
import {getDisambiguations, getGroupedPronunciations, getTermFrequency, groupKanjiFrequencies, groupTermFrequencies, groupTermTags, isNonNounVerbOrAdjective} from '../dictionary/dictionary-data-util.js';
20+
import {getDisambiguations, getGroupedPronunciations, getTermFrequency, groupKanjiFrequencies, groupTermFrequencies, groupTermTags, isNonNounVerbOrAdjective, groupByPronunciation} from '../dictionary/dictionary-data-util.js';
2121
import {HtmlTemplateCollection} from '../dom/html-template-collection.js';
2222
import {distributeFurigana, getKanaMorae, getPitchCategory, isCodePointKanji} from '../language/ja/japanese.js';
2323
import {getLanguageFromText} from '../language/text-utilities.js';
@@ -119,7 +119,8 @@ export class DisplayGenerator {
119119

120120
this._appendMultiple(inflectionRuleChainsContainer, this._createInflectionRuleChain.bind(this), inflectionRuleChainCandidates);
121121
this._appendMultiple(frequencyGroupListContainer, this._createFrequencyGroup.bind(this), groupedFrequencies, false);
122-
this._appendMultiple(groupedPronunciationsContainer, this._createGroupedPronunciation.bind(this), groupedPronunciations);
122+
const dictionariesGroupedByPronunciation = groupByPronunciation(groupedPronunciations);
123+
this._appendMultiple(groupedPronunciationsContainer, this._createGroupedPronunciationByPronunciation.bind(this), dictionariesGroupedByPronunciation);
123124
this._appendMultiple(headwordTagsContainer, this._createTermTag.bind(this), termTags, headwords.length);
124125

125126
for (const term of uniqueTerms) {
@@ -659,37 +660,32 @@ export class DisplayGenerator {
659660
}
660661

661662
/**
662-
* @param {import('dictionary-data-util').DictionaryGroupedPronunciations} details
663+
* @param {import('dictionary-data-util').PronunciationsInSeveralDictionaries} details
663664
* @returns {HTMLElement}
664665
*/
665-
_createGroupedPronunciation(details) {
666-
const {dictionary, dictionaryAlias, pronunciations} = details;
666+
_createGroupedPronunciationByPronunciation({pronunciation, dictionaries}) {
667+
const container = document.createElement('div');
668+
container.classList.add('grouped-pronunciation-container');
667669

668670
const node = this._instantiate('pronunciation-group');
669-
node.dataset.dictionary = dictionary;
670-
node.dataset.pronunciationsMulti = 'true';
671-
node.dataset.pronunciationsCount = `${pronunciations.length}`;
672-
673-
const n1 = this._querySelector(node, '.pronunciation-group-tag-list');
674-
const tag = this._createTag(this._createTagData(dictionaryAlias, 'pronunciation-dictionary'));
675-
tag.dataset.details = dictionary;
676-
n1.appendChild(tag);
677671

678-
let hasTags = false;
679-
for (const {pronunciation: {tags}} of pronunciations) {
680-
if (tags.length > 0) {
681-
hasTags = true;
682-
break;
683-
}
672+
const tagListNode = this._querySelector(node, '.pronunciation-group-tag-list');
673+
for (const dictionary of dictionaries) {
674+
const tag = this._createTag(this._createTagData(dictionary, 'pronunciation-dictionary'));
675+
tag.dataset.details = dictionary;
676+
tagListNode.appendChild(tag);
684677
}
685678

686-
const n = this._querySelector(node, '.pronunciation-list');
687-
n.dataset.hasTags = `${hasTags}`;
688-
this._appendMultiple(n, this._createPronunciation.bind(this), pronunciations);
679+
const pronunciationListNode = this._querySelector(node, '.pronunciation-list');
689680

690-
return node;
681+
this._appendMultiple(pronunciationListNode, this._createPronunciation.bind(this), [pronunciation]);
682+
683+
container.appendChild(node);
684+
685+
return container;
691686
}
692687

688+
693689
/**
694690
* @param {import('dictionary-data-util').GroupedPronunciation} details
695691
* @returns {HTMLElement}
@@ -1067,14 +1063,20 @@ export class DisplayGenerator {
10671063
* @returns {?string}
10681064
*/
10691065
_getPronunciationCategories(reading, termPronunciations, wordClasses, headwordIndex) {
1070-
if (termPronunciations.length === 0) { return null; }
1066+
if (termPronunciations.length === 0) {
1067+
return null;
1068+
}
10711069
const isVerbOrAdjective = isNonNounVerbOrAdjective(wordClasses);
10721070
/** @type {Set<import('japanese-util').PitchCategory>} */
10731071
const categories = new Set();
10741072
for (const termPronunciation of termPronunciations) {
1075-
if (termPronunciation.headwordIndex !== headwordIndex) { continue; }
1073+
if (termPronunciation.headwordIndex !== headwordIndex) {
1074+
continue;
1075+
}
10761076
for (const pronunciation of termPronunciation.pronunciations) {
1077-
if (pronunciation.type !== 'pitch-accent') { continue; }
1077+
if (pronunciation.type !== 'pitch-accent') {
1078+
continue;
1079+
}
10781080
const category = getPitchCategory(reading, pronunciation.position, isVerbOrAdjective);
10791081
if (category !== null) {
10801082
categories.add(category);

ext/templates-display.html

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,25 @@
105105
</span></span></template>
106106

107107
<!-- Pitch accent -->
108-
<template id="pronunciation-group-template"><li class="pronunciation-group"><span class="pronunciation-group-tag-list tag-list"></span><ul class="pronunciation-list"></ul></li></template>
109-
<template id="pronunciation-disambiguation-template"><span class="pronunciation-disambiguation"></span></template>
110-
<template id="pronunciation-template"><li class="pronunciation"><span class="pronunciation-tag-list tag-list"></span><span class="pronunciation-disambiguation-list"></span><span class="pronunciation-representation-list"><span class="pronunciation-text-container"></span><span class="pronunciation-downstep-notation-container"></span><span class="pronunciation-graph-container"></span></span></li></template>
108+
<template id="pronunciation-group-template">
109+
<li class="pronunciation-group">
110+
<ul class="pronunciation-list"></ul>
111+
<span class="pronunciation-group-tag-list tag-list"></span>
112+
</li>
113+
</template>
114+
<template id="pronunciation-disambiguation-template">
115+
<span class="pronunciation-disambiguation"></span>
116+
</template>
117+
<template id="pronunciation-template">
118+
<li class="pronunciation">
119+
<span class="pronunciation-tag-list tag-list"></span>
120+
<span class="pronunciation-disambiguation-list"></span>
121+
<span class="pronunciation-representation-list">
122+
<span class="pronunciation-text-container"></span>
123+
<span class="pronunciation-downstep-notation-container"></span>
124+
<span class="pronunciation-graph-container"></span></span>
125+
</li>
126+
</template>
111127

112128
<!-- Kanji entry -->
113129
<template id="kanji-entry-template" data-remove-whitespace-text="true"><div class="entry" data-type="kanji">

types/ext/dictionary-data-util.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ export type DictionaryGroupedPronunciations = {
8484
pronunciations: GroupedPronunciation[];
8585
};
8686

87+
export type PronunciationsInSeveralDictionaries = {
88+
dictionaries: string[];
89+
pronunciation: DictionaryGroupedPronunciations;
90+
};
91+
8792
export type TagGroup = {
8893
tag: Dictionary.Tag;
8994
headwordIndices: number[];

0 commit comments

Comments
 (0)