| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- import type { ISettingItem } from "../../../reducers/setting"
- export interface ISettingItemOption {
- label: string;
- value: string;
- }
- export interface ISetting {
- key: string;
- label: string;
- description?: string;
- defaultValue: string | number | boolean | string[];
- value?: string | number | boolean;
- widget?: "input" | "select" | "radio" | "radio-button" | "transfer";
- options?: ISettingItemOption[];
- max?: number;
- min?: number;
- }
- export const GetUserSetting = (
- key: string,
- curr?: ISettingItem[]
- ): string | number | boolean | string[] | undefined => {
- const currSetting = curr?.find((element) => element.key === key);
- if (typeof currSetting !== "undefined") {
- return currSetting.value;
- } else {
- const _default = defaultSetting.find((element) => element.key === key);
- if (typeof _default !== "undefined") {
- return _default.defaultValue;
- } else {
- return undefined;
- }
- }
- };
- export const SettingFind = (
- key: string,
- settings?: ISettingItem[]
- ): ISetting | undefined => {
- const userSetting = GetUserSetting(key, settings);
- const result = defaultSetting.find((element) => element.key === key);
- if (userSetting && result) {
- result.defaultValue = userSetting;
- }
- return result;
- };
- export const defaultSetting: ISetting[] = [
- {
- /**
- * 是否显示巴利原文
- */
- key: "setting.display.original",
- label: "setting.display.original.label",
- description: "setting.display.original.description",
- defaultValue: true,
- },
- {
- /**
- * 排版方向
- */
- key: "setting.layout.direction",
- label: "setting.layout.direction.label",
- description: "setting.layout.direction.description",
- defaultValue: "column",
- options: [
- {
- value: "column",
- label: "setting.layout.direction.col.label",
- },
- {
- value: "row",
- label: "setting.layout.direction.row.label",
- },
- ],
- widget: "radio-button",
- },
- {
- /**
- * commentary排版方向
- */
- key: "setting.layout.commentary",
- label: "setting.layout.commentary.label",
- description: "setting.layout.direction.description",
- defaultValue: "column",
- options: [
- {
- value: "column",
- label: "setting.layout.direction.col.label",
- },
- {
- value: "row",
- label: "setting.layout.direction.row.label",
- },
- ],
- widget: "radio-button",
- },
- {
- /**
- * 段落或者逐句对读
- */
- key: "setting.layout.paragraph",
- label: "setting.layout.paragraph.label",
- description: "setting.layout.paragraph.description",
- defaultValue: "sentence",
- options: [
- {
- value: "sentence",
- label: "setting.layout.paragraph.sentence.label",
- },
- {
- value: "paragraph",
- label: "setting.layout.paragraph.paragraph.label",
- },
- ],
- widget: "radio-button",
- },
- {
- /**
- * 第一巴利脚本
- */
- key: "setting.pali.script.primary",
- label: "setting.pali.script.primary.label",
- description: "setting.pali.script.primary.description",
- defaultValue: "roman",
- options: [
- {
- value: "roman",
- label: "setting.pali.script.rome.label",
- },
- {
- value: "roman_to_my",
- label: "setting.pali.script.my.label",
- },
- {
- value: "roman_to_si",
- label: "setting.pali.script.si.label",
- },
- {
- value: "roman_to_thai",
- label: "setting.pali.script.thai.label",
- },
- {
- value: "roman_to_taitham",
- label: "setting.pali.script.tai.label",
- },
- ],
- },
- {
- /**
- * 第二巴利脚本
- */
- key: "setting.pali.script.secondary",
- label: "setting.pali.script.secondary.label",
- description: "setting.pali.script.secondary.description",
- defaultValue: "none",
- options: [
- {
- value: "none",
- label: "setting.pali.script.none.label",
- },
- {
- value: "roman",
- label: "setting.pali.script.rome.label",
- },
- {
- value: "roman_to_my",
- label: "setting.pali.script.my.label",
- },
- {
- value: "roman_to_si",
- label: "setting.pali.script.si.label",
- },
- ],
- },
- {
- /**
- * 字典语言
- */
- key: "setting.dict.lang",
- label: "setting.dict.lang.label",
- description: "setting.dict.lang.description",
- defaultValue: ["zh-Hans"],
- widget: "transfer",
- options: [
- {
- value: "en",
- label: "languages.en-US",
- },
- {
- value: "zh-Hans",
- label: "languages.zh-Hans",
- },
- {
- value: "zh-Hant",
- label: "languages.zh-Hant",
- },
- {
- value: "my",
- label: "languages.my",
- },
- {
- value: "vi",
- label: "languages.vi",
- },
- ],
- },
- {
- /**
- * 术语首次显示
- */
- key: "setting.term.first.show",
- label: "setting.term.first.show.label",
- description: "setting.term.first.show.description",
- defaultValue: "meaning_pali_others",
- options: [
- {
- value: "meaning_pali_others",
- label: "term.first.show.meaning_pali_others",
- },
- {
- value: "meaning_pali",
- label: "term.first.show.meaning_pali",
- },
- {
- value: "meaning_others",
- label: "term.first.show.meaning_others",
- },
- {
- value: "meaning",
- label: "term.first.show.meaning",
- },
- ],
- },
- {
- /**
- * nissaya 显示模式切换
- */
- key: "setting.nissaya.layout.read",
- label: "setting.nissaya.layout.read.label",
- defaultValue: "inline",
- options: [
- {
- value: "inline",
- label: "setting.nissaya.layout.inline.label",
- },
- {
- value: "list",
- label: "setting.nissaya.layout.list.label",
- },
- ],
- widget: "radio-button",
- },
- {
- /**
- * nissaya 显示模式切换
- */
- key: "setting.nissaya.layout.edit",
- label: "setting.nissaya.layout.edit.label",
- defaultValue: "list",
- options: [
- {
- value: "inline",
- label: "setting.nissaya.layout.inline.label",
- },
- {
- value: "list",
- label: "setting.nissaya.layout.list.label",
- },
- ],
- widget: "radio-button",
- },
- {
- /**
- * 是否显示逐词解析输入顺序提示
- */
- key: "setting.wbw.order",
- label: "setting.wbw.order.label",
- defaultValue: false,
- },
- {
- /**
- * 是否显示逐词解析输入顺序提示
- */
- key: "setting.layout.root.fixed",
- label: "setting.layout.root.fixed.label",
- defaultValue: false,
- },
- ];
|