@dosgato/dialog 1.2.8 → 1.3.1

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.
Files changed (58) hide show
  1. package/dist/Button.svelte +15 -13
  2. package/dist/ButtonGroup.svelte +44 -40
  3. package/dist/Checkbox.svelte +13 -12
  4. package/dist/Container.svelte +50 -46
  5. package/dist/Dialog.svelte +56 -41
  6. package/dist/FieldAutocomplete.svelte +77 -70
  7. package/dist/FieldCheckbox.svelte +25 -22
  8. package/dist/FieldChoices.svelte +74 -68
  9. package/dist/FieldChooserLink.svelte +148 -150
  10. package/dist/FieldDate.svelte +19 -18
  11. package/dist/FieldDateTime.svelte +36 -34
  12. package/dist/FieldDualListbox.svelte +80 -79
  13. package/dist/FieldHidden.svelte +16 -15
  14. package/dist/FieldIdentifier.svelte +18 -17
  15. package/dist/FieldMultiple.svelte +71 -74
  16. package/dist/FieldMultiselect.svelte +81 -72
  17. package/dist/FieldNumber.svelte +20 -19
  18. package/dist/FieldRadio.svelte +42 -41
  19. package/dist/FieldSelect.svelte +45 -45
  20. package/dist/FieldStandard.svelte +28 -27
  21. package/dist/FieldText.svelte +27 -24
  22. package/dist/FieldTextArea.svelte +24 -24
  23. package/dist/FileIcon.svelte +10 -8
  24. package/dist/Form.svelte +40 -18
  25. package/dist/Form.svelte.d.ts +15 -13
  26. package/dist/FormDialog.svelte +40 -25
  27. package/dist/FormDialog.svelte.d.ts +23 -17
  28. package/dist/Icon.svelte +38 -33
  29. package/dist/InlineMessage.svelte +31 -29
  30. package/dist/InlineMessages.svelte +10 -7
  31. package/dist/Input.svelte +40 -39
  32. package/dist/Listbox.svelte +102 -109
  33. package/dist/MaxLength.svelte +19 -18
  34. package/dist/Radio.svelte +18 -15
  35. package/dist/Switcher.svelte +37 -33
  36. package/dist/Tab.svelte +23 -21
  37. package/dist/Tabs.svelte +111 -110
  38. package/dist/Tooltip.svelte +7 -7
  39. package/dist/chooser/Chooser.svelte +83 -76
  40. package/dist/chooser/ChooserPreview.svelte +16 -14
  41. package/dist/chooser/Details.svelte +6 -4
  42. package/dist/chooser/Thumbnail.svelte +20 -16
  43. package/dist/chooser/UploadUI.svelte +78 -69
  44. package/dist/code/CodeEditor.svelte +63 -66
  45. package/dist/code/FieldCodeEditor.svelte +21 -19
  46. package/dist/colorpicker/FieldColorPicker.svelte +36 -35
  47. package/dist/cropper/FieldCropper.svelte +142 -141
  48. package/dist/iconpicker/FieldIconPicker.svelte +102 -94
  49. package/dist/imageposition/FieldImagePosition.svelte +107 -98
  50. package/dist/tagpicker/FieldTagPicker.svelte +63 -54
  51. package/dist/tree/LoadIcon.svelte +0 -1
  52. package/dist/tree/Tree.svelte +198 -192
  53. package/dist/tree/Tree.svelte.d.ts +5 -5
  54. package/dist/tree/TreeCell.svelte +10 -6
  55. package/dist/tree/TreeCell.svelte.d.ts +5 -5
  56. package/dist/tree/TreeNode.svelte +213 -241
  57. package/dist/tree/TreeNode.svelte.d.ts +5 -5
  58. package/package.json +8 -9
