This repository was archived by the owner on Jul 18, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +84
-12
lines changed
views/Table/components/DataGrid/GridCell Expand file tree Collapse file tree 7 files changed +84
-12
lines changed Original file line number Diff line number Diff line change 1111 NumberInput ,
1212 ColorInput ,
1313 Checkbox ,
14- DateInput ,
14+ // DateInput,
1515 // DatetimeInput,
1616 } from " obsidian-svelte" ;
17+ import DateInput from " src/ui/components/DateInput.svelte" ;
1718 import DatetimeInput from " src/ui/components/DatetimeInput.svelte" ;
1819 import { TagsInput } from " src/ui/components/TagsInput" ;
1920 import HorizontalGroup from " src/ui/components/HorizontalGroup/HorizontalGroup.svelte" ;
Original file line number Diff line number Diff line change 99 TextInput ,
1010 NumberInput ,
1111 Checkbox ,
12- DateInput ,
12+ // DateInput,
1313 // DatetimeInput,
1414 } from " obsidian-svelte" ;
15+ import DateInput from " src/ui/components/DateInput.svelte" ;
1516 import DatetimeInput from " src/ui/components/DatetimeInput.svelte" ;
1617 import { TagsInput } from " src/ui/components/TagsInput" ;
1718 import HorizontalGroup from " src/ui/components/HorizontalGroup/HorizontalGroup.svelte" ;
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import { createEventDispatcher } from " svelte" ;
3+ import dayjs from " dayjs" ;
4+
5+ /**
6+ * Specifies the date value.
7+ */
8+ export let value: Date | null ;
9+
10+ /**
11+ * Specifies whether to remove decorations so that it can be embedded in other
12+ * components.
13+ */
14+ export let embed: boolean = false ;
15+
16+ const dispatch = createEventDispatcher <{
17+ change: Date | null ;
18+ input: Date | null ;
19+ }>();
20+
21+ function handleChange(event : Event ) {
22+ if (event .currentTarget instanceof HTMLInputElement ) {
23+ dispatch (
24+ " change" ,
25+ event .currentTarget .value
26+ ? dayjs (event .currentTarget .value ).toDate ()
27+ : null
28+ );
29+ }
30+ }
31+
32+ function handleInput(event : Event ) {
33+ if (event .currentTarget instanceof HTMLInputElement ) {
34+ dispatch (
35+ " input" ,
36+ event .currentTarget .value
37+ ? dayjs (event .currentTarget .value ).toDate ()
38+ : null
39+ );
40+ }
41+ }
42+ </script >
43+
44+ <input
45+ type =" date"
46+ class:embed
47+ value ={value ? dayjs (value ).format (" YYYY-MM-DD" ) : null }
48+ max =" 9999-12-31"
49+ on:change ={handleChange }
50+ on:input ={handleInput }
51+ on:blur
52+ />
53+
54+ <style >
55+ input {
56+ border-radius : 9999px ;
57+ border : 0 ;
58+ background-color : var (--background-modifier-hover );
59+ font-family : var (--font-default );
60+ padding-left : var (--size-4-6 );
61+ }
62+
63+ .embed {
64+ margin : 0 8px ;
65+ }
66+ </style >
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import {
33 Autocomplete ,
4- DateInput ,
4+ // DateInput,
55 // DatetimeInput,
66 NumberInput ,
77 Switch ,
88 TextInput ,
99 } from " obsidian-svelte" ;
10+ import DateInput from " ../DateInput.svelte" ;
1011 import DatetimeInput from " ../DatetimeInput.svelte" ;
1112 import dayjs from " dayjs" ;
1213
7576 value ={isDate (value ) ? value : null }
7677 on:change ={({ detail : value }) => (cachedValue = value )}
7778 on:blur ={() => {
78- if (! cachedValue ) {
79+ if (! cachedValue || ! isDate ( value ) ) {
7980 onChange (cachedValue );
8081 return ;
8182 }
8283 const cachedDate = dayjs (cachedValue );
83- const newDatetime = dayjs (isDate ( value ) ? value : null )
84+ const newDatetime = dayjs (value )
8485 .set (" year" , cachedDate .year ())
8586 .set (" month" , cachedDate .month ())
8687 .set (" date" , cachedDate .date ());
Original file line number Diff line number Diff line change 88 SettingItem ,
99 TextInput ,
1010 NumberInput ,
11- DateInput ,
11+ // DateInput,
1212 // DatetimeInput,
1313 Switch ,
1414 } from " obsidian-svelte" ;
2323 } from " src/lib/dataframe/dataframe" ;
2424 import { i18n } from " src/lib/stores/i18n" ;
2525 import { onMount } from " svelte" ;
26+ import DateInput from " src/ui/components/DateInput.svelte" ;
2627 import DatetimeInput from " src/ui/components/DatetimeInput.svelte" ;
2728
2829 export let existingFields: DataField [];
Original file line number Diff line number Diff line change 11<script lang =" ts" >
2- import { DateInput } from " obsidian-svelte" ;
2+ // import { DateInput } from "obsidian-svelte";
3+ import { isDate } from " src/lib/dataframe/dataframe" ;
4+ import DateInput from " src/ui/components/DateInput.svelte" ;
35 import type { Optional } from " src/lib/dataframe/dataframe" ;
46 import dayjs from " dayjs" ;
57
5456 </svelte:fragment >
5557 <svelte:fragment slot =" edit" >
5658 <DateInput
57- value ={value != undefined ? value : null }
58- on:change ={({ detail : value }) => (cachedValue = value )}
59+ value ={value ?? null }
60+ on:change ={({ detail }) => (cachedValue = detail )}
5961 on:blur ={() => {
6062 edit = false ;
61- if (! cachedValue ) {
63+ if (! cachedValue || ! isDate ( value ) ) {
6264 onChange (cachedValue );
6365 return ;
6466 }
Original file line number Diff line number Diff line change 6060 </svelte:fragment >
6161 <svelte:fragment slot =" edit" >
6262 <DatetimeInput
63- value ={value != undefined ? value : null }
64- on:input ={({ detail : value }) => (cachedValue = value )}
63+ value ={value ?? null }
64+ on:input ={({ detail }) => (cachedValue = detail )}
6565 on:blur ={() => {
6666 edit = false ;
6767 onChange (cachedValue );
You can’t perform that action at this time.
0 commit comments