-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.view.ts
More file actions
243 lines (185 loc) · 5.73 KB
/
notes.view.ts
File metadata and controls
243 lines (185 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
namespace $.$$ {
export class $hyoo_notes extends $.$hyoo_notes {
pages() {
return [
this.Tagging_page(),
this.Notes_page( this.tag() ),
... this.note() ? [ this.Note_page( this.note() ) ] : [],
]
}
@ $mol_mem_key
note_reminder( note: string ) {
const moment = this.note_moment( note )
if( !moment ) return null
const duration = new $mol_time_interval({
start: new $mol_time_moment,
end: moment,
}).duration
const ms = duration.valueOf()
if( ms < 0 ) return null
this.$.$mol_state_time.now( 1000 * 60 * 60 * 24 )
const days = duration.count( 'P1D' )
if( days > 30 ) return null
this.$.$mol_notify.allowed( true )
return new $mol_after_timeout( ms, ()=> {
this.$.$mol_notify.show({
context: this.note_title( note ),
message: moment.toString( 'YYYY-MM-DD hh:mm' ),
uri: this.$.$mol_state_arg.make_link({ note })
})
} )
}
@ $mol_mem
reminders() {
this.note_ids().map( id => this.note_reminder( id ) )
return null
}
note_ids( next? : string[] ) {
return this.$.$mol_state_local.value( 'note_ids' , next ) || []
}
note_tags( id : string , next? : string[] | null ) {
return this.$.$mol_state_local.value( `note=${id}.tags` , next ) || []
}
note( next? : string | null ) {
return this.$.$mol_state_arg.value( 'note' , next )
}
note_content( note : string , next? : string | null ) {
if( next ) this.note_ids([ note , ... this.note_ids().filter( id => id !== note ) ])
return this.$.$mol_state_local.value( `note=${ note }.content` , next ) || ''
}
note_current_content( next? : string ) {
return this.note_content( this.note()! , next )
}
@ $mol_mem_key
note_moment( note : string , next? : $mol_time_moment ) {
const str = this.$.$mol_state_local.value( `note=${ note }.moment` , next && next.toString() ) || null
return str ? new $mol_time_moment( str ) : null!
}
@ $mol_mem_key
note_moment_view( note: string ) {
return this.note_moment( note )?.toString( 'MM-DD hh:mm' ) ?? ''
}
note_current_moment( next? : $mol_time_moment ) {
return this.note_moment( this.note()! , next )
}
tag_ids( next? : string[] ) {
return this.$.$mol_state_local.value( 'tag_ids' , next ) || []
}
tag( next? : string | null ) {
return this.$.$mol_state_arg.value( 'tag' , next )
}
tagging_add_showed() {
const id = this.tagging_filter()
if( !id ) return false
if( this.tag_ids().includes( id ) ) return false
return true
}
@ $mol_mem
tagging_tools() {
return [
this.Tagging_filter() ,
... this.tagging_add_showed() ? [ this.Tagging_add() ] : [] ,
]
}
notes_filter_showed() {
return this.note_ids_available().length > 1
}
notes_page_tools() {
return [
this.Reminders(),
... this.tag() ? [ this.Tag_archived() ] : [],
]
}
tag_add() {
const id = this.tagging_filter()
this.tag_ids([ id , ... this.tag_ids() ])
this.tag( id )
this.tagging_filter( '' )
}
tagging_add() {
const id = this.tagging_filter()
this.tag_ids([ id , ... this.tag_ids() ])
this.tagging_tag( id , true )
this.tagging_filter( '' )
}
tag_title( id : string ) {
return id
}
id( id : string ) {
return id
}
note_title( id : string ) {
return this.note_content( id ).replace( /\n[\s\S]*/ , '' ) || this.note_default_title()
}
note_current_title() {
return this.note_title( this.note()! )
}
tagging_rows() {
return this.tag_ids()
.filter( $mol_match_text( this.tagging_filter() , id => [ id ] ) )
.map( id => this.Tagging_tag_row( id ) )
}
@ $mol_mem_key
tagging_tag_row( id: string ) {
return [
this.Tag_link(id),
... this.note() ? [ this.Tag_toggle(id) ] : [],
]
}
note_ids_available() {
const tag = this.tag()
if( !tag ) return this.note_ids()
return this.note_ids()
.filter( note => this.note_tags( note ).includes( tag ) )
}
note_rows() {
return this.note_ids_available()
.filter( $mol_match_text( this.note_filter() , id => [ this.note_content( id ) ] ) )
.sort( ( a, b )=>
( this.note_moment( a )?.valueOf() ?? Number.POSITIVE_INFINITY )
- ( this.note_moment( b )?.valueOf() ?? Number.POSITIVE_INFINITY )
)
.map( id => this.Note_row( id ) )
}
note_add_short() {
const id = $mol_stub_code()
this.note_ids([ id , ... this.note_ids() ])
this.note_tags( id , $mol_maybe( this.tag() ) )
const title = this.note_filter()
this.note_content( id , title ? title + '\n\n' : '' )
this.note_filter('')
}
note_add_long() {
this.note_add_short()
this.note( this.note_ids()[0] )
setTimeout( ()=> this.Note_content().Edit().focused( true ) , 500 )
}
note_archived( next?: boolean ) {
const note = this.note()!
if( next === undefined ) return !this.note_ids().includes( note )
if( next ) this.note_ids( this.note_ids().filter( id => id !== note ) )
else this.note_ids([ note, ... this.note_ids() ])
return next
}
tag_archived( next?: boolean ) {
const tag = this.tag()!
if( next === undefined ) return !this.tag_ids().includes( tag )
if( next ) this.tag_ids( this.tag_ids().filter( id => id !== tag ) )
else this.tag_ids([ tag, ... this.tag_ids() ])
return next
}
notes_title() {
const tag = this.tag()
return tag ? this.tag_title( tag ) : super.notes_title()
}
tagging_tag( tag : string , next?: boolean ) {
const note = this.note()!
const tags = this.note_tags( note )
if( next === undefined ) return tags.includes( tag )
const filtered = tags.filter( id => id !== tag )
if( next ) this.note_tags( note , [ tag , ... filtered ] )
else this.note_tags( note , filtered )
return next
}
}
}