1 line
35 KiB
Plaintext
1 line
35 KiB
Plaintext
|
{"version":3,"file":"countryInputField-Dm2t4SUk.js","sources":["../src/helpers/object/getDeepProperty.ts","../src/components/checkboxField.ts","../src/helpers/formatPhoneNumber.ts","../src/components/telInputField.ts","../src/components/countryInputField.ts"],"sourcesContent":["import {splitDeepPath} from './setDeepProperty';\n\nexport default function getDeepProperty(object: any, key: string | Array<string>) {\n const splitted = Array.isArray(key) ? key : splitDeepPath(key);\n let o: any = object;\n for(const key of splitted) {\n o = o?.[key];\n if(!o) {\n break;\n }\n }\n\n return o;\n}\n","/*\n * https://github.com/morethanwords/tweb\n * Copyright (C) 2019-2021 Eduard Kuzmenko\n * https://github.com/morethanwords/tweb/blob/master/LICENSE\n */\n\nimport type ListenerSetter from '../helpers/listenerSetter';\nimport ripple from './ripple';\nimport {LangPackKey, _i18n} from '../lib/langPack';\nimport getDeepProperty from '../helpers/object/getDeepProperty';\nimport rootScope from '../lib/rootScope';\nimport apiManagerProxy from '../lib/mtproto/mtprotoworker';\nimport simulateEvent from '../helpers/dom/dispatchEvent';\n\nexport type CheckboxFieldOptions = {\n text?: LangPackKey,\n textArgs?: any[],\n name?: string,\n round?: boolean,\n toggle?: boolean,\n stateKey?: string,\n stateValues?: any[],\n stateValueReverse?: boolean,\n disabled?: boolean,\n checked?: boolean,\n restriction?: boolean,\n withRipple?: boolean,\n withHover?: boolean,\n listenerSetter?: ListenerSetter,\n asRadio?: boolean\n};\nexport default class CheckboxField {\n public input: HTMLInputElement;\n public label: HTMLLabelElement;\n public span: HTMLSpanElement;\n public listenerSetter: ListenerSetter;\n\n constructor(options: CheckboxFieldOptions = {}) {\n const label = this.label = document.createElement('label');\n label.classList.add('checkbox-field');\n\n if(options.restriction && !options.toggle) {\n label.classList.add('checkbox-field-restriction');\n }\n\n if(options.round) {\n label.classList.add('checkbox-field-round');\n }\n\n if(options.disabled) {\n this.toggleDisability(true);\n }\n\n this.listenerSetter = options.listenerSetter;\n\n const input = this.input = document.createElement('input');\n input.classList.add('checkbox-field-input');\n input.type = options.asRadio ? 'radio' : 'checkbox';\n if(options.name) {\n input[options.asRadio ? 'name' : 'id'] = 'input-' + options.name;\n }\n\n if(options.checked) {\n input.checked = true;\n }\n\n if(options.stateKey) {\n let loaded = options.checked !== undefined;\n const onChange = () => {\n if(!loaded) {\n return;\n }\n\n let value: any;\n if(options.stateValues) {\n value = options.stateValues[input.checked ? 1 : 0];\n } else {\n value = input.checked;\n\n if(options.stateValueReverse) {\n value = !value;\n }\n }\n\n rootScope.managers.appStateManager.setByKey(options.stateKey, value);\n };\n\n !loaded && apiManagerProxy.getState().then((state) => {\n loaded = true;\n const stateValue = getDeepProperty(state, options.stateKey);\n let checked: boolean;\n if(options.stateValues) {\n checked = options.stateValues.indexOf(stateValue) === 1;\n } else {\n checked = stateValue;\n\n if(options.stateValueReverse) {\n checked = !checked;\n }\n }\n\n this.setValueSilently(checked);\n });\n\n if(options.listenerSetter) options.listenerSetter.add(input)('change', onChange);\n else input.addEventListener('change', onChange);\n }\n\n let span: HTMLSpanElement;\n if(options.text) {\n span = this.span = document.createElement('span');\n span.classList.add('checkbox-caption');\n _i18n(span, options.text, options.textArgs);\n } else {\n label.classList.add('checkbox-without-caption');\n }\n\n label.append(input);\n\n if(opti
|