@@ -4,76 +4,83 @@
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, onMount } from 'svelte';
8
- import { Field, FORM_CONTEXT, arraySerialize, FORM_INHERITED_PATH } from '@txstate-mws/svelte-forms';
9
- import { derivedStore } from '@txstate-mws/svelte-store';
10
- import { get, isNotBlank, randomid } from 'txstate-utils';
11
- import Container from './Container.svelte';
12
- import Checkbox from './Checkbox.svelte';
13
- import { getDescribedBy } from './helpers';
14
- let className = '';
15
- export { className as class };
16
- export let id = undefined;
17
- export let path;
18
- export let label = '';
19
- export let choices;
20
- export let defaultValue = [];
21
- export let conditional = undefined;
22
- export let maxwidth = 250;
23
- export let leftToRight = false;
24
- export let related = 0;
25
- export let extradescid = undefined;
26
- export let helptext = undefined;
27
- export let selectAll = false;
28
- const store = getContext(FORM_CONTEXT);
29
- const inheritedPath = getContext(FORM_INHERITED_PATH);
30
- const finalPath = [inheritedPath, path].filter(isNotBlank).join('.');
31
- const valStore = store.getField(finalPath);
32
- const currentWidth = derivedStore(store, 'width');
33
- $: cols = Math.min(Math.ceil($currentWidth / maxwidth), choices.length);
34
- let orders;
35
- let width = '100%';
36
- function redoLayout(..._) {
37
- width = `${100 / cols}%`;
38
- const rows = Math.ceil(choices.length / cols);
39
- orders = choices.map((_, i) => leftToRight ? i : Math.floor((i + 1) / cols) + rows * (i % cols));
40
- }
41
- $: redoLayout(choices, cols);
42
- function onChangeCheckbox(setVal, choice, included) {
7
+ <script lang="ts">
8
+ import { getContext, onMount } from 'svelte'
9
+ import { Field, FORM_CONTEXT, arraySerialize, FORM_INHERITED_PATH } from '@txstate-mws/svelte-forms'
10
+ import type { FormStore } from '@txstate-mws/svelte-forms'
11
+ import { derivedStore } from '@txstate-mws/svelte-store'
12
+ import { get, isNotBlank, randomid } from 'txstate-utils'
13
+ import Container from './Container.svelte'
14
+ import Checkbox from './Checkbox.svelte'
15
+ import { getDescribedBy } from './helpers'
16
+
17
+ let className = ''
18
+ export { className as class }
19
+ export let id: string | undefined = undefined
20
+ export let path: string
21
+ export let label: string = ''
22
+ export let choices: { label?: string, value: any, disabled?: boolean }[]
23
+ export let defaultValue: any = []
24
+ export let conditional: boolean | undefined = undefined
25
+ export let maxwidth = 250
26
+ export let leftToRight = false
27
+ export let related: true | number = 0
28
+ export let extradescid: string | undefined = undefined
29
+ export let helptext: string | undefined = undefined
30
+ export let selectAll: boolean = false
31
+
32
+ const store = getContext<FormStore>(FORM_CONTEXT)
33
+ const inheritedPath = getContext<string>(FORM_INHERITED_PATH)
34
+ const finalPath = [inheritedPath, path].filter(isNotBlank).join('.')
35
+ const valStore = store.getField<any[]>(finalPath)
36
+ const currentWidth = derivedStore(store, 'width')
37
+ $: cols = Math.min(Math.ceil($currentWidth / maxwidth), choices.length)
38
+
39
+ let orders: number[]
40
+ let width = '100%'
41
+ function redoLayout (..._: any) {
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))
45
+ }
46
+ $: redoLayout(choices, cols)
47
+
48
+ function onChangeCheckbox (setVal: (val: any) => void, choice: typeof choices[number], included: boolean) {
43
49
  setVal(v => {
44
- if (v == null)
45
- return included ? [] : [choice.value];
46
- if (included)
47
- return v.filter(s => s !== choice.value);
48
- else
49
- return [...v, choice.value];
50
- });
51
- }
52
- $: selected = new Set($valStore ?? []);
53
- let selectAllElement;
54
- const selectAllId = randomid();
55
- $: selectAllChecked = choices.every(choice => choice.disabled || selected.has(choice.value));
56
- function selectAllChanged() {
50
+ if (v == null) return included ? [] : [choice.value]
51
+ if (included) return v.filter(s => s !== choice.value)
52
+ else return [...v, choice.value]
53
+ })
54
+ }
55
+
56
+ $: selected = new Set($valStore ?? [])
57
+
58
+ let selectAllElement: HTMLInputElement | undefined
59
+ const selectAllId = randomid()
60
+
61
+ $: selectAllChecked = choices.every(choice => choice.disabled || selected.has(choice.value))
62
+
63
+ function selectAllChanged () {
57
64
  if (selectAllChecked) {
58
- // it was checked and is now unchecked, clear it out
59
- void store.setField(finalPath, []);
65
+ // it was checked and is now unchecked, clear it out
66
+ void store.setField(finalPath, [])
67
+ } else {
68
+ // it was not checked and now it is checked
69
+ void store.setField(finalPath, choices.filter(choice => !choice.disabled).map(choice => choice.value))
60
70
  }
61
- else {
62
- // it was not checked and now it is checked
63
- void store.setField(finalPath, choices.filter(choice => !choice.disabled).map(choice => choice.value));
64
- }
65
- }
66
- const descid = randomid();
67
- function reactToChoices(..._) {
68
- const choiceSet = new Set(choices?.filter(c => !c.disabled).map(c => c.value));
69
- selected = new Set(Array.from(selected).filter(v => choiceSet.has(v)));
70
- const val = get($store.data, finalPath);
71
- const filtered = val?.filter(v => choiceSet.has(v));
72
- if (filtered?.length !== val?.length)
73
- store.setField(finalPath, filtered).catch(console.error);
74
- }
75
- $: reactToChoices(choices);
76
- onMount(reactToChoices);
71
+ }
72
+
73
+ const descid = randomid()
74
+
75
+ function reactToChoices (..._: any[]) {
76
+ const choiceSet = new Set(choices?.filter(c => !c.disabled).map(c => c.value))
77
+ selected = new Set(Array.from(selected).filter(v => choiceSet.has(v)))
78
+ const val = get($store.data, finalPath)
79
+ const filtered = val?.filter(v => choiceSet.has(v))
80
+ if (filtered?.length !== val?.length) store.setField(finalPath, filtered).catch(console.error)
81
+ }
82
+ $: reactToChoices(choices)
83
+ onMount(reactToChoices)
77
84
  </script>
