default.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import { 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. let 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. * 段落或者逐句对读
  77. */
  78. key: "setting.layout.paragraph",
  79. label: "setting.layout.paragraph.label",
  80. description: "setting.layout.paragraph.description",
  81. defaultValue: "sentence",
  82. options: [
  83. {
  84. value: "sentence",
  85. label: "setting.layout.paragraph.sentence.label",
  86. },
  87. {
  88. value: "paragraph",
  89. label: "setting.layout.paragraph.paragraph.label",
  90. },
  91. ],
  92. widget: "radio-button",
  93. },
  94. {
  95. /**
  96. * 第一巴利脚本
  97. */
  98. key: "setting.pali.script.primary",
  99. label: "setting.pali.script.primary.label",
  100. description: "setting.pali.script.primary.description",
  101. defaultValue: "roman",
  102. options: [
  103. {
  104. value: "roman",
  105. label: "setting.pali.script.rome.label",
  106. },
  107. {
  108. value: "roman_to_my",
  109. label: "setting.pali.script.my.label",
  110. },
  111. {
  112. value: "roman_to_si",
  113. label: "setting.pali.script.si.label",
  114. },
  115. {
  116. value: "roman_to_thai",
  117. label: "setting.pali.script.thai.label",
  118. },
  119. {
  120. value: "roman_to_taitham",
  121. label: "setting.pali.script.tai.label",
  122. },
  123. ],
  124. },
  125. {
  126. /**
  127. * 第二巴利脚本
  128. */
  129. key: "setting.pali.script.secondary",
  130. label: "setting.pali.script.secondary.label",
  131. description: "setting.pali.script.secondary.description",
  132. defaultValue: "none",
  133. options: [
  134. {
  135. value: "none",
  136. label: "setting.pali.script.none.label",
  137. },
  138. {
  139. value: "roman",
  140. label: "setting.pali.script.rome.label",
  141. },
  142. {
  143. value: "roman_to_my",
  144. label: "setting.pali.script.my.label",
  145. },
  146. {
  147. value: "roman_to_si",
  148. label: "setting.pali.script.si.label",
  149. },
  150. ],
  151. },
  152. {
  153. /**
  154. * 字典语言
  155. */
  156. key: "setting.dict.lang",
  157. label: "setting.dict.lang.label",
  158. description: "setting.dict.lang.description",
  159. defaultValue: ["zh-Hans"],
  160. widget: "transfer",
  161. options: [
  162. {
  163. value: "en",
  164. label: "languages.en-US",
  165. },
  166. {
  167. value: "zh-Hans",
  168. label: "languages.zh-Hans",
  169. },
  170. {
  171. value: "zh-Hant",
  172. label: "languages.zh-Hant",
  173. },
  174. {
  175. value: "my",
  176. label: "languages.my",
  177. },
  178. {
  179. value: "vi",
  180. label: "languages.vi",
  181. },
  182. ],
  183. },
  184. {
  185. /**
  186. * 术语首次显示
  187. */
  188. key: "setting.term.first.show",
  189. label: "setting.term.first.show.label",
  190. description: "setting.term.first.show.description",
  191. defaultValue: "meaning_pali_others",
  192. options: [
  193. {
  194. value: "meaning_pali_others",
  195. label: "term.first.show.meaning_pali_others",
  196. },
  197. {
  198. value: "meaning_pali",
  199. label: "term.first.show.meaning_pali",
  200. },
  201. {
  202. value: "meaning_others",
  203. label: "term.first.show.meaning_others",
  204. },
  205. {
  206. value: "meaning",
  207. label: "term.first.show.meaning",
  208. },
  209. ],
  210. },
  211. {
  212. /**
  213. * nissaya 显示模式切换
  214. */
  215. key: "setting.nissaya.layout.read",
  216. label: "setting.nissaya.layout.read.label",
  217. defaultValue: "inline",
  218. options: [
  219. {
  220. value: "inline",
  221. label: "setting.nissaya.layout.inline.label",
  222. },
  223. {
  224. value: "list",
  225. label: "setting.nissaya.layout.list.label",
  226. },
  227. ],
  228. widget: "radio-button",
  229. },
  230. {
  231. /**
  232. * nissaya 显示模式切换
  233. */
  234. key: "setting.nissaya.layout.edit",
  235. label: "setting.nissaya.layout.edit.label",
  236. defaultValue: "list",
  237. options: [
  238. {
  239. value: "inline",
  240. label: "setting.nissaya.layout.inline.label",
  241. },
  242. {
  243. value: "list",
  244. label: "setting.nissaya.layout.list.label",
  245. },
  246. ],
  247. widget: "radio-button",
  248. },
  249. {
  250. /**
  251. * 是否显示逐词解析输入顺序提示
  252. */
  253. key: "setting.wbw.order",
  254. label: "setting.wbw.order.label",
  255. defaultValue: false,
  256. },
  257. ];