@dosgato/dialog 0.0.41 → 0.0.42
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.
package/FieldAutocomplete.svelte
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>import { nullableSerialize, nullableDeserialize } from '@txstate-mws/svelte-forms';
|
|
2
2
|
import FieldStandard from './FieldStandard.svelte';
|
|
3
|
-
import { randomid } from 'txstate-utils';
|
|
4
|
-
import { PopupMenu, ScreenReaderOnly } from '@txstate-mws/svelte-components';
|
|
3
|
+
import { isBlank, isNotBlank, randomid } from 'txstate-utils';
|
|
4
|
+
import { modifierKey, PopupMenu, ScreenReaderOnly } from '@txstate-mws/svelte-components';
|
|
5
5
|
import { getDescribedBy } from './';
|
|
6
6
|
import { onMount } from 'svelte';
|
|
7
7
|
export let id = undefined;
|
|
@@ -13,47 +13,63 @@ export { className as class };
|
|
|
13
13
|
export let notNull = false;
|
|
14
14
|
export let disabled = false;
|
|
15
15
|
export let choices;
|
|
16
|
-
export let defaultValue =
|
|
16
|
+
export let defaultValue = undefined;
|
|
17
17
|
export let conditional = undefined;
|
|
18
18
|
export let required = false;
|
|
19
19
|
export let inputelement = undefined;
|
|
20
20
|
export let helptext = undefined;
|
|
21
21
|
let inputvalue = '';
|
|
22
22
|
let popupvalue = undefined;
|
|
23
|
-
let savedLabel = '';
|
|
24
|
-
let changed = false;
|
|
25
23
|
let menuid;
|
|
26
24
|
const liveTextId = randomid();
|
|
27
|
-
$:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
$: finalserialize = !notNull ? nullableSerialize : v => v;
|
|
26
|
+
$: finaldeserialize = !notNull ? nullableDeserialize : v => v;
|
|
27
|
+
$: valueToLabel = Object.fromEntries(choices.map(c => [c.value, c.label || c.value]));
|
|
28
|
+
$: labelToValue = Object.fromEntries(choices.map(c => [c.label || c.value, c.value]));
|
|
29
|
+
$: filteredChoices = choices.filter((item) => {
|
|
30
|
+
return item.label?.toLowerCase().includes(inputvalue.toLowerCase()) || item.value.toLowerCase().includes(inputvalue.toLowerCase());
|
|
31
|
+
});
|
|
32
|
+
let menushown = false;
|
|
33
|
+
let savedVal = defaultValue;
|
|
34
|
+
function onKeyUp(setVal) {
|
|
35
|
+
return (e) => {
|
|
36
|
+
if (!modifierKey(e)) {
|
|
37
|
+
const val = labelToValue[inputvalue.trim()];
|
|
38
|
+
menushown = !val;
|
|
39
|
+
// we need to make sure the form state stays up to date with what's shown in the text field
|
|
40
|
+
// if the text field has only a substring of a valid label the form state value should remain
|
|
41
|
+
// empty, but once the text field has a valid label the form state should be updated
|
|
42
|
+
if (savedVal !== val) {
|
|
43
|
+
savedVal = val;
|
|
44
|
+
setVal(val);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
32
49
|
function onchangepopup(setVal) {
|
|
33
50
|
return (e) => {
|
|
34
51
|
inputvalue = e.detail.label || e.detail.value;
|
|
35
|
-
savedLabel = inputvalue;
|
|
36
52
|
popupvalue = undefined;
|
|
53
|
+
savedVal = e.detail.value;
|
|
37
54
|
setVal(e.detail.value);
|
|
38
|
-
changed = false;
|
|
39
55
|
};
|
|
40
56
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
function reactToValue(value, setVal) {
|
|
58
|
+
const dsvalue = finaldeserialize(value);
|
|
59
|
+
if (dsvalue !== savedVal) {
|
|
60
|
+
const label = valueToLabel[dsvalue];
|
|
61
|
+
// if the form state value changes from the outside we need to replace the text field content
|
|
62
|
+
// with the new label
|
|
63
|
+
// if the new form state value is undefined, we should let them keep any half-finished typing they
|
|
64
|
+
// might have in the field, but if they have a fully valid entry in the field, it needs to disappear
|
|
65
|
+
// to reflect the new reality that the form value has gone away
|
|
66
|
+
if (label != null || (savedVal && valueToLabel[savedVal]))
|
|
67
|
+
inputvalue = label ?? '';
|
|
68
|
+
savedVal = dsvalue;
|
|
69
|
+
// if the form state value changes from the outside to an invalid value, we have to clear it out
|
|
70
|
+
if (isNotBlank(dsvalue) && isBlank(label))
|
|
71
|
+
setVal(finaldeserialize(''));
|
|
72
|
+
}
|
|
57
73
|
}
|
|
58
74
|
let portal;
|
|
59
75
|
onMount(() => {
|
|
@@ -61,10 +77,10 @@ onMount(() => {
|
|
|
61
77
|
});
|
|
62
78
|
</script>
|
|
63
79
|
|
|
64
|
-
<FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {helptext} serialize={
|
|
65
|
-
{@const _ =
|
|
66
|
-
<input bind:this={inputelement} bind:value={inputvalue} {id} {placeholder} class="dialog-input {className}" class:valid class:invalid aria-invalid={invalid} aria-expanded={false} aria-controls={menuid} on:blur={onBlur} on:
|
|
67
|
-
<PopupMenu bind:menuid align="bottomleft" usePortal={portal} items={filteredChoices} buttonelement={inputelement} bind:value={popupvalue} on:change={onchangepopup(setVal)} emptyText="No options available"/>
|
|
80
|
+
<FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {helptext} serialize={finalserialize} deserialize={finaldeserialize} let:value let:setVal let:valid let:invalid let:id let:onBlur let:messagesid let:helptextid>
|
|
81
|
+
{@const _ = reactToValue(value, setVal)}
|
|
82
|
+
<input bind:this={inputelement} bind:value={inputvalue} {id} {placeholder} class="dialog-input {className}" class:valid class:invalid aria-invalid={invalid} aria-expanded={false} aria-controls={menuid} on:blur={onBlur} on:keyup={onKeyUp(setVal)} autocapitalize="none" type="text" autocomplete="off" aria-autocomplete="list" role="combobox" {disabled} aria-describedby={getDescribedBy([messagesid, helptextid])}>
|
|
83
|
+
<PopupMenu bind:menushown bind:menuid align="bottomleft" usePortal={portal} items={filteredChoices} buttonelement={inputelement} bind:value={popupvalue} on:change={onchangepopup(setVal)} emptyText="No options available"/>
|
|
68
84
|
<ScreenReaderOnly arialive="polite" ariaatomic={true} id={liveTextId}>
|
|
69
85
|
{filteredChoices.length} {filteredChoices.length === 1 ? 'option' : 'options'} available.
|
|
70
86
|
</ScreenReaderOnly>
|
|
@@ -13,7 +13,7 @@ declare const __propDef: {
|
|
|
13
13
|
value: string;
|
|
14
14
|
disabled?: boolean | undefined;
|
|
15
15
|
}[];
|
|
16
|
-
defaultValue?:
|
|
16
|
+
defaultValue?: string | undefined;
|
|
17
17
|
conditional?: boolean | undefined;
|
|
18
18
|
required?: boolean | undefined;
|
|
19
19
|
inputelement?: HTMLInputElement | undefined;
|
package/FieldMultiselect.svelte
CHANGED
|
@@ -11,6 +11,7 @@ export let disabled = false;
|
|
|
11
11
|
export let defaultValue = [];
|
|
12
12
|
export let conditional = undefined;
|
|
13
13
|
export let required = false;
|
|
14
|
+
export let maxSelections = 0;
|
|
14
15
|
export let getOptions;
|
|
15
16
|
// each time we run getOptions we will save the value -> label mappings
|
|
16
17
|
// that it finds, so that we can display labels on pills
|
|
@@ -54,7 +55,7 @@ async function reactToValue(value) {
|
|
|
54
55
|
<FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} let:value let:valid let:invalid let:id let:onBlur let:setVal>
|
|
55
56
|
{@const _ = reactToValue(value)}
|
|
56
57
|
<div class:valid class:invalid>
|
|
57
|
-
<MultiSelect {id} name={path} usePortal={portal} {disabled} selected={$selectedStore} {placeholder} getOptions={wrapGetOptions} on:change={e => setVal(e.detail.map(itm => itm.value))} on:blur={onBlur}></MultiSelect>
|
|
58
|
+
<MultiSelect {id} name={path} usePortal={portal} {disabled} {maxSelections} selected={$selectedStore} {placeholder} getOptions={wrapGetOptions} on:change={e => setVal(e.detail.map(itm => itm.value))} on:blur={onBlur}></MultiSelect>
|
|
58
59
|
</div>
|
|
59
60
|
</FieldStandard>
|
|
60
61
|
{/if}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dosgato/dialog",
|
|
3
3
|
"description": "A component library for building forms that edit a JSON document.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.42",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@txstate-mws/svelte-components": "^1.3.
|
|
6
|
+
"@txstate-mws/svelte-components": "^1.3.9",
|
|
7
7
|
"@txstate-mws/svelte-forms": "^1.3.4",
|
|
8
8
|
"@iconify/svelte": "^3.0.0",
|
|
9
9
|
"@iconify-icons/mdi": "^1.2.22",
|