@dosgato/dialog 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>import FieldMultiselect from '../FieldMultiselect.svelte';
|
|
2
2
|
import { getContext } from 'svelte';
|
|
3
|
-
import { TAG_API_CONTEXT } from './TagAPI';
|
|
4
3
|
import { isNotBlank } from 'txstate-utils';
|
|
4
|
+
import { TAG_API_CONTEXT } from './TagAPI';
|
|
5
5
|
export let path;
|
|
6
6
|
export let label;
|
|
7
7
|
export let target;
|
|
@@ -9,15 +9,28 @@ const tagClient = getContext(TAG_API_CONTEXT);
|
|
|
9
9
|
let lasttarget = -1;
|
|
10
10
|
let groups = [];
|
|
11
11
|
let tags;
|
|
12
|
-
async function
|
|
12
|
+
async function fetchAvailableTags() {
|
|
13
13
|
if (lasttarget !== target) {
|
|
14
14
|
groups = await tagClient.availableForTarget(target);
|
|
15
15
|
tags = groups.flatMap(g => g.tags.map(t => ({ ...t, lcname: t.name.toLocaleLowerCase(), group: { ...g, lctitle: g.title?.toLocaleLowerCase() ?? '' } })));
|
|
16
16
|
lasttarget = target;
|
|
17
17
|
}
|
|
18
|
+
}
|
|
19
|
+
function tagToOption(tag) {
|
|
20
|
+
return { label: `${tag.group.title ?? ''}${isNotBlank(tag.group.title) ? ': ' : ''}${tag.name}`, value: tag.id };
|
|
21
|
+
}
|
|
22
|
+
async function getOptions(search) {
|
|
23
|
+
await fetchAvailableTags();
|
|
18
24
|
const lcsearch = search?.toLocaleLowerCase() ?? '';
|
|
19
|
-
return tags.filter(t => t.lcname.includes(lcsearch) || t.group.lctitle.includes(lcsearch)).map(
|
|
25
|
+
return tags.filter(t => t.lcname.includes(lcsearch) || t.group.lctitle.includes(lcsearch)).map(tagToOption);
|
|
26
|
+
}
|
|
27
|
+
async function lookupByValue(id) {
|
|
28
|
+
await fetchAvailableTags();
|
|
29
|
+
const tag = tags.find(t => t.id === id);
|
|
30
|
+
if (!tag)
|
|
31
|
+
return undefined;
|
|
32
|
+
return tagToOption(tag);
|
|
20
33
|
}
|
|
21
34
|
</script>
|
|
22
35
|
|
|
23
|
-
<FieldMultiselect {path} {label} {getOptions} />
|
|
36
|
+
<FieldMultiselect {path} {label} {getOptions} {lookupByValue} />
|
package/package.json
CHANGED