Clean up type validation

This commit is contained in:
Jeremy Stretch 2024-02-07 17:09:11 -05:00
parent 912f257a68
commit 018815cf9d
7 changed files with 33 additions and 24 deletions

Binary file not shown.

View File

@ -40,6 +40,7 @@
"devDependencies": {
"@types/bootstrap": "5.2.10",
"@types/cookie": "^0.5.1",
"@types/node": "^20.11.16",
"@typescript-eslint/eslint-plugin": "^5.39.0",
"@typescript-eslint/parser": "^5.39.0",
"esbuild": "^0.13.15",

View File

@ -1,14 +1,14 @@
import { TomOption } from 'tom-select/src/types';
import { escape_html } from 'tom-select/src/utils';
import { DynamicTomSelect } from './classes/dynamicTomSelect';
import { getElements } from '../util';
import { DynamicTomSelect } from './classes/dynamicTomSelect'
const VALUE_FIELD = 'id';
const LABEL_FIELD = 'display';
const MAX_OPTIONS = 100;
// Render the HTML for a dropdown option
function renderOption(data: any, escape: Function) {
function renderOption(data: TomOption, escape: typeof escape_html) {
// If the option has a `_depth` property, indent its label
if (typeof data._depth === 'number' && data._depth > 0) {
return `<div>${'─'.repeat(data._depth)} ${escape(data[LABEL_FIELD])}</div>`;
@ -17,10 +17,8 @@ function renderOption(data: any, escape: Function) {
return `<div>${escape(data[LABEL_FIELD])}</div>`;
}
// Initialize <select> elements which are populated via a REST API call
export function initDynamicSelects(): void {
for (const select of getElements<HTMLSelectElement>('select.api-select')) {
new DynamicTomSelect(select, {
valueField: VALUE_FIELD,
@ -42,12 +40,13 @@ export function initDynamicSelects(): void {
// Define custom rendering functions
render: {
option: renderOption
option: renderOption,
},
// By default, load() will be called only if query.length > 0
shouldLoad: function(): boolean { return true; }
});
shouldLoad: function (): boolean {
return true;
},
});
}
}

View File

@ -1,7 +1,6 @@
import { initColorSelects, initStaticSelects } from './static';
import { initDynamicSelects } from './dynamic';
export function initSelects(): void {
initStaticSelects();
initDynamicSelects();

View File

@ -1,30 +1,28 @@
import { getElements } from '../util';
import { TomOption } from 'tom-select/src/types';
import TomSelect from 'tom-select';
import { escape_html } from 'tom-select/src/utils';
import { getElements } from '../util';
// Initialize <select> elements with statically-defined options
export function initStaticSelects(): void {
for (const select of getElements<HTMLSelectElement>('select:not(.api-select):not(.color-select)')) {
for (const select of getElements<HTMLSelectElement>(
'select:not(.api-select):not(.color-select)',
)) {
new TomSelect(select, {
plugins: ['clear_button']
plugins: ['clear_button'],
});
}
}
// Initialize color selection fields
export function initColorSelects(): void {
for (const select of getElements<HTMLSelectElement>('select.color-select')) {
new TomSelect(select, {
render: {
option: function(item: TomOption, escape: Function) {
option: function (item: TomOption, escape: typeof escape_html) {
return `<div style="background-color: #${escape(item.value)}">${escape(item.text)}</div>`;
}
}
},
},
});
}
}
}

View File

@ -3,7 +3,7 @@
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"noUnusedParameters": true,
"noUnusedParameters": false,
"esModuleInterop": true,
"isolatedModules": true,
"noUnusedLocals": true,

View File

@ -150,6 +150,13 @@
resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz"
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
"@types/node@^20.11.16":
version "20.11.16"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.16.tgz#4411f79411514eb8e2926f036c86c9f0e4ec6708"
integrity sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==
dependencies:
undici-types "~5.26.4"
"@typescript-eslint/eslint-plugin@^5.39.0":
version "5.39.0"
resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.39.0.tgz"
@ -2233,6 +2240,11 @@ unbox-primitive@^1.0.2:
has-symbols "^1.0.3"
which-boxed-primitive "^1.0.2"
undici-types@~5.26.4:
version "5.26.5"
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
uri-js@^4.2.2:
version "4.4.1"
resolved "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz"