@dosgato/dialog 1.5.6 → 1.5.9

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.
@@ -26,6 +26,8 @@
26
26
  export let required = false
27
27
  export let related: true | number = 0
28
28
  export let conditional: boolean | undefined = undefined
29
+ let className = ''
30
+ export { className as class }
29
31
  /** The `id` of `<div>` messages are rendered in. */
30
32
  let messagesid: string | undefined
31
33
 
@@ -55,7 +57,7 @@
55
57
  </script>
56
58
 
57
59
  {#if conditional !== false}
58
- <div use:eq class="dialog-field-container" data-related={Array.from({ length: related === true ? 1 : related }, (_, i) => i + 1).join(' ')}>
60
+ <div use:eq class="dialog-field-container {className}" data-related={Array.from({ length: related === true ? 1 : related }, (_, i) => i + 1).join(' ')}>
59
61
  {#if descid == null}
60
62
  <label class="dialog-field-label" for={id}>{label}{#if required}&nbsp;*{/if}</label>
61
63
  {:else}
@@ -12,6 +12,7 @@ declare const __propDef: {
12
12
  /** Syntactic sugar that toggles a '*' to be appended to label. */ required?: boolean;
13
13
  related?: true | number;
14
14
  conditional?: boolean | undefined;
15
+ class?: string;
15
16
  };
16
17
  events: {
17
18
  [evt: string]: CustomEvent<any>;
@@ -5,11 +5,11 @@
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 lang="ts">
8
- import { getContext, onMount } from 'svelte'
8
+ import { getContext } from 'svelte'
9
9
  import { Field, FORM_CONTEXT, arraySerialize, FORM_INHERITED_PATH } from '@txstate-mws/svelte-forms'
10
10
  import type { FormStore } from '@txstate-mws/svelte-forms'
11
11
  import { derivedStore } from '@txstate-mws/svelte-store'
12
- import { get, isNotBlank, randomid } from 'txstate-utils'
12
+ import { isNotBlank, randomid } from 'txstate-utils'
13
13
  import Container from './Container.svelte'
14
14
  import Checkbox from './Checkbox.svelte'
15
15
  import { getDescribedBy } from './helpers'
@@ -19,7 +19,7 @@
19
19
  export let id: string | undefined = undefined
20
20
  export let path: string
21
21
  export let label = ''
22
- export let choices: { label?: string, value: any, disabled?: boolean }[]
22
+ export let choices: { label?: string, value: any, disabled?: boolean }[] | undefined
23
23
  export let defaultValue: any = []
24
24
  export let conditional: boolean | undefined = undefined
25
25
  export let maxwidth = 250
@@ -34,18 +34,18 @@
34
34
  const finalPath = [inheritedPath, path].filter(isNotBlank).join('.')
35
35
  const val = store.getField<any[]>(finalPath)
36
36
  const currentWidth = derivedStore(store, 'width')
37
- $: cols = Math.min(Math.ceil($currentWidth / maxwidth), choices.length)
37
+ $: cols = Math.min(Math.ceil($currentWidth / maxwidth), choices?.length ?? 0)
38
38
 
39
39
  let orders: number[]
40
40
  let width = '100%'
41
41
  function redoLayout (..._: any) {
42
42
  width = `${100 / cols}%`
43
- const rows = Math.ceil(choices.length / cols)
44
- orders = choices.map((_, i) => leftToRight ? i : Math.floor((i + 1) / cols) + rows * (i % cols))
43
+ const rows = Math.ceil((choices?.length ?? 0) / cols)
44
+ orders = choices?.map((_, i) => leftToRight ? i : Math.floor((i + 1) / cols) + rows * (i % cols)) ?? []
45
45
  }
46
46
  $: redoLayout(choices, cols)
47
47
 
48
- function onChangeCheckbox (setVal: (val: any) => void, choice: typeof choices[number], included: boolean) {
48
+ function onChangeCheckbox (setVal: (val: any) => void, choice: NonNullable<typeof choices>[number], included: boolean) {
49
49
  setVal(v => {
50
50
  if (v == null) return included ? [] : [choice.value]
51
51
  if (included) return v.filter(s => s !== choice.value)
@@ -62,7 +62,7 @@
62
62
  let selectAllElement: HTMLInputElement | undefined
63
63
  const selectAllId = randomid()
64
64
 
65
- $: selectAllChecked = choices.every(choice => choice.disabled || selected.has(choice.value))
65
+ $: selectAllChecked = choices?.every(choice => choice.disabled || selected.has(choice.value)) ?? false
66
66
 
67
67
  function selectAllChanged () {
68
68
  if (selectAllChecked) {
@@ -70,24 +70,14 @@
70
70
  void store.setField(finalPath, [])
71
71
  } else {
72
72
  // it was not checked and now it is checked
73
- void store.setField(finalPath, choices.filter(choice => !choice.disabled).map(choice => choice.value))
73
+ void store.setField(finalPath, choices?.filter(choice => !choice.disabled).map(choice => choice.value) ?? [])
74
74
  }
75
75
  }
76
76
 
77
77
  const descid = randomid()
78
-
79
- function reactToChoices (..._: any[]) {
80
- const choiceSet = new Set(choices?.filter(c => !c.disabled).map(c => c.value))
81
- selected = new Set(Array.from(selected).filter(v => choiceSet.has(v)))
82
- const val = get($store.data, finalPath)
83
- const filtered = val?.filter(v => choiceSet.has(v))
84
- if (filtered?.length !== val?.length) store.setField(finalPath, filtered).catch(console.error)
85
- }
86
- $: reactToChoices(choices)
87
- onMount(reactToChoices)
88
78
  </script>
89
79
 
90
- <Field {path} {defaultValue} {conditional} let:path={fullpath} let:value let:onBlur let:setVal let:messages let:valid let:invalid serialize={arraySerialize}>
80
+ <Field {path} {defaultValue} allowedValues={choices?.map(choice => choice.value)} allowedValuesMultiple {conditional} let:path={fullpath} let:value let:onBlur let:setVal let:messages let:valid let:invalid serialize={arraySerialize}>
91
81
  <Container path={fullpath} {id} {label} {messages} {descid} {related} {helptext} let:messagesid let:helptextid>
92
82
  <div class="dialog-choices {className}" class:valid class:invalid>
93
83
  {#if selectAll}
@@ -9,7 +9,7 @@ declare const __propDef: {
9
9
  label?: string;
10
10
  value: any;
11
11
  disabled?: boolean;
12
- }[];
12
+ }[] | undefined;
13
13
  defaultValue?: any;
14
14
  conditional?: boolean | undefined;
15
15
  maxwidth?: number;
@@ -75,7 +75,7 @@
75
75
  let messages: Feedback[] = []
76
76
  </script>
77
77
 
78
- <Container {path} {label} {messages} {conditional} {related} {helptext} let:helptextid>
78
+ <Container {path} {label} {messages} {conditional} {related} {helptext} class={compact ? 'compact' : ''} let:helptextid>
79
79
  {noOp(fieldMultipleContext.helptextid = helptextid)}
80
80
  <AddMore bind:messages {path} {initialState} {minLength} {maxLength} {conditional} let:path={fullpath} let:currentLength let:maxLength={resolvedMaxLength} let:index let:minned let:maxed let:value let:onDelete let:onMoveUp let:onMoveDown>
81
81
  {@const showDelete = removable && !minned}
@@ -92,7 +92,7 @@
92
92
  {#if showDelete}<button class="dialog-multiple-delete" type="button" on:click|preventDefault|stopPropagation={confirmedDelete(onDelete, value)}><Icon icon={xCircle} hiddenLabel="remove from list" /></button>{/if}
93
93
  </div>{/if}
94
94
  </div>
95
- <svelte:fragment slot="addbutton" let:maxed let:onClick>
95
+ <svelte:fragment slot="addbutton" let:maxed let:onClick let:maxLength={resolvedMaxLength}>
96
96
  {#if !maxed || (maxed && resolvedMaxLength > 1)}
97
97
  <Button type="button" icon={plusCircleLight} class="{addMoreClass} dialog-multiple-button" disabled={maxed} on:click={onClick}>{maxed ? maxedText : addMoreText}</Button>
98
98
  {/if}
@@ -9,9 +9,9 @@
9
9
  export let path: string
10
10
  export let label = ''
11
11
  export let notNull = false
12
- export let choices: { label?: string, value: any, disabled?: boolean }[]
13
- export let defaultValue: any = notNull ? choices[0].value : undefined
14
- export let conditional: boolean | undefined = undefined
12
+ export let choices: { label?: string, value: any, disabled?: boolean }[] | undefined
13
+ export let defaultValue: any = undefined
14
+ export let conditional = true
15
15
  export let required = false
16
16
  export let horizontal = false
17
17
  export let related: true | number = 0
@@ -24,23 +24,10 @@
24
24
  export let serialize: ((value: any) => string) | undefined = undefined
25
25
  export let deserialize: ((value: string) => any) | undefined = undefined
26
26
 
27
- const store = getContext<FormStore>(FORM_CONTEXT)
28
27
  const inheritedPath = getContext<string>(FORM_INHERITED_PATH)
29
28
  const finalPath = [inheritedPath, path].filter(isNotBlank).join('.')
30
-
31
- let finalDeserialize: (value: string) => any
32
- async function reactToChoices (..._: any[]) {
33
- if (!finalDeserialize) return
34
- if (!choices.length) {
35
- return await store.setField(finalPath, finalDeserialize(''), { notDirty: true })
36
- }
37
- const val = get($store.data, finalPath)
38
- if (!choices.some(o => equal(o.value, val))) await store.setField(finalPath, notNull ? defaultValue : finalDeserialize(''), { notDirty: true })
39
- }
40
- $: reactToChoices(choices).catch(console.error)
41
- onMount(reactToChoices)
42
29
  </script>
43
30
 
44
- <Field {path} {defaultValue} {conditional} {notNull} {number} {date} {datetime} {boolean} {serialize} {deserialize} bind:finalDeserialize let:serialize={finalSerialize} let:value let:valid let:invalid let:onBlur let:setVal let:messages>
45
- <Switcher bind:id {path} class={className} name={finalPath} {horizontal} {label} iptValue={value} {valid} {invalid} {required} {related} {extradescid} {helptext} {messages} on:change={e => setVal(finalDeserialize(e.detail))} {onBlur} choices={choices.map(c => ({ ...c, value: finalSerialize(c.value) }))} />
31
+ <Field {path} {defaultValue} allowedValues={choices?.map(c => c.value)} {conditional} {notNull} {number} {date} {datetime} {boolean} {serialize} {deserialize} let:deserialize={finalDeserialize} let:serialize={finalSerialize} let:value let:valid let:invalid let:onBlur let:setVal let:messages>
32
+ <Switcher bind:id {path} class={className} name={finalPath} {horizontal} {label} iptValue={value} {valid} {invalid} {required} {related} {extradescid} {helptext} {messages} on:change={e => setVal(finalDeserialize(e.detail))} {onBlur} choices={choices?.map(c => ({ ...c, value: finalSerialize(c.value) })) ?? []} />
46
33
  </Field>
@@ -10,9 +10,9 @@ declare const __propDef: {
10
10
  label?: string;
11
11
  value: any;
12
12
  disabled?: boolean;
13
- }[];
13
+ }[] | undefined;
14
14
  defaultValue?: any;
15
- conditional?: boolean | undefined;
15
+ conditional?: boolean;
16
16
  required?: boolean;
17
17
  horizontal?: boolean;
18
18
  related?: true | number;
@@ -12,8 +12,8 @@
12
12
  export let placeholder: string = 'Select' + (label ? ' ' + label : '')
13
13
  export let notNull = false
14
14
  export let disabled = false
15
- export let choices: { label?: string, value: any, disabled?: boolean }[]
16
- export let defaultValue: any = notNull ? choices[0]?.value : undefined
15
+ export let choices: { label?: string, value: any, disabled?: boolean }[] | undefined
16
+ export let defaultValue: any = undefined
17
17
  export let conditional: boolean | undefined = undefined
18
18
  export let required = false
19
19
  export let inputelement: HTMLSelectElement = undefined as any
@@ -26,25 +26,9 @@
26
26
  export let boolean = false
27
27
  export let serialize: ((value: any) => string) | undefined = undefined
28
28
  export let deserialize: ((value: string) => any) | undefined = undefined
29
-
30
- const store = getContext<FormStore>(FORM_CONTEXT)
31
- const inheritedPath = getContext<string>(FORM_INHERITED_PATH)
32
- const finalPath = [inheritedPath, path].filter(isNotBlank).join('.')
33
-
34
- let finalDeserialize: (value: string) => any
35
- async function reactToChoices (..._: any[]) {
36
- if (!finalDeserialize) return
37
- if (!choices.length) {
38
- return await store.setField(finalPath, finalDeserialize(''), { notDirty: true })
39
- }
40
- const val = get($store.data, finalPath)
41
- if (!choices.some(o => equal(o.value, val))) await store.setField(finalPath, notNull ? defaultValue : finalDeserialize(''), { notDirty: true })
42
- }
43
- $: reactToChoices(choices).catch(console.error)
44
- onMount(reactToChoices)
45
29
  </script>
46
30
 
47
- <FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {related} {helptext} {notNull} {number} {date} {datetime} {boolean} {serialize} {deserialize} bind:finalDeserialize let:serialize={finalSerialize} let:value let:valid let:invalid let:id={fieldid} let:onBlur let:onChange let:messagesid let:helptextid>
31
+ <FieldStandard bind:id allowedValues={choices?.map(choice => choice.value)} {label} {path} {required} {defaultValue} {conditional} {related} {helptext} {notNull} {number} {date} {datetime} {boolean} {serialize} {deserialize} let:serialize={finalSerialize} let:value let:valid let:invalid let:id={fieldid} let:onBlur let:onChange let:messagesid let:helptextid>
48
32
  <select bind:this={inputelement} id={fieldid} 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
33
  {#if !notNull}<option value="" selected={!value}>{placeholder}</option>{/if}
50
34
  {#each choices as choice (choice.value)}
@@ -12,7 +12,7 @@ declare const __propDef: {
12
12
  label?: string;
13
13
  value: any;
14
14
  disabled?: boolean;
15
- }[];
15
+ }[] | undefined;
16
16
  defaultValue?: any;
17
17
  conditional?: boolean | undefined;
18
18
  required?: boolean;
@@ -36,9 +36,11 @@
36
36
  export let helptext: string | undefined = undefined
37
37
  export let finalSerialize: ((value: any) => string) | undefined = undefined
38
38
  export let finalDeserialize: ((value: string) => any) | undefined = undefined
39
+ export let allowedValues: any[] | undefined = undefined
40
+ export let allowedValuesMultiple = false
39
41
  </script>
40
42
 
41
- <Field {path} {defaultValue} {conditional} {notNull} {number} {date} {datetime} {boolean} {serialize} {deserialize} bind:finalSerialize bind:finalDeserialize {initialize} {finalize} let:path={fullpath} let:value let:onBlur let:onChange let:setVal let:messages let:valid let:invalid>
43
+ <Field {path} {defaultValue} {allowedValues} {allowedValuesMultiple} {conditional} {notNull} {number} {date} {datetime} {boolean} {serialize} {deserialize} bind:finalSerialize bind:finalDeserialize {initialize} {finalize} let:path={fullpath} let:value let:onBlur let:onChange let:setVal let:messages let:valid let:invalid>
42
44
  <Container path={fullpath} {id} {label} {messages} {descid} {required} {related} {helptext} let:messagesid let:helptextid>
43
45
  <slot {id} path={fullpath} {value} {onBlur} {onChange} {setVal} {valid} {invalid} {messagesid} {helptextid} serialize={finalSerialize} deserialize={finalDeserialize} />
44
46
  </Container>
@@ -22,6 +22,8 @@ declare const __propDef: {
22
22
  helptext?: string | undefined;
23
23
  finalSerialize?: ((value: any) => string) | undefined;
24
24
  finalDeserialize?: ((value: string) => any) | undefined;
25
+ allowedValues?: any[] | undefined;
26
+ allowedValuesMultiple?: boolean;
25
27
  };
26
28
  events: {
27
29
  [evt: string]: CustomEvent<any>;
@@ -19,7 +19,7 @@
19
19
  export let extradescid: string | undefined = undefined
20
20
  export let helptext: string | undefined = undefined
21
21
  export let messages: Feedback[] = []
22
- export let iptValue = choices[0].value
22
+ export let iptValue: string | undefined = undefined
23
23
  export let valid = false
24
24
  export let invalid = false
25
25
  export let onBlur: (() => void | Promise<void>) | undefined = undefined
@@ -18,7 +18,7 @@ declare const __propDef: {
18
18
  extradescid?: string | undefined;
19
19
  helptext?: string | undefined;
20
20
  messages?: Feedback[];
21
- iptValue?: string;
21
+ iptValue?: string | undefined;
22
22
  valid?: boolean;
23
23
  invalid?: boolean;
24
24
  onBlur?: (() => void | Promise<void>) | undefined;
@@ -105,6 +105,8 @@
105
105
  {/if}
106
106
  </section>
107
107
  <ChooserPreview {thumbnailExpanded} {previewId} {store} on:thumbnailsizechange={() => { thumbnailExpanded = !thumbnailExpanded }}/>
108
+ </section>
109
+ <svelte:fragment slot="buttons" let:describedby>
108
110
  {#if showAltTextOption}
109
111
  <section class="alt-text-options">
110
112
  <label>
@@ -113,8 +115,6 @@
113
115
  </label>
114
116
  </section>
115
117
  {/if}
116
- </section>
117
- <svelte:fragment slot="buttons" let:describedby>
118
118
  {#if chooserClient.upload && $source?.type === 'asset'}
119
119
  <Button class="upload" disabled={$selected?.type !== 'folder' || !(chooserClient.mayUpload?.($selected) ?? true)} on:click={() => { showuploader = true }}>Upload</Button>
120
120
  {/if}
@@ -159,6 +159,7 @@
159
159
  .alt-text-options {
160
160
  width: 100%;
161
161
  padding-block: 1em;
162
+ margin-bottom: 0.5em;
162
163
  }
163
164
  :global(footer.actions .upload) {
164
165
  margin-right: auto;
@@ -172,8 +173,5 @@
172
173
  width: 100%;
173
174
  height: 50%;
174
175
  }
175
- .alt-text-options {
176
- order: 4;
177
- }
178
176
  }
179
177
  </style>
@@ -1,7 +1,5 @@
1
1
  <script lang="ts">
2
- import { FORM_CONTEXT, FORM_INHERITED_PATH, type FormStore } from '@txstate-mws/svelte-forms'
3
- import { getContext, onMount } from 'svelte'
4
- import { get, isNotBlank, randomid, shouldUseWhiteText } from 'txstate-utils'
2
+ import { randomid, shouldUseWhiteText } from 'txstate-utils'
5
3
  import { Radio } from '..'
6
4
  import FieldStandard from '../FieldStandard.svelte'
7
5
  import type { ColorPickerOption } from './colorpicker'
@@ -15,26 +13,15 @@
15
13
  export let label = ''
16
14
  export let required = false
17
15
  export let notNull = false
18
- export let defaultValue: any = notNull ? (addAllOption ? 'alternating' : options[0].value) : undefined
16
+ export let defaultValue: any = notNull && addAllOption ? 'alternating' : undefined
19
17
  export let conditional: boolean | undefined = undefined
20
18
  export let helptext: string | undefined = undefined
21
19
  const groupid = randomid()
22
20
 
23
- const store = getContext<FormStore>(FORM_CONTEXT)
24
- const inheritedPath = getContext<string>(FORM_INHERITED_PATH)
25
- const finalPath = [inheritedPath, path].filter(isNotBlank).join('.')
26
-
27
- async function reactToOptions (..._: any[]) {
28
- const val = get($store.data, finalPath)
29
- if (!val) return
30
- if (!options.length) await store.setField(finalPath, addAllOption ? 'alternating' : undefined, { notDirty: true })
31
- else if (val !== 'alternating' && !options.some(o => o.value === val)) await store.setField(finalPath, notNull ? options[0].value : (addAllOption ? 'alternating' : undefined), { notDirty: true })
32
- }
33
- $: reactToOptions(options).catch(console.error)
34
- onMount(reactToOptions)
21
+ $: allowedValues = [...(addAllOption ? ['alternating'] : []), ...options.map(o => o.value)]
35
22
  </script>
36
23
 
37
- <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>
24
+ <FieldStandard bind:id descid={groupid} {path} {label} {required} {defaultValue} {notNull} {conditional} {helptext} {allowedValues} let:value let:valid let:invalid let:onBlur let:onChange let:messagesid let:helptextid>
38
25
  <div class="container-query-wrapper">
39
26
  <div class="color-container {className}" role="radiogroup" aria-labelledby={groupid} class:invalid class:valid>
40
27
  {#if addAllOption}
@@ -256,7 +256,7 @@
256
256
  aria-posinset={posinset}
257
257
  aria-setsize={setsize}
258
258
  aria-selected={isSelected}
259
- aria-expanded={item.hasChildren ? item.open && !!item.children && !!item.children.length : undefined}
259
+ aria-expanded={item.hasChildren ? !!item.open && !!item.children?.length : undefined}
260
260
  aria-busy={item.loading}
261
261
  on:keydown={onKeyDown}
262
262
  on:click={onClick}
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.5.6",
4
+ "version": "1.5.9",
5
5
  "scripts": {
6
6
  "prepublishOnly": "npm run package",
7
7
  "dev": "vite dev --force",
@@ -32,7 +32,7 @@
32
32
  "@iconify-icons/ph": "^1.2.2",
33
33
  "@iconify/svelte": "^4.0.0 || ^5.0.0",
34
34
  "@txstate-mws/svelte-components": "^1.6.11",
35
- "@txstate-mws/svelte-forms": "^2.0.0",
35
+ "@txstate-mws/svelte-forms": "^2.1.0",
36
36
  "@valtown/codemirror-ts": "^2.3.1",
37
37
  "codemirror": "^6.0.1",
38
38
  "cm6-graphql": "0.2.1",