78
85
 
79
86
  <Field {path} {defaultValue} {conditional} let:path let:value let:onBlur let:setVal let:messages let:valid let:invalid serialize={arraySerialize}>
@@ -116,5 +123,4 @@ onMount(reactToChoices);
116
123
  label :global(input[type="checkbox"]) {
117
124
  transform: none;
118
125
  }
119
-
120
126
  </style>
@@ -1,165 +1,164 @@
1
- <script>import arrowClockwiseFill from '@iconify-icons/ph/arrow-clockwise-fill';
2
- import deleteOutline from '@iconify-icons/mdi/delete-outline';
3
- import xCircle from '@iconify-icons/ph/x-circle';
4
- import { FORM_CONTEXT, FORM_INHERITED_PATH } from '@txstate-mws/svelte-forms';
5
- import { getContext } from 'svelte';
6
- import { isBlank, isNotBlank, randomid } from 'txstate-utils';
7
- import { Chooser, ChooserStore, CHOOSER_API_CONTEXT, cleanUrl } from './chooser';
8
- import Details from './chooser/Details.svelte';
9
- import Thumbnail from './chooser/Thumbnail.svelte';
10
- import { getDescribedBy, FieldStandard, InlineMessage, Icon } from './';
11
- export let id = undefined;
12
- export let path;
13
- export let label = '';
14
- export let defaultValue = undefined;
15
- export let conditional = undefined;
16
- export let required = false;
17
- export let images = false;
18
- export let pages = false;
19
- export let assets = images;
20
- export let folders = false;
21
- export let urlEntry = false;
22
- export let initialSource = undefined;
23
- export let initialPath = undefined;
24
- export let related = 0;
25
- export let extradescid = undefined;
26
- export let helptext = undefined;
27
- export let selectedAsset = undefined;
28
- // TODO: add a mime type acceptance prop, maybe a regex or function, to prevent users from
29
- // choosing unacceptable mime types
30
- const formStore = getContext(FORM_CONTEXT);
31
- const inheritedPath = getContext(FORM_INHERITED_PATH);
32
- const finalPath = [inheritedPath, path].filter(isNotBlank).join('.');
33
- const value = formStore.getField(finalPath);
34
- const chooserClient = getContext(CHOOSER_API_CONTEXT);
35
- const store = new ChooserStore(chooserClient);
36
- let urlEntryInput;
37
- const descid = randomid();
38
- let modalshown = false;
39
- async function show() {
40
- if (selectedAsset && selectedAsset.type !== 'raw' && selectedAsset.type !== 'broken')
41
- store.setPreview(selectedAsset);
42
- modalshown = true;
43
- }
44
- function hide() {
45
- modalshown = false;
46
- }
47
- function onChange(setVal) {
1
+ <script lang="ts">
2
+ import arrowClockwiseFill from '@iconify-icons/ph/arrow-clockwise-fill'
3
+ import deleteOutline from '@iconify-icons/mdi/delete-outline'
4
+ import xCircle from '@iconify-icons/ph/x-circle'
5
+ import { FORM_CONTEXT, FORM_INHERITED_PATH, type FormStore } from '@txstate-mws/svelte-forms'
6
+ import { getContext } from 'svelte'
7
+ import { isBlank, isNotBlank, randomid } from 'txstate-utils'
8
+ import { Chooser, ChooserStore, CHOOSER_API_CONTEXT, cleanUrl, type BrokenURL, type RawURL } from './chooser'
9
+ import type { AnyItem, Client } from './chooser/ChooserAPI'
10
+ import Details from './chooser/Details.svelte'
11
+ import Thumbnail from './chooser/Thumbnail.svelte'
12
+ import { getDescribedBy, FieldStandard, InlineMessage, Icon } from './'
13
+
14
+ export let id: string | undefined = undefined
15
+ export let path: string
16
+ export let label: string = ''
17
+ export let defaultValue: boolean | undefined = undefined
18
+ export let conditional: boolean | undefined = undefined
19
+ export let required = false
20
+ export let images = false
21
+ export let pages = false
22
+ export let assets = images
23
+ export let folders = false
24
+ export let urlEntry = false
25
+ export let initialSource: string | undefined = undefined
26
+ export let initialPath: string | undefined = undefined
27
+ export let related: true | number = 0
28
+ export let extradescid: string | undefined = undefined
29
+ export let helptext: string | undefined = undefined
30
+ export let selectedAsset: AnyItem | RawURL | BrokenURL | undefined = undefined
31
+
32
+ // TODO: add a mime type acceptance prop, maybe a regex or function, to prevent users from
33
+ // choosing unacceptable mime types
34
+
35
+ const formStore = getContext<FormStore>(FORM_CONTEXT)
36
+ const inheritedPath = getContext<string>(FORM_INHERITED_PATH)
37
+ const finalPath = [inheritedPath, path].filter(isNotBlank).join('.')
38
+ const value = formStore.getField<string>(finalPath)
39
+ const chooserClient = getContext<Client>(CHOOSER_API_CONTEXT)
40
+ const store = new ChooserStore(chooserClient)
41
+ let urlEntryInput: HTMLInputElement | undefined
42
+
43
+ const descid = randomid()
44
+ let modalshown = false
45
+ async function show () {
46
+ if (selectedAsset && selectedAsset.type !== 'raw' && selectedAsset.type !== 'broken') store.setPreview(selectedAsset)
47
+ modalshown = true
48
+ }
49
+ function hide () {
50
+ modalshown = false
51
+ }
52
+ function onChange (setVal: any) {
48
53
  return (e) => {
49
- selectedAsset = e.detail;
50
- setVal(selectedAsset?.id);
51
- hide();
52
- };
53
- }
54
- function clearUrlEntry() {
55
- urlEntryInput.value = '';
56
- urlEntryInput.dispatchEvent(new InputEvent('input'));
57
- }
58
- let timer;
59
- function userUrlEntry() {
60
- clearTimeout(timer);
61
- timer = setTimeout(userUrlEntryDebounced.bind(this), 300);
62
- }
63
- async function userUrlEntryDebounced() {
64
- const url = this.value;
65
- const cleanedUrl = cleanUrl(url);
66
- store.clearPreview();
54
+ selectedAsset = e.detail
55
+ setVal(selectedAsset?.id)
56
+ hide()
57
+ }
58
+ }
59
+ function clearUrlEntry () {
60
+ urlEntryInput!.value = ''
61
+ urlEntryInput!.dispatchEvent(new InputEvent('input'))
62
+ }
63
+
64
+ let timer: ReturnType<typeof setTimeout>
65
+ function userUrlEntry () {
66
+ clearTimeout(timer)
67
+ timer = setTimeout(userUrlEntryDebounced.bind(this), 300)
68
+ }
69
+
70
+ async function userUrlEntryDebounced () {
71
+ const url = this.value
72
+ const cleanedUrl = cleanUrl(url)
73
+ store.clearPreview()
67
74
  if (isBlank(url)) {
68
- selectedAsset = undefined;
69
- void formStore.setField(finalPath, undefined);
70
- return;
75
+ selectedAsset = undefined
76
+ void formStore.setField(finalPath, undefined)
77
+ return
71
78
  }
72
- let found = false;
79
+ let found = false
73
80
  if (chooserClient.findByUrl) {
74
- let item = await chooserClient.findByUrl(url);
75
- if (!item && isNotBlank(cleanedUrl))
76
- item = await chooserClient.findByUrl(cleanedUrl);
77
- if (url !== this.value)
78
- return;
79
- if (item) {
80
- found = true;
81
- if ((item.type === 'page' && !pages) || // they typed the URL for a page but we don't allow pages right now
82
- (item.type === 'folder' && !folders) || // they typed the URL for an asset folder but not allowed
83
- (item.type === 'asset' && !assets) || // they typed the URL for an asset but not allowed
84
- (item.type === 'asset' && !item.image && images) // they typed the URL for a non-image asset but we only want images
85
- ) {
86
- // they entered something that is recognized but not allowed
87
- // they can keep the typing they've done, but the id must be 'undefined' so that nothing
88
- // is entered into the form data
89
- selectedAsset = {
90
- type: 'raw',
91
- id: undefined,
92
- url
93
- };
94
- }
95
- else {
96
- selectedAsset = { ...item, url };
97
- }
81
+ let item = await chooserClient.findByUrl(url)
82
+ if (!item && isNotBlank(cleanedUrl)) item = await chooserClient.findByUrl(cleanedUrl)
83
+ if (url !== this.value) return
84
+ if (item) {
85
+ found = true
86
+ if (
87
+ (item.type === 'page' && !pages) || // they typed the URL for a page but we don't allow pages right now
88
+ (item.type === 'folder' && !folders) || // they typed the URL for an asset folder but not allowed
89
+ (item.type === 'asset' && !assets) || // they typed the URL for an asset but not allowed
90
+ (item.type === 'asset' && !item.image && images) // they typed the URL for a non-image asset but we only want images
91
+ ) {
92
+ // they entered something that is recognized but not allowed
93
+ // they can keep the typing they've done, but the id must be 'undefined' so that nothing
94
+ // is entered into the form data
95
+ selectedAsset = {
96
+ type: 'raw',
97
+ id: undefined,
98
+ url
99
+ }
100
+ } else {
101
+ selectedAsset = { ...item, url } as any
98
102
  }
103
+ }
99
104
  }
100
105
  if (!found) {
101
- if (urlToValueCache[url]) {
102
- selectedAsset = { type: 'raw', id: urlToValueCache[url], url };
103
- }
104
- else {
105
- if (isBlank(cleanedUrl) || cleanedUrl.startsWith('/')) {
106
- // here we "select" a raw url so that we do not interrupt the users' typing, but
107
- // we set its id to 'undefined' so that nothing makes it into the form until it's
108
- // a valid URL
109
- selectedAsset = { type: 'raw', id: undefined, url };
110
- }
111
- else {
112
- selectedAsset = {
113
- type: 'raw',
114
- id: chooserClient.urlToValue?.(cleanedUrl) ?? cleanedUrl,
115
- url
116
- };
117
- }
106
+ if (urlToValueCache[url]) {
107
+ selectedAsset = { type: 'raw', id: urlToValueCache[url], url }
108
+ } else {
109
+ if (isBlank(cleanedUrl) || cleanedUrl.startsWith('/')) {
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
+ } else {
115
+ selectedAsset = {
116
+ type: 'raw',
117
+ id: chooserClient.urlToValue?.(cleanedUrl) ?? cleanedUrl,
118
+ url
119
+ }
118
120
  }
121
+ }
119
122
  }
120
- void formStore.setField(finalPath, selectedAsset?.id);
121
- formStore.dirtyField(finalPath);
122
- }
123
- const urlToValueCache = {};
124
- async function updateSelected(..._) {
123
+ void formStore.setField(finalPath, selectedAsset?.id)
124
+ }
125
+
126
+ const urlToValueCache: Record<string, string> = {}
127
+ async function updateSelected (..._: any) {
125
128
  if (selectedAsset?.id !== $value) {
126
- if (!$value) {
127
- selectedAsset = undefined;
128
- return;
129
- }
130
- const valueBeforeFind = $value;
131
- const asset = await chooserClient.findById($value);
132
- if ($value !== valueBeforeFind)
133
- return;
134
- selectedAsset = asset;
135
- try {
136
- if (!selectedAsset) {
137
- const urlFromValue = chooserClient.valueToUrl?.($value) ?? $value;
138
- const cleanedUrlFromValue = cleanUrl(urlFromValue);
139
- if (isBlank(cleanedUrlFromValue)) {
140
- selectedAsset = undefined;
141
- }
142
- else if (cleanedUrlFromValue.startsWith('/')) {
143
- selectedAsset = { type: 'broken', id: $value, url: cleanedUrlFromValue };
144
- }
145
- else {
146
- selectedAsset = { type: 'raw', id: $value, url: cleanedUrlFromValue };
147
- }
148
- }
149
- if (selectedAsset) {
150
- urlToValueCache[selectedAsset.url] = $value;
151
- if (selectedAsset.type !== 'raw' && selectedAsset.type !== 'broken') {
152
- initialPath = selectedAsset.path ?? initialPath;
153
- initialSource = selectedAsset.source ?? initialSource;
154
- }
155
- }
129
+ if (!$value) {
130
+ selectedAsset = undefined
131
+ return
132
+ }
133
+ const valueBeforeFind = $value
134
+ const asset = await chooserClient.findById($value)
135
+ if ($value !== valueBeforeFind) return
136
+ selectedAsset = asset
137
+ try {
138
+ if (!selectedAsset) {
139
+ const urlFromValue = chooserClient.valueToUrl?.($value) ?? $value
140
+ const cleanedUrlFromValue = cleanUrl(urlFromValue)
141
+ if (isBlank(cleanedUrlFromValue)) {
142
+ selectedAsset = undefined
143
+ } else if (cleanedUrlFromValue.startsWith('/')) {
144
+ selectedAsset = { type: 'broken', id: $value, url: cleanedUrlFromValue }
145
+ } else {
146
+ selectedAsset = { type: 'raw', id: $value, url: cleanedUrlFromValue }
147
+ }
156
148
  }
157
- catch (e) {
158
- console.error(e);
149
+ if (selectedAsset) {
150
+ urlToValueCache[selectedAsset.url] = $value
151
+ if (selectedAsset.type !== 'raw' && selectedAsset.type !== 'broken') {
152
+ initialPath = selectedAsset.path ?? initialPath
153
+ initialSource = selectedAsset.source ?? initialSource
154
+ }
159
155
  }
156
+ } catch (e: any) {
157
+ console.error(e)
158
+ }
160
159
  }
161
- }
162
- $: void updateSelected($value);
160
+ }
161
+ $: void updateSelected($value)
163
162
  </script>
164
163
 
165
164
  <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>
@@ -282,5 +281,4 @@ $: void updateSelected($value);
282
281
  :global([data-eq~="400px"] .dialog-chooser-container .dialog-chooser-thumbnail img) {
283
282
  object-position: left;
284
283
  }
285
-
286
284
  </style>
@@ -1,21 +1,22 @@
1
- <script>import { dateSerialize, dateDeserialize } from '@txstate-mws/svelte-forms';
2
- import FieldStandard from './FieldStandard.svelte';
3
- import Input from './Input.svelte';
4
- let className = '';
5
- export { className as class };
6
- export let id = undefined;
7
- export let path;
8
- export let label = '';
9
- export let defaultValue = undefined;
10
- export let min = undefined;
11
- export let max = undefined;
12
- export let step = undefined;
13
- export let conditional = undefined;
14
- export let required = false;
15
- export let inputelement = undefined;
16
- export let related = 0;
17
- export let extradescid = undefined;
18
- export let helptext = undefined;
1
+ <script lang="ts">
2
+ import { dateSerialize, dateDeserialize } from '@txstate-mws/svelte-forms'
3
+ import FieldStandard from './FieldStandard.svelte'
4
+ import Input from './Input.svelte'
5
+ let className = ''
6
+ export { className as class }
7
+ export let id: string | undefined = undefined
8
+ export let path: string
9
+ export let label: string = ''
10
+ export let defaultValue: any = undefined
11
+ export let min: Date | { toJSDate: () => Date } | undefined = undefined
12
+ export let max: Date | { toJSDate: () => Date } | undefined = undefined
13
+ export let step: number | undefined = undefined
14
+ export let conditional: boolean | undefined = undefined
15
+ export let required = false
16
+ export let inputelement: HTMLInputElement = undefined as any
17
+ export let related: true | number = 0
18
+ export let extradescid: string | undefined = undefined
19
+ export let helptext: string | undefined = undefined
19
20
  </script>
20
21
 
21
22
  <FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {related} {helptext} serialize={dateSerialize} deserialize={dateDeserialize} let:value let:valid let:invalid let:id let:onBlur let:onChange let:messagesid let:helptextid>
@@ -1,39 +1,41 @@
1
- <script>import { datetimeSerialize, datetimeDeserialize } from '@txstate-mws/svelte-forms';
2
- import FieldStandard from './FieldStandard.svelte';
3
- import Input from './Input.svelte';
4
- import { createEventDispatcher } from 'svelte';
5
- let className = '';
6
- export { className as class };
7
- export let id = undefined;
8
- export let path;
9
- export let label = '';
10
- export let defaultValue = undefined;
11
- export let min = undefined;
12
- export let max = undefined;
13
- export let step = undefined;
14
- export let conditional = undefined;
15
- export let required = false;
16
- export let related = 0;
17
- export let extradescid = undefined;
18
- export let helptext = undefined;
19
- export let inputelement = undefined;
20
- const dispatch = createEventDispatcher();
21
- function onChange(setVal) {
1
+ <script lang="ts">
2
+ import { datetimeSerialize, datetimeDeserialize } from '@txstate-mws/svelte-forms'
3
+ import FieldStandard from './FieldStandard.svelte'
4
+ import Input from './Input.svelte'
5
+ import { createEventDispatcher } from 'svelte'
6
+ let className = ''
7
+ export { className as class }
8
+ export let id: string | undefined = undefined
9
+ export let path: string
10
+ export let label: string = ''
11
+ export let defaultValue: any = undefined
12
+ export let min: Date | { toJSDate: () => Date } | undefined = undefined
13
+ export let max: Date | { toJSDate: () => Date } | undefined = undefined
14
+ export let step: number | undefined = undefined
15
+ export let conditional: boolean | undefined = undefined
16
+ export let required = false
17
+ export let related: true | number = 0
18
+ export let extradescid: string | undefined = undefined
19
+ export let helptext: string | undefined = undefined
20
+ export let inputelement: HTMLInputElement = undefined!
21
+
22
+ const dispatch = createEventDispatcher()
23
+
24
+ function onChange (setVal) {
22
25
  return () => {
23
- if (inputelement) {
24
- const date = new Date(inputelement.value);
25
- const invalid = inputelement.validity.badInput || !(date instanceof Date && !isNaN(date.valueOf()));
26
- if (invalid) {
27
- setVal(undefined);
28
- dispatch('change', undefined);
29
- }
30
- else {
31
- setVal(datetimeDeserialize(inputelement.value));
32
- dispatch('change', datetimeDeserialize(inputelement.value));
33
- }
26
+ if (inputelement) {
27
+ const date = new Date(inputelement.value)
28
+ const invalid = inputelement.validity.badInput || !(date instanceof Date && !isNaN(date.valueOf()))
29
+ if (invalid) {
30
+ setVal(undefined)
31
+ dispatch('change', undefined)
32
+ } else {
33
+ setVal(datetimeDeserialize(inputelement.value))
34
+ dispatch('change', datetimeDeserialize(inputelement.value))
34
35
  }
35
- };
36
- }
36
+ }
37
+ }
38
+ }
37
39
  </script>
38
40
 
39
41
  <FieldStandard bind:id {label} {path} {required} {defaultValue} {conditional} {related} {helptext} serialize={datetimeSerialize} deserialize={datetimeDeserialize} let:value let:valid let:invalid let:id let:onBlur let:helptextid let:messagesid let:setVal>