@dosgato/dialog 1.1.14 → 1.1.16

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.
@@ -5,9 +5,9 @@
5
5
  The value of the field will be an array corresponding to the values of the checkboxes that are checked.
6
6
  -->
7
7
  <script>import { getContext, onMount } from 'svelte';
8
- import { Field, FORM_CONTEXT, arraySerialize } from '@txstate-mws/svelte-forms';
8
+ import { Field, FORM_CONTEXT, arraySerialize, FORM_INHERITED_PATH } from '@txstate-mws/svelte-forms';
9
9
  import { derivedStore } from '@txstate-mws/svelte-store';
10
- import { randomid } from 'txstate-utils';
10
+ import { get, isNotBlank, randomid } from 'txstate-utils';
11
11
  import Container from './Container.svelte';
12
12
  import Checkbox from './Checkbox.svelte';
13
13
  import { getDescribedBy } from './helpers';
@@ -25,6 +25,8 @@ export let related = 0;
25
25
  export let extradescid = undefined;
26
26
  export let helptext = undefined;
27
27
  const store = getContext(FORM_CONTEXT);
28
+ const inheritedPath = getContext(FORM_INHERITED_PATH);
29
+ const finalPath = [inheritedPath, path].filter(isNotBlank).join('.');
28
30
  const currentWidth = derivedStore(store, 'width');
29
31
  $: cols = Math.min(Math.ceil($currentWidth / maxwidth), choices.length);
30
32
  let orders;
@@ -46,25 +48,18 @@ function onChangeCheckbox(setVal, choice, included) {
46
48
  });
47
49
  }
48
50
  const descid = randomid();
49
- let val, stVal;
50
- function updateValue(valu, sVal) {
51
- val = valu;
52
- stVal = sVal;
53
- }
54
51
  function reactToChoices(..._) {
55
- if (!stVal)
56
- return;
57
52
  const choiceSet = new Set(choices?.map(c => c.value));
53
+ const val = get($store, finalPath);
58
54
  const filtered = val?.filter(v => choiceSet.has(v));
59
55
  if (filtered?.length !== val?.length)
60
- stVal(filtered, true);
56
+ store.setField(finalPath, filtered).catch(console.error);
61
57
  }
62
58
  $: reactToChoices(choices);
63
59
  onMount(reactToChoices);
64
60
  </script>
65
61
 
66
62
  <Field {path} {defaultValue} {conditional} let:path let:value let:onBlur let:setVal let:messages let:valid let:invalid serialize={arraySerialize}>
67
- {@const _ = updateValue(value, setVal)}
68
63
  <Container {path} {id} {label} {messages} {descid} {related} {helptext} let:messagesid let:helptextid>
69
64
  <div class="dialog-choices {className}" class:valid class:invalid>
70
65
  {#each choices as choice, idx (choice.value)}
@@ -183,7 +183,7 @@ $: void updateSelected($value);
183
183
  <div class="dialog-chooser-entry">
184
184
  {#if urlEntry}
185
185
  <div class="dialog-chooser-entry-input">
186
- <input bind:this={urlEntryInput} type="text" data-lpignore="true" value={selectedAsset?.url ?? ''} on:change={userUrlEntry} on:input={userUrlEntry}>
186
+ <input bind:this={urlEntryInput} {id} type="text" data-lpignore="true" value={selectedAsset?.url ?? ''} on:change={userUrlEntry} on:input={userUrlEntry} on:blur={onBlur}>
187
187
  <button type="button" on:click={clearUrlEntry}><Icon icon={xCircle} hiddenLabel="clear input" inline/></button>
188
188
  </div>
189
189
  {/if}
@@ -1,5 +1,6 @@
1
- <script>import { Field } from '@txstate-mws/svelte-forms';
2
- import { onMount } from 'svelte';
1
+ <script>import { FORM_CONTEXT, FORM_INHERITED_PATH, Field } from '@txstate-mws/svelte-forms';
2
+ import { getContext, onMount } from 'svelte';
3
+ import { get, isNotBlank } from 'txstate-utils';
3
4
  import Switcher from './Switcher.svelte';
4
5
  let className = '';
5
6
  export { className as class };
@@ -21,27 +22,28 @@ export let datetime = false;
21
22
  export let boolean = false;
22
23
  export let serialize = undefined;
23
24
  export let deserialize = undefined;
24
- let val, stVal, finalDeserialize;
25
- function updateValue(valu, sVal, fDes) {
26
- val = valu;
27
- stVal = sVal;
25
+ const store = getContext(FORM_CONTEXT);
26
+ const inheritedPath = getContext(FORM_INHERITED_PATH);
27
+ const finalPath = [inheritedPath, path].filter(isNotBlank).join('.');
28
+ let finalDeserialize;
29
+ function updateDeserialize(fDes) {
28
30
  finalDeserialize = fDes;
29
31
  }
30
- function reactToChoices(..._) {
31
- if (!stVal)
32
+ async function reactToChoices(..._) {
33
+ if (!finalDeserialize)
32
34
  return;
33
35
  if (!choices.length) {
34
- stVal(finalDeserialize(''), true);
35
- return;
36
+ return await store.setField(finalPath, finalDeserialize(''));
36
37
  }
38
+ const val = get($store, finalPath);
37
39
  if (!choices.some(o => o.value === finalDeserialize(val)))
38
- stVal(notNull ? defaultValue : finalDeserialize(''), true);
40
+ await store.setField(finalPath, notNull ? defaultValue : finalDeserialize(''));
39
41
  }
40
- $: reactToChoices(choices);
42
+ $: reactToChoices(choices).catch(console.error);
41
43
  onMount(reactToChoices);
42
44
  </script>
43
45
 
44
- <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>
45
- {@const _ = updateValue(value, setVal, deserialize)}
46
+ <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:deserialize>
47
+ {@const _ = updateDeserialize(deserialize)}
46
48
  <Switcher bind:id {path} 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) }))} />
