refactor: layers basic typization

This commit is contained in:
Azgaar 2022-07-05 20:33:28 +03:00
parent 7c2c624417
commit 1847772d74
15 changed files with 337 additions and 194 deletions

View file

@ -1,3 +1,3 @@
export function isCtrlClick(event: MouseEvent) {
return event.ctrlKey || event.metaKey;
export function isCtrlPressed(event?: MouseEvent) {
return event && (event.ctrlKey || event.metaKey);
}

View file

@ -7,13 +7,29 @@ export function getNextId(core: string, index = 1) {
}
export function getInputValue(id: string) {
const $element = byId(id);
if (!$element) throw new Error(`Element ${id} not found`);
if (!("value" in $element)) throw new Error(`Element ${id} is not an input`);
return (byId(id) as HTMLInputElement)?.value;
}
export function getInputNumber(id: string) {
const $element = byId(id);
if (!$element) throw new Error(`Element ${id} not found`);
if (!("value" in $element)) throw new Error(`Element ${id} is not an input`);
return (byId(id) as HTMLInputElement)?.valueAsNumber;
}
export function setInputValue(id: string, value: string | number | boolean) {
const $element = byId(id);
if (!$element) throw new Error(`Element ${id} not found`);
if (!("value" in $element)) throw new Error(`Element ${id} is not an input`);
($element as HTMLInputElement).value = String(value);
}
// apply drop-down menu option. If the value is not in options, add it
export function applyDropdownOption($select: HTMLSelectElement, value: string, name = value) {
const isExisting = Array.from($select.options).some(o => o.value === value);