@dosgato/dialog 1.2.0 → 1.2.2

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 getOptions(search) {
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.excludeTitle && isNotBlank(tag.group.title) ? 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(t => ({ label: `${t.group.title ?? ''}${isNotBlank(t.group.title) ? ': ' : ''}${t.name}`, value: t.id }));
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} />
@@ -6,6 +6,14 @@ export interface Tag {
6
6
  export interface TagGroup {
7
7
  id: string;
8
8
  title?: string;
9
+ /**
10
+ * The group title is not useful to disambiguate tag names, therefore it need not be prefixed onto
11
+ * the tag name when the tag is removed from its group context.
12
+ *
13
+ * Example: when the group title is "Misc" or "Ungrouped", you probably don't want to see "Misc: MyTag",
14
+ * you just want to see "MyTag"
15
+ */
16
+ excludeTitle?: boolean;
9
17
  tags: Tag[];
10
18
  }
11
19
  export interface TagClient<TargetTypes = any> {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dosgato/dialog",
3
3
  "description": "A component library for building forms that edit a JSON document.",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "scripts": {
6
6
  "prepublishOnly": "svelte-package",
7
7
  "dev": "vite dev --force",