47
49
  </Field>
@@ -1,4 +1,6 @@
1
- <script>import { onMount } from 'svelte';
1
+ <script>import { FORM_CONTEXT, FORM_INHERITED_PATH } from '@txstate-mws/svelte-forms';
2
+ import { getContext, onMount } from 'svelte';
3
+ import { isNotBlank, get, equal } from 'txstate-utils';
2
4
  import { getDescribedBy } from './';
3
5
  import FieldStandard from './FieldStandard.svelte';
4
6
  let className = '';
@@ -23,28 +25,29 @@ export let datetime = false;
23
25
  export let boolean = false;
24
26
  export let serialize = undefined;
25
27
  export let deserialize = undefined;
26
- let val, stVal, finalDeserialize;
27
- function updateValue(valu, sVal, fDes) {
28
- val = valu;
29
- stVal = sVal;
28
+ const store = getContext(FORM_CONTEXT);
29
+ const inheritedPath = getContext(FORM_INHERITED_PATH);
30
+ const finalPath = [inheritedPath, path].filter(isNotBlank).join('.');
31
+ let finalDeserialize;
32
+ function updateDeserialize(fDes) {
30
33
  finalDeserialize = fDes;
31
34
  }
32
- function reactToChoices(..._) {
33
- if (!stVal)
35
+ async function reactToChoices(..._) {
36
+ if (!finalDeserialize)
34
37
  return;
35
38
  if (!choices.length) {
36
- stVal(finalDeserialize(''), true);
37
- return;
39
+ return await store.setField(finalPath, finalDeserialize(''));
38
40
  }
39
- if (!choices.some(o => o.value === finalDeserialize(val)))
40
- stVal(notNull ? defaultValue : finalDeserialize(''), true);
41
+ const val = get($store.data, finalPath);
42
+ if (!choices.some(o => equal(o.value, val)))
43
+ await store.setField(finalPath, notNull ? defaultValue : finalDeserialize(''));
41
44
  }
42
- $: reactToChoices(choices);
45
+ $: reactToChoices(choices).catch(console.error);
43
46
  onMount(reactToChoices);
44
47
  </script>
45
48
 
46
- <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>
47
- {@const _ = updateValue(value, setVal, deserialize)}
49
+ <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>
50
+ {@const _ = updateDeserialize(deserialize)}
48
51
  <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])}>
49
52
  {#if !notNull}<option value="" selected={!value}>{placeholder}</option>{/if}
50
53
  {#each choices as choice (choice.value)}
@@ -6,8 +6,6 @@ import { isNotBlank, randomid } from 'txstate-utils';
6
6
  import { Button, Dialog, iconForMime, Tabs, Tree, UploadUI, expandTreePath } from '..';
7
7
  import { CHOOSER_API_CONTEXT } from './ChooserAPI';
8
8
  import { CHOOSER_STORE_CONTEXT, ChooserStore } from './ChooserStore';
9
- import Details from './Details.svelte';
10
- import Thumbnail from './Thumbnail.svelte';
11
9
  import ChooserPreview from './ChooserPreview.svelte';
12
10
  const chooserClient = getContext(CHOOSER_API_CONTEXT);
13
11
  export let label = undefined;
@@ -39,7 +39,8 @@ export class ChooserStore extends Store {
39
39
  const $source = this.getSource();
40
40
  if (item?.type === 'asset' || !$source)
41
41
  return [];
42
- return await this.client.getChildren($source.name, item?.path ?? '/', this.filter);
42
+ const imageFilter = this.options.images ? (itm) => ((itm.type === 'asset' && !!itm.image) || itm.type === 'folder') : nofilter;
43
+ return (await this.client.getChildren($source.name, item?.path ?? '/', this.filter)).filter(imageFilter);
43
44
  }
44
45
  treeStore = new TreeStore(this.fetchChildren.bind(this));
45
46
  sources = derivedStore(this, v => [...(v.sources?.page ?? []), ...(v.sources?.asset ?? [])].filter(s => this.options.activeSources ? this.options.activeSources.has(s.name) : true));
@@ -105,7 +105,7 @@ function onKeyDown(e) {
105
105
 
106
106
  <FieldStandard bind:id {path} {descid} {label} {required} {defaultValue} {conditional} {helptext} let:value let:valid let:invalid let:id let:onBlur let:setVal let:messagesid let:helptextid>
107
107
  <Icon icon={`${value.prefix === 'fab' ? 'fa6-brands' : 'fa6-solid'}:${value.icon?.slice(3) ?? 'graduation-cap'}`}/>
108
- <button type="button" id="btnSelectIcon" class="select-icon" on:click={() => { modalOpen = true }} aria-describedby={getDescribedBy([descid, messagesid, helptextid])}>Select New Icon</button>
108
+ <button type="button" {id} class="select-icon" on:click={() => { modalOpen = true }} aria-describedby={getDescribedBy([descid, messagesid, helptextid])} on:blur={onBlur}>Select New Icon</button>
109
109
  {#if modalOpen}
110
110
  <Modal>
111
111
  <section>
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.1.14",
4
+ "version": "1.1.16",
5
5
  "scripts": {
6
6
  "prepublishOnly": "svelte-package",
7
7
  "dev": "vite dev --force",