sveltacular 0.0.52 → 0.0.53
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.
|
@@ -1,17 +1,26 @@
|
|
|
1
|
-
<script>import { currentDateTime } from "../../helpers/date.js";
|
|
1
|
+
<script>import { currentDateTime, isDate, isDateOrDateTime, isDateTime } from "../../helpers/date.js";
|
|
2
2
|
import { uniqueId } from "../../helpers/unique-id.js";
|
|
3
3
|
import FormField from "../form-field.svelte";
|
|
4
4
|
import FormLabel from "../form-label.svelte";
|
|
5
5
|
const id = uniqueId();
|
|
6
6
|
export let value = void 0;
|
|
7
|
+
export let defaultValue = void 0;
|
|
7
8
|
export let size = "full";
|
|
8
9
|
export let placeholder = "";
|
|
9
10
|
export let nullable = false;
|
|
10
11
|
export let enabled = true;
|
|
11
12
|
export let type = "date";
|
|
12
13
|
export let required = false;
|
|
13
|
-
const
|
|
14
|
-
const getDefaultValue = () =>
|
|
14
|
+
const _defaultValue = defaultValue !== void 0 ? defaultValue : value || currentDateTime();
|
|
15
|
+
const getDefaultValue = () => {
|
|
16
|
+
if (nullable && !isDateOrDateTime(String(_defaultValue))) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (type === "date") {
|
|
20
|
+
return isDate(String(_defaultValue)) ? _defaultValue : currentDateTime().substring(0, 10);
|
|
21
|
+
}
|
|
22
|
+
return isDateTime(String(_defaultValue)) ? _defaultValue : currentDateTime();
|
|
23
|
+
};
|
|
15
24
|
const checkChanged = () => {
|
|
16
25
|
if (nullable) {
|
|
17
26
|
value = enabled ? getDefaultValue() : "";
|
|
@@ -3,6 +3,7 @@ import type { FormFieldSizeOptions } from '../../index.js';
|
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: {
|
|
5
5
|
value?: string | undefined | null;
|
|
6
|
+
defaultValue?: string | undefined | null;
|
|
6
7
|
size?: FormFieldSizeOptions | undefined;
|
|
7
8
|
placeholder?: string | undefined;
|
|
8
9
|
nullable?: boolean | undefined;
|
package/dist/helpers/date.d.ts
CHANGED
|
@@ -12,3 +12,6 @@ export declare const dateTimeFromSupabase: (dateTime: string | null) => string;
|
|
|
12
12
|
export declare const dateTimeToSupabase: (dateTime: string) => string | null;
|
|
13
13
|
export declare const dateTimeToHuman: (dateTime: string) => string;
|
|
14
14
|
export declare const dateTimeToInput: (dateTime?: Date) => string;
|
|
15
|
+
export declare const isDate: (date: string) => boolean;
|
|
16
|
+
export declare const isDateTime: (dateTime: string) => boolean;
|
|
17
|
+
export declare const isDateOrDateTime: (dateOrDateTime: string) => boolean;
|
package/dist/helpers/date.js
CHANGED
|
@@ -66,3 +66,14 @@ export const dateTimeToInput = (dateTime) => {
|
|
|
66
66
|
dateTime.setMinutes(dateTime.getMinutes() - offset);
|
|
67
67
|
return dateTime.toISOString().split('.')[0].slice(0, -3);
|
|
68
68
|
};
|
|
69
|
+
// Is this date formatted in YYYY-MM-DD format?
|
|
70
|
+
export const isDate = (date) => {
|
|
71
|
+
return /^\d{4}-\d{2}-\d{2}$/.test(date);
|
|
72
|
+
};
|
|
73
|
+
// Is this datetime formatted in YYYY-MM-DD HH:MM format?
|
|
74
|
+
export const isDateTime = (dateTime) => {
|
|
75
|
+
return /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?$/.test(dateTime);
|
|
76
|
+
};
|
|
77
|
+
export const isDateOrDateTime = (dateOrDateTime) => {
|
|
78
|
+
return isDate(dateOrDateTime) || isDateTime(dateOrDateTime);
|
|
79
|
+
};
|