-
-
Notifications
You must be signed in to change notification settings - Fork 738
/
dicts.ts
160 lines (152 loc) · 5.5 KB
/
dicts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { SupportedLangs } from '@/_helpers/lang-check'
import baidu from '@/components/dictionaries/baidu/config'
import bing from '@/components/dictionaries/bing/config'
import ahdict from '@/components/dictionaries/ahdict/config'
import oaldict from '@/components/dictionaries/oaldict/config'
import caiyun from '@/components/dictionaries/caiyun/config'
import cambridge from '@/components/dictionaries/cambridge/config'
import cnki from '@/components/dictionaries/cnki/config'
import cobuild from '@/components/dictionaries/cobuild/config'
import etymonline from '@/components/dictionaries/etymonline/config'
import eudic from '@/components/dictionaries/eudic/config'
import google from '@/components/dictionaries/google/config'
import googledict from '@/components/dictionaries/googledict/config'
import guoyu from '@/components/dictionaries/guoyu/config'
import hjdict from '@/components/dictionaries/hjdict/config'
import jikipedia from '@/components/dictionaries/jikipedia/config'
import jukuu from '@/components/dictionaries/jukuu/config'
import lexico from '@/components/dictionaries/lexico/config'
import liangan from '@/components/dictionaries/liangan/config'
import longman from '@/components/dictionaries/longman/config'
import macmillan from '@/components/dictionaries/macmillan/config'
import mojidict from '@/components/dictionaries/mojidict/config'
import naver from '@/components/dictionaries/naver/config'
import renren from '@/components/dictionaries/renren/config'
// import shanbay from '@/components/dictionaries/shanbay/config'
import sogou from '@/components/dictionaries/sogou/config'
import tencent from '@/components/dictionaries/tencent/config'
import urban from '@/components/dictionaries/urban/config'
import vocabulary from '@/components/dictionaries/vocabulary/config'
import weblio from '@/components/dictionaries/weblio/config'
import weblioejje from '@/components/dictionaries/weblioejje/config'
import merriamwebster from '@/components/dictionaries/merriamwebster/config'
import websterlearner from '@/components/dictionaries/websterlearner/config'
import wikipedia from '@/components/dictionaries/wikipedia/config'
import youdao from '@/components/dictionaries/youdao/config'
import youdaotrans from '@/components/dictionaries/youdaotrans/config'
import zdic from '@/components/dictionaries/zdic/config'
// For TypeScript to generate typings
// Follow alphabetical order for easy reading
export const defaultAllDicts = {
baidu: baidu(),
bing: bing(),
ahdict: ahdict(),
oaldict: oaldict(),
caiyun: caiyun(),
cambridge: cambridge(),
cnki: cnki(),
cobuild: cobuild(),
etymonline: etymonline(),
eudic: eudic(),
google: google(),
googledict: googledict(),
guoyu: guoyu(),
hjdict: hjdict(),
jikipedia: jikipedia(),
jukuu: jukuu(),
lexico: lexico(),
liangan: liangan(),
longman: longman(),
macmillan: macmillan(),
mojidict: mojidict(),
naver: naver(),
renren: renren(),
// shanbay: shanbay(),
sogou: sogou(),
tencent: tencent(),
urban: urban(),
vocabulary: vocabulary(),
weblio: weblio(),
weblioejje: weblioejje(),
merriamwebster: merriamwebster(),
websterlearner: websterlearner(),
wikipedia: wikipedia(),
youdao: youdao(),
youdaotrans: youdaotrans(),
zdic: zdic()
}
export type AllDicts = typeof defaultAllDicts
export const getAllDicts = (): AllDicts =>
JSON.parse(JSON.stringify(defaultAllDicts))
interface DictItemBase {
/**
* Supported language: en, zh-CN, zh-TW, ja, kor, fr, de, es
* `1` for supported
*/
lang: string
/** Show this dictionary when selection contains words in the chosen languages. */
selectionLang: SupportedLangs
/**
* If set to true, the dict start searching automatically.
* Otherwise it'll only start seaching when user clicks the unfold button.
* Default MUST be true and let user decide.
*/
defaultUnfold: SupportedLangs
/**
* This is the default height when the dict first renders the result.
* If the content height is greater than the preferred height,
* the preferred height is used and a mask with a view-more button is shown.
* Otherwise the content height is used.
*/
selectionWC: {
min: number
max: number
}
/** Word count to start searching */
preferredHeight: number
}
/**
* Optional dict custom options. Can only be boolean, number or string.
* For string, add additional `options_sel` field to list out choices.
*/
type DictItemWithOptions<
Options extends
| { [option: string]: number | boolean | string }
| undefined = undefined
> = Options extends undefined
? DictItemBase
: DictItemBase & { options: Options }
/** Infer selectable options type */
export type SelectOptions<
Options extends
| { [option: string]: number | boolean | string }
| undefined = undefined,
Key extends keyof Options = Options extends undefined ? never : keyof Options
> = {
[opt in Key extends any
? Options[Key] extends string
? Key
: never
: never]: Options[opt][]
}
/**
* If an option is of `string` type there will be an array
* of options in `options_sel` field.
*/
export type DictItem<
Options extends
| { [option: string]: number | boolean | string }
| undefined = undefined,
Key extends keyof Options = Options extends undefined ? never : keyof Options
> = Options extends undefined
? DictItemWithOptions
: DictItemWithOptions<Options> &
((Key extends any
? Options[Key] extends string
? Key
: never
: never) extends never
? {}
: {
options_sel: SelectOptions<Options, Key>
})