@dosgato/dialog 0.0.54 → 0.0.55
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/dist/ButtonGroup.svelte +1 -1
- package/dist/FieldChoices.svelte +18 -2
- package/dist/FieldChooserLink.svelte +34 -14
- package/dist/FieldRadio.svelte +19 -1
- package/dist/FieldSelect.svelte +21 -2
- package/dist/Switcher.svelte +1 -1
- package/dist/colorpicker/FieldColorPicker.svelte +21 -4
- package/package.json +1 -1
package/dist/ButtonGroup.svelte
CHANGED
|
@@ -46,7 +46,7 @@ function onKeyDown(choice, idx) {
|
|
|
46
46
|
{/if}
|
|
47
47
|
<!-- svelte-ignore a11y-no-noninteractive-element-to-interactive-role -->
|
|
48
48
|
<ul class="dialog-btn-group" class:disabled class:valid class:invalid aria-disabled={disabled} role="radiogroup" aria-labelledby={groupid} on:blur>
|
|
49
|
-
{#each choices as choice, i}
|
|
49
|
+
{#each choices as choice, i (choice.value)}
|
|
50
50
|
{@const selected = choice.value === value}
|
|
51
51
|
<li bind:this={elements[i]} role="radio" class:selected aria-checked={selected} tabindex={selected ? 0 : -1} aria-controls={ariaControls} on:click={onClick(choice, i)} on:keydown={onKeyDown(choice, i)} on:blur aria-describedby="{groupid} {messagesid}">{choice.label || choice.value}</li>
|
|
52
52
|
{/each}
|
package/dist/FieldChoices.svelte
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
flex. Ordering is top down by default but can be order horizontally by toggling `leftToRight`.
|
|
5
5
|
The value of the field will be an array corresponding to the values of the checkboxes that are checked.
|
|
6
6
|
-->
|
|
7
|
-
<script>import { getContext } from 'svelte';
|
|
7
|
+
<script>import { getContext, onMount } from 'svelte';
|
|
8
8
|
import { Field, FORM_CONTEXT } from '@txstate-mws/svelte-forms';
|
|
9
9
|
import { derivedStore } from '@txstate-mws/svelte-store';
|
|
10
10
|
import { randomid } from 'txstate-utils';
|
|
@@ -46,12 +46,28 @@ function onChangeCheckbox(setVal, choice, included) {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
const descid = randomid();
|
|
49
|
+
let val, stVal;
|
|
50
|
+
function updateValue(valu, sVal) {
|
|
51
|
+
val = valu;
|
|
52
|
+
stVal = sVal;
|
|
53
|
+
}
|
|
54
|
+
function reactToChoices(..._) {
|
|
55
|
+
if (!stVal)
|
|
56
|
+
return;
|
|
57
|
+
const choiceSet = new Set(choices?.map(c => c.value));
|
|
58
|
+
const filtered = val?.filter(v => choiceSet.has(v));
|
|
59
|
+
if (filtered?.length !== val?.length)
|
|
60
|
+
stVal(filtered);
|
|
61
|
+
}
|
|
62
|
+
$: reactToChoices(choices);
|
|
63
|
+
onMount(reactToChoices);
|
|
49
64
|
</script>
|
|
50
65
|
|
|
51
66
|
<Field {path} {defaultValue} {conditional} let:path let:value let:onBlur let:setVal let:messages let:valid let:invalid>
|
|
67
|
+
{@const _ = updateValue(value, setVal)}
|
|
52
68
|
<Container {id} {label} {messages} {descid} {related} {helptext} let:messagesid let:helptextid>
|
|
53
69
|
<div class="dialog-choices {className}" class:valid class:invalid>
|
|
54
|
-
{#each choices as choice, idx}
|
|
70
|
+
{#each choices as choice, idx (choice.value)}
|
|
55
71
|
{@const checkid = `${path}.${idx}`}
|
|
56
72
|
{@const included = value && value.includes(choice.value)}
|
|
57
73
|
{@const label = choice.label || (typeof choice.value === 'string' ? choice.value : '')}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
<script context="module">function reconstructUrl(url) {
|
|
2
|
+
const urlToTest = (/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])/.test(url)) ? `https://${url}` : url;
|
|
3
|
+
return new URL(urlToTest).toString();
|
|
4
|
+
}
|
|
5
|
+
</script>
|
|
1
6
|
<script>import { FORM_CONTEXT, FORM_INHERITED_PATH } from '@txstate-mws/svelte-forms';
|
|
2
7
|
import { getContext } from 'svelte';
|
|
3
|
-
import { isNotBlank, randomid } from 'txstate-utils';
|
|
8
|
+
import { isBlank, isNotBlank, randomid } from 'txstate-utils';
|
|
4
9
|
import { Chooser, ChooserStore, CHOOSER_API_CONTEXT } from './chooser';
|
|
5
10
|
import Details from './chooser/Details.svelte';
|
|
6
11
|
import Thumbnail from './chooser/Thumbnail.svelte';
|
|
7
12
|
import FieldStandard from './FieldStandard.svelte';
|
|
13
|
+
import InlineMessage from './InlineMessage.svelte';
|
|
8
14
|
import { getDescribedBy } from './';
|
|
9
15
|
export let id = undefined;
|
|
10
16
|
export let path;
|
|
@@ -56,6 +62,11 @@ function userUrlEntry() {
|
|
|
56
62
|
async function userUrlEntryDebounced() {
|
|
57
63
|
const url = this.value;
|
|
58
64
|
store.clearPreview();
|
|
65
|
+
if (isBlank(url)) {
|
|
66
|
+
selectedAsset = undefined;
|
|
67
|
+
formStore.setField(finalPath, undefined);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
59
70
|
let found = false;
|
|
60
71
|
if (chooserClient.findByUrl) {
|
|
61
72
|
const item = await chooserClient.findByUrl(url);
|
|
@@ -83,18 +94,24 @@ async function userUrlEntryDebounced() {
|
|
|
83
94
|
}
|
|
84
95
|
}
|
|
85
96
|
if (!found) {
|
|
86
|
-
|
|
87
|
-
selectedAsset = {
|
|
88
|
-
type: 'raw',
|
|
89
|
-
id: urlToValueCache[url] ?? chooserClient.urlToValue?.(new URL(url).toString()),
|
|
90
|
-
url
|
|
91
|
-
};
|
|
97
|
+
if (urlToValueCache[url]) {
|
|
98
|
+
selectedAsset = { type: 'raw', id: urlToValueCache[url], url };
|
|
92
99
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
else {
|
|
101
|
+
try {
|
|
102
|
+
const reconstructed = reconstructUrl(url);
|
|
103
|
+
selectedAsset = {
|
|
104
|
+
type: 'raw',
|
|
105
|
+
id: chooserClient.urlToValue?.(reconstructed) ?? reconstructed,
|
|
106
|
+
url
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// here we "select" a raw url so that we do not interrupt the users' typing, but
|
|
111
|
+
// we set its id to 'undefined' so that nothing makes it into the form until it's
|
|
112
|
+
// a valid URL
|
|
113
|
+
selectedAsset = { type: 'raw', id: undefined, url };
|
|
114
|
+
}
|
|
98
115
|
}
|
|
99
116
|
}
|
|
100
117
|
formStore.setField(finalPath, selectedAsset?.id);
|
|
@@ -112,7 +129,7 @@ async function updateSelected(..._) {
|
|
|
112
129
|
if (!selectedAsset) {
|
|
113
130
|
const urlFromValue = chooserClient.valueToUrl?.($value) ?? $value;
|
|
114
131
|
try {
|
|
115
|
-
selectedAsset = { type: 'raw', id: $value, url:
|
|
132
|
+
selectedAsset = { type: 'raw', id: $value, url: reconstructUrl(urlFromValue) };
|
|
116
133
|
}
|
|
117
134
|
catch {
|
|
118
135
|
selectedAsset = { type: 'broken', id: $value, url: $value };
|
|
@@ -129,7 +146,7 @@ $: updateSelected($value);
|
|
|
129
146
|
</script>
|
|
130
147
|
|
|
131
148
|
<FieldStandard bind:id {path} {descid} {label} {defaultValue} {conditional} {required} {related} {helptext} let:value let:messagesid let:helptextid let:valid let:invalid let:id let:onBlur let:setVal>
|
|
132
|
-
{#if selectedAsset}
|
|
149
|
+
{#if selectedAsset?.id}
|
|
133
150
|
<div class="dialog-chooser-container">
|
|
134
151
|
<Thumbnail item={selectedAsset} />
|
|
135
152
|
<Details item={selectedAsset} />
|
|
@@ -141,6 +158,9 @@ $: updateSelected($value);
|
|
|
141
158
|
{/if}
|
|
142
159
|
<button type="button" on:click={show} aria-describedby={getDescribedBy([descid, messagesid, helptextid, extradescid])}>Select {#if value}New{/if} {#if assets && pages}Link Target{:else if images}Image{:else if assets}Asset{:else}Page{/if}</button>
|
|
143
160
|
</div>
|
|
161
|
+
{#if selectedAsset?.url.length && !selectedAsset.id}
|
|
162
|
+
<InlineMessage message={{ message: 'Entry does not match an internal resource and is not a valid URL. Nothing will be saved.', type: 'warning' }} />
|
|
163
|
+
{/if}
|
|
144
164
|
{#if modalshown}
|
|
145
165
|
<Chooser {store} {label} {pages} {assets} {images} {initialSource} {initialPath} {folders} {required} on:change={onChange(setVal)} on:escape={hide} />
|
|
146
166
|
{/if}
|
package/dist/FieldRadio.svelte
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script>import { Field } from '@txstate-mws/svelte-forms';
|
|
2
|
+
import { onMount } from 'svelte';
|
|
2
3
|
import Switcher from './Switcher.svelte';
|
|
3
4
|
let className = '';
|
|
4
5
|
export { className as class };
|
|
@@ -20,8 +21,25 @@ export let datetime = false;
|
|
|
20
21
|
export let boolean = false;
|
|
21
22
|
export let serialize = undefined;
|
|
22
23
|
export let deserialize = undefined;
|
|
24
|
+
let val, stVal, finalDeserialize;
|
|
25
|
+
function updateValue(valu, sVal, fDes) {
|
|
26
|
+
val = valu;
|
|
27
|
+
stVal = sVal;
|
|
28
|
+
finalDeserialize = fDes;
|
|
29
|
+
}
|
|
30
|
+
function reactToChoices(..._) {
|
|
31
|
+
if (!stVal)
|
|
32
|
+
return;
|
|
33
|
+
if (!choices.length)
|
|
34
|
+
stVal(finalDeserialize(''));
|
|
35
|
+
if (!choices.some(o => o.value === val))
|
|
36
|
+
stVal(notNull ? choices[0].value : finalDeserialize(''));
|
|
37
|
+
}
|
|
38
|
+
$: reactToChoices(choices);
|
|
39
|
+
onMount(reactToChoices);
|
|
23
40
|
</script>
|
|
24
41
|
|
|
25
|
-
<Field {path} {defaultValue} {conditional} {notNull} {number} {date} {datetime} {boolean} {serialize} {deserialize} let:value let:valid let:invalid let:onBlur let:onChange let:messages let:serialize>
|
|
42
|
+
<Field {path} {defaultValue} {conditional} {notNull} {number} {date} {datetime} {boolean} {serialize} {deserialize} let:value let:valid let:invalid let:onBlur let:onChange let:messages let:serialize let:setVal let:deserialize>
|
|
43
|
+
{@const _ = updateValue(value, setVal, deserialize)}
|
|
26
44
|
<Switcher bind:id class={className} name={path} {horizontal} {label} iptValue={value} {valid} {invalid} {required} {related} {extradescid} {helptext} {messages} on:change={onChange} {onBlur} choices={choices.map(c => ({ ...c, value: serialize(c.value) }))} />
|
|
27
45
|
</Field>
|
package/dist/FieldSelect.svelte
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { onMount } from 'svelte';
|
|
2
|
+
import { isBlank } from 'txstate-utils';
|
|
3
|
+
import { getDescribedBy } from './';
|
|
2
4
|
import FieldStandard from './FieldStandard.svelte';
|
|
3
5
|
let className = '';
|
|
4
6
|
export { className as class };
|
|
@@ -22,9 +24,26 @@ export let datetime = false;
|
|
|
22
24
|
export let boolean = false;
|
|
23
25
|
export let serialize = undefined;
|
|
24
26
|
export let deserialize = undefined;
|
|
27
|
+
let val, stVal, finalDeserialize;
|
|
28
|
+
function updateValue(valu, sVal, fDes) {
|
|
29
|
+
val = valu;
|
|
30
|
+
stVal = sVal;
|
|
31
|
+
finalDeserialize = fDes;
|
|
32
|
+
}
|
|
33
|
+
function reactToChoices(..._) {
|
|
34
|
+
if (!stVal)
|
|
35
|
+
return;
|
|
36
|
+
if (!choices.length)
|
|
37
|
+
stVal(finalDeserialize(''));
|
|
38
|
+
if (!choices.some(o => o.value === val))
|
|
39
|
+
stVal(notNull ? choices[0].value : finalDeserialize(''));
|
|
40
|
+
}
|
|
41
|
+
$: reactToChoices(choices);
|
|
42
|
+
onMount(reactToChoices);
|
|
25
43
|
</script>
|
|
26
44
|
|
|
27
|
-
<FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {related} {helptext} {notNull} {number} {date} {datetime} {boolean} {serialize} {deserialize} let:value let:valid let:invalid let:id let:onBlur let:onChange let:messagesid let:helptextid let:serialize>
|
|
45
|
+
<FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {related} {helptext} {notNull} {number} {date} {datetime} {boolean} {serialize} {deserialize} let:value let:valid let:invalid let:id let:onBlur let:onChange let:messagesid let:helptextid let:serialize let:deserialize let:setVal>
|
|
46
|
+
{@const _ = updateValue(value, setVal, deserialize)}
|
|
28
47
|
<select bind:this={inputelement} {id} name={path} {disabled} class="dialog-input dialog-select {className}" on:change={onChange} on:blur={onBlur} class:valid class:invalid aria-describedby={getDescribedBy([messagesid, helptextid, extradescid])}>
|
|
29
48
|
{#if !notNull}<option value="" selected={!value}>{placeholder}</option>{/if}
|
|
30
49
|
{#each choices as choice (choice.value)}
|
package/dist/Switcher.svelte
CHANGED
|
@@ -32,7 +32,7 @@ $: width = (horizontal ? 100 / Math.min(choices.length, choices.length === 4 &&
|
|
|
32
32
|
</script>
|
|
33
33
|
<Container {id} {label} {messages} descid={groupid} {required} {related} {helptext} let:helptextid>
|
|
34
34
|
<div class="dialog-radio {className}" use:eq={{ store }} class:horizontal role="radiogroup" aria-labelledby={groupid} class:valid class:invalid>
|
|
35
|
-
{#each choices as choice, idx}
|
|
35
|
+
{#each choices as choice, idx (choice.value)}
|
|
36
36
|
{@const radioid = `${groupid}.${idx}`}
|
|
37
37
|
<label for={radioid} style:width>
|
|
38
38
|
<Radio id={radioid} {name} value={choice.value} selected={iptValue === choice.value} disabled={choice.disabled} {onChange} {onBlur} {helptextid} {extradescid} />
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
<script>import
|
|
2
|
-
import { Radio } from '..';
|
|
1
|
+
<script>import { onMount } from 'svelte';
|
|
3
2
|
import { randomid, shouldUseWhiteText } from 'txstate-utils';
|
|
3
|
+
import FieldStandard from '../FieldStandard.svelte';
|
|
4
|
+
import { Radio } from '..';
|
|
4
5
|
export let id = undefined;
|
|
5
6
|
let className = '';
|
|
6
7
|
export { className as class };
|
|
@@ -14,15 +15,31 @@ export let defaultValue = notNull ? (addAllOption ? 'alternating' : options[0].v
|
|
|
14
15
|
export let conditional = undefined;
|
|
15
16
|
export let helptext = undefined;
|
|
16
17
|
const groupid = randomid();
|
|
18
|
+
let val, stVal;
|
|
19
|
+
function updateValue(valu, sVal) {
|
|
20
|
+
val = valu;
|
|
21
|
+
stVal = sVal;
|
|
22
|
+
}
|
|
23
|
+
function reactToOptions(..._) {
|
|
24
|
+
if (!stVal)
|
|
25
|
+
return;
|
|
26
|
+
if (!options.length)
|
|
27
|
+
stVal(addAllOption ? 'alternating' : undefined);
|
|
28
|
+
if (val !== 'alternating' && !options.some(o => o.value === val))
|
|
29
|
+
stVal(notNull ? options[0].value : (addAllOption ? 'alternating' : undefined));
|
|
30
|
+
}
|
|
31
|
+
$: reactToOptions(options);
|
|
32
|
+
onMount(reactToOptions);
|
|
17
33
|
</script>
|
|
18
34
|
|
|
19
|
-
<FieldStandard bind:id descid={groupid} {path} {label} {required} {defaultValue} {conditional} {helptext} let:value let:valid let:invalid let:onBlur let:onChange let:messagesid let:helptextid>
|
|
35
|
+
<FieldStandard bind:id descid={groupid} {path} {label} {required} {defaultValue} {conditional} {helptext} let:value let:valid let:invalid let:onBlur let:onChange let:messagesid let:helptextid let:setVal>
|
|
36
|
+
{@const _ = updateValue(value, setVal)}
|
|
20
37
|
<div class="color-container {className}" role="radiogroup" aria-labelledby={groupid} class:invalid class:valid>
|
|
21
38
|
{#if addAllOption}
|
|
22
39
|
<label for={`${path}.alt`} class="colorsel alternating">
|
|
23
40
|
<Radio id={`${path}.alt`} name={path} value="alternating" selected={value === 'alternating'} {onChange} {onBlur} {helptextid}/>
|
|
24
41
|
<span class="alternating-bg">
|
|
25
|
-
{#each options as option}
|
|
42
|
+
{#each options as option (option.value)}
|
|
26
43
|
<span style:background-color={option.color}></span>
|
|
27
44
|
{/each}
|
|
28
45
|
</span>
|
package/package.json
CHANGED