refactor fragment aliases & add field lookup checking
why is that not the default
This commit is contained in:
parent
43af72aa4d
commit
969cdc938d
3 changed files with 19 additions and 11 deletions
2
Makefile
2
Makefile
|
@ -50,7 +50,7 @@ $(BUILDDIR)/%: $(TMPDIR)/%
|
||||||
|
|
||||||
$(TMPDIR)/%.js: %.ts
|
$(TMPDIR)/%.js: %.ts
|
||||||
echo "[tsc] "$@
|
echo "[tsc] "$@
|
||||||
tsc --strict --noEmitOnError \
|
tsc --strict --noUncheckedIndexedAccess --noEmitOnError \
|
||||||
--lib dom,es2021 --target es2015 \
|
--lib dom,es2021 --target es2015 \
|
||||||
--outDir $(dir $@) $^
|
--outDir $(dir $@) $^
|
||||||
|
|
||||||
|
|
|
@ -106,23 +106,30 @@ function makeFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Shortcuts = { [short: string]: Set<string> };
|
||||||
|
const shortcuts: Shortcuts = {
|
||||||
|
'summary': new Set('require_artsummary'),
|
||||||
|
'colourexamples': new Set('require_colourexample'),
|
||||||
|
'flatexamples': new Set('require_flatexample'),
|
||||||
|
'sketchexamples': new Set('require_sketchexample'),
|
||||||
|
'iconexamples': new Set('require_iconexample'),
|
||||||
|
'curated': new Set('require_curated')
|
||||||
|
};
|
||||||
|
|
||||||
function useFragment() {
|
function useFragment() {
|
||||||
const frag = decodeURIComponent(location.hash).replace(/^#/, '');
|
const frag = decodeURIComponent(location.hash).replace(/^#/, '');
|
||||||
const details = document.getElementById('filters-details') as HTMLDetailsElement;
|
const details = document.getElementById('filters-details') as HTMLDetailsElement;
|
||||||
|
const fromShortcut = shortcuts[frag];
|
||||||
|
|
||||||
if (!frag) {
|
if (!frag) {
|
||||||
clearForm();
|
clearForm();
|
||||||
} else if (frag == 'all') {
|
} else if (frag == 'all') {
|
||||||
allBoxes.forEach(b => b.checked = false);
|
allBoxes.forEach(b => b.checked = false);
|
||||||
details.open = false;
|
details.open = false;
|
||||||
|
} else if (fromShortcut) {
|
||||||
|
allBoxes.forEach(b => b.checked = fromShortcut.has(b.id));
|
||||||
} else {
|
} else {
|
||||||
const pieces =
|
const pieces = frag.split(';');
|
||||||
frag == 'summary' ? ['require_artsummary'] :
|
|
||||||
frag == 'colourexamples' ? ['require_colourexample'] :
|
|
||||||
frag == 'flatexamples' ? ['require_flatexample'] :
|
|
||||||
frag == 'sketchexamples' ? ['require_sketchexample'] :
|
|
||||||
frag == 'iconexamples' ? ['require_iconexample'] :
|
|
||||||
frag == 'curated' ? ['require_curated'] : frag.split(';');
|
|
||||||
const set = new Set(pieces);
|
const set = new Set(pieces);
|
||||||
const re = /^(require|exclude)_|hide_filters/;
|
const re = /^(require|exclude)_|hide_filters/;
|
||||||
if (pieces.every(x => re.test(x))) {
|
if (pieces.every(x => re.test(x))) {
|
||||||
|
@ -154,7 +161,7 @@ function sortFilters(cmp: (a: Node, b: Node) => number) {
|
||||||
function sortFiltersAlpha(e: Event) {
|
function sortFiltersAlpha(e: Event) {
|
||||||
function getName(node: Node): string {
|
function getName(node: Node): string {
|
||||||
if (node instanceof Element) {
|
if (node instanceof Element) {
|
||||||
return node.getElementsByTagName('input')[0].value;
|
return node.getElementsByTagName('input')[0]?.value ?? '';
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -164,9 +171,9 @@ function sortFiltersAlpha(e: Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortFiltersUses(e: Event) {
|
function sortFiltersUses(e: Event) {
|
||||||
function getUses(node: Node) {
|
function getUses(node: Node): number {
|
||||||
if (node instanceof Element) {
|
if (node instanceof Element) {
|
||||||
const countStr = node.getElementsByTagName('label')[0].dataset.count;
|
const countStr = node.getElementsByTagName('label')[0]?.dataset.count;
|
||||||
return countStr ? +countStr : 0;
|
return countStr ? +countStr : 0;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"strict": true,
|
"strict": true,
|
||||||
|
"noUncheckedIndexedAccess": true,
|
||||||
"noEmitOnError": true,
|
"noEmitOnError": true,
|
||||||
"lib": ["ES2021", "dom"],
|
"lib": ["ES2021", "dom"],
|
||||||
"target": "ES2015"
|
"target": "ES2015"
|
||||||
|
|
Loading…
Reference in a new issue