default.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import type { ISettingItem } from "../../../reducers/setting"
  2. export interface ISettingItemOption {
  3. label: string;
  4. value: string;
  5. }
  6. export interface ISetting {
  7. key: string;
  8. label: string;
  9. description?: string;
  10. defaultValue: string | number | boolean | string[];
  11. value?: string | number | boolean;
  12. widget?: "input" | "select" | "radio" | "radio-button" | "transfer";
  13. options?: ISettingItemOption[];
  14. max?: number;
  15. min?: number;
  16. }
  17. export const GetUserSetting = (
  18. key: string,
  19. curr?: ISettingItem[]
  20. ): string | number | boolean | string[] | undefined => {
  21. const currSetting = curr?.find((element) => element.key === key);
  22. if (typeof currSetting !== "undefined") {
  23. return currSetting.value;
  24. } else {
  25. const _default = defaultSetting.find((element) => element.key === key);
  26. if (typeof _default !== "undefined") {
  27. return _default.defaultValue;
  28. } else {
  29. return undefined;
  30. }
  31. }
  32. };
  33. export const SettingFind = (
  34. key: string,
  35. settings?: ISettingItem[]
  36. ): ISetting | undefined => {
  37. const userSetting = GetUserSetting(key, settings);
  38. const result = defaultSetting.find((element) => element.key === key);
  39. if (userSetting && result) {
  40. result.defaultValue = userSetting;
  41. }
  42. return result;
  43. };
  44. export const defaultSetting: ISetting[] = [
  45. {
  46. /**
  47. * 是否显示巴利原文
  48. */
  49. key: "setting.display.original",
  50. label: "setting.display.original.label",
  51. description: "setting.display.original.description",
  52. defaultValue: true,
  53. },
  54. {
  55. /**
  56. * 排版方向
  57. */
  58. key: "setting.layout.direction",
  59. label: "setting.layout.direction.label",
  60. description: "setting.layout.direction.description",
  61. defaultValue: "column",
  62. options: [
  63. {
  64. value: "column",
  65. label: "setting.layout.direction.col.label",
  66. },
  67. {
  68. value: "row",
  69. label: "setting.layout.direction.row.label",
  70. },
  71. ],
  72. widget: "radio-button",
  73. },
  74. {
  75. /**
  76. * commentary排版方向
  77. */
  78. key: "setting.layout.commentary",
  79. label: "setting.layout.commentary.label",
  80. description: "setting.layout.direction.description",
  81. defaultValue: "column",
  82. options: [
  83. {
  84. value: "column",
  85. label: "setting.layout.direction.col.label",
  86. },
  87. {
  88. value: "row",
  89. label: "setting.layout.direction.row.label",
  90. },
  91. ],
  92. widget: "radio-button",
  93. },
  94. {
  95. /**
  96. * 段落或者逐句对读
  97. */
  98. key: "setting.layout.paragraph",
  99. label: "setting.layout.paragraph.label",
  100. description: "setting.layout.paragraph.description",
  101. defaultValue: "sentence",
  102. options: [
  103. {
  104. value: "sentence",
  105. label: "setting.layout.paragraph.sentence.label",
  106. },
  107. {
  108. value: "paragraph",
  109. label: "setting.layout.paragraph.paragraph.label",
  110. },
  111. ],
  112. widget: "radio-button",
  113. },
  114. {
  115. /**
  116. * 第一巴利脚本
  117. */
  118. key: "setting.pali.script.primary",
  119. label: "setting.pali.script.primary.label",
  120. description: "setting.pali.script.primary.description",
  121. defaultValue: "roman",
  122. options: [
  123. {
  124. value: "roman",
  125. label: "setting.pali.script.rome.label",
  126. },
  127. {
  128. value: "roman_to_my",
  129. label: "setting.pali.script.my.label",
  130. },
  131. {
  132. value: "roman_to_si",
  133. label: "setting.pali.script.si.label",
  134. },
  135. {
  136. value: "roman_to_thai",
  137. label: "setting.pali.script.thai.label",
  138. },
  139. {
  140. value: "roman_to_taitham",
  141. label: "setting.pali.script.tai.label",
  142. },
  143. ],
  144. },
  145. {
  146. /**
  147. * 第二巴利脚本
  148. */
  149. key: "setting.pali.script.secondary",
  150. label: "setting.pali.script.secondary.label",
  151. description: "setting.pali.script.secondary.description",
  152. defaultValue: "none",
  153. options: [
  154. {
  155. value: "none",
  156. label: "setting.pali.script.none.label",
  157. },
  158. {
  159. value: "roman",
  160. label: "setting.pali.script.rome.label",
  161. },
  162. {
  163. value: "roman_to_my",
  164. label: "setting.pali.script.my.label",
  165. },
  166. {
  167. value: "roman_to_si",
  168. label: "setting.pali.script.si.label",
  169. },
  170. ],
  171. },
  172. {
  173. /**
  174. * 字典语言
  175. */
  176. key: "setting.dict.lang",
  177. label: "setting.dict.lang.label",
  178. description: "setting.dict.lang.description",
  179. defaultValue: ["zh-Hans"],
  180. widget: "transfer",
  181. options: [
  182. {
  183. value: "en",
  184. label: "languages.en-US",
  185. },
  186. {
  187. value: "zh-Hans",
  188. label: "languages.zh-Hans",
  189. },
  190. {
  191. value: "zh-Hant",
  192. label: "languages.zh-Hant",
  193. },
  194. {
  195. value: "my",
  196. label: "languages.my",
  197. },
  198. {
  199. value: "vi",
  200. label: "languages.vi",
  201. },
  202. ],
  203. },
  204. {
  205. /**
  206. * 术语首次显示
  207. */
  208. key: "setting.term.first.show",
  209. label: "setting.term.first.show.label",
  210. description: "setting.term.first.show.description",
  211. defaultValue: "meaning_pali_others",
  212. options: [
  213. {
  214. value: "meaning_pali_others",
  215. label: "term.first.show.meaning_pali_others",
  216. },
  217. {
  218. value: "meaning_pali",
  219. label: "term.first.show.meaning_pali",
  220. },
  221. {
  222. value: "meaning_others",
  223. label: "term.first.show.meaning_others",
  224. },
  225. {
  226. value: "meaning",
  227. label: "term.first.show.meaning",
  228. },
  229. ],
  230. },
  231. {
  232. /**
  233. * nissaya 显示模式切换
  234. */
  235. key: "setting.nissaya.layout.read",
  236. label: "setting.nissaya.layout.read.label",
  237. defaultValue: "inline",
  238. options: [
  239. {
  240. value: "inline",
  241. label: "setting.nissaya.layout.inline.label",
  242. },
  243. {
  244. value: "list",
  245. label: "setting.nissaya.layout.list.label",
  246. },
  247. ],
  248. widget: "radio-button",
  249. },
  250. {
  251. /**
  252. * nissaya 显示模式切换
  253. */
  254. key: "setting.nissaya.layout.edit",
  255. label: "setting.nissaya.layout.edit.label",
  256. defaultValue: "list",
  257. options: [
  258. {
  259. value: "inline",
  260. label: "setting.nissaya.layout.inline.label",
  261. },
  262. {
  263. value: "list",
  264. label: "setting.nissaya.layout.list.label",
  265. },
  266. ],
  267. widget: "radio-button",
  268. },
  269. {
  270. /**
  271. * 是否显示逐词解析输入顺序提示
  272. */
  273. key: "setting.wbw.order",
  274. label: "setting.wbw.order.label",
  275. defaultValue: false,
  276. },
  277. {
  278. /**
  279. * 是否显示逐词解析输入顺序提示
  280. */
  281. key: "setting.layout.root.fixed",
  282. label: "setting.layout.root.fixed.label",
  283. defaultValue: false,
  284. },
  285. ];