generated from hyoo-ru/template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.view.ts
187 lines (139 loc) · 4.18 KB
/
page.view.ts
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
namespace $.$$ {
export class $hyoo_page extends $.$hyoo_page {
@ $mol_mem
profile() {
return this.side( this.yard().home().id() )
}
title() {
const side = this.side_current()
const book = this.side_current_book()
return book === side ? side.title() : `${ side.title() } | ${ book.title() }`
}
@ $mol_mem
aura_showing( next?: boolean ) {
const key = `aura_showing:${ this.book_id() }`
return this.$.$mol_state_local.value( key, next?.toString() ) !== 'false'
}
@ $mol_mem
aura_image(): string {
return $mol_wire_stale( ()=> {
if( !this.aura_showing() ) return ''
const side = this.side_current()
const aura = side.aura_effective()
if( !aura ) return ''
const shade = 'hsla( 0deg, 0%, calc( 50% + var(--mol_theme_luma) * 50% ), .666 )'
return `linear-gradient( ${shade}, ${shade} ), url("${ aura }")`
} ) ?? ''
}
@ $mol_mem
editing( next?: boolean ) {
if( next ) this.$.$mol_storage.persisted( true )
return this.$.$mol_state_session.value( 'edit', next ) ?? false
}
@ $mol_mem
rights( next?: boolean ) {
return this.$.$mol_state_session.value( 'rights', next ) ?? false
}
@ $mol_mem
info( next?: boolean ) {
return this.$.$mol_state_session.value( 'info', next ) ?? false
}
@ $mol_mem
safe( next?: boolean ) {
const arg = next == undefined ? undefined : next ? '' : null
return this.$.$mol_state_arg.value( 'hyoo_meta_key', arg ) !== null
}
edit_close() {
this.editing( false )
}
rights_close() {
this.rights( false )
}
info_close() {
this.info( false )
}
safe_close() {
this.safe( false )
}
side( id: $mol_int62_string ) {
return this.yard().world().Fund( $hyoo_page_side ).Item( id )
}
side_uri( id: $mol_int62_string ) {
return this.$.$mol_state_arg.make_link({ '': id })
}
@ $mol_mem
side_current_id() {
return ( this.$.$mol_state_arg.value( '' ) || this.side_main_id() ) as $mol_int62_string
}
side_current() {
return this.side( this.side_current_id() )
}
side_current_book() {
return this.side_current().book() ?? this.side_current()
}
@ $mol_mem
book_id() {
return $mol_wire_stale( ()=> {
if( !this.side_menu_showed() ) return ''
const side = this.side_current()
const books = side.books().slice().reverse()
if( side.pages().length || this.side_menu_showed() ) books.push( side )
return books[0]?.id() ?? ''
} ) ?? this.side_current_id()
}
book_side() {
const id = this.book_id()
return id ? this.side( id ) : null!
}
book_pages_node() {
return this.pages_node( this.book_id() )
}
@ $mol_mem
side_menu_showed( next?: boolean ) {
return next ?? Boolean( this.side_current().book() || this.side_current().pages().length > 0 )
}
@ $mol_mem
pages() {
const id = this.side_current_id()
const book = this.book_id()
return [
// this.News(),
this.Gap( 'left' ),
... book ? [ this.Side_menu() ] : [],
this.View( id ),
... this.info() ? [ this.Info( id ) ] : [],
... this.editing() ? [ this.Edit( id ) ] : [],
... this.rights() ? [ this.Rights( id ) ] : [],
this.Gap( 'right' ),
... this.safe() ? [ this.Safe() ] : [],
]
}
@ $mol_action
page_add() {
const land = this.yard().land_grab()
this.$.$mol_dom_context.location.href = this.$.$mol_state_arg.link({ '': land.id() })
this.bookmarks_node()!.add( land.id() )
this.editing( true )
}
@ $mol_action
side_add( id: $mol_int62_string ) {
const book = this.side( id )
const page = book.world()!.Fund( $hyoo_page_side ).make()
this.$.$mol_dom_context.location.href = this.$.$mol_state_arg.link({ '': page.id() })
page.steal_rights( book )
page.book( book )
this.bookmarks_node()!.add( page.id() )
this.editing( true )
}
@ $mol_mem
@ $mol_action
ref_track() {
const ref = this.$.$mol_dom_context.document.referrer
if( !ref ) return
const key = `${this}.ref_track`
if( this.$.$mol_state_session.value( key ) ) return
this.side_current().referrers_track( ref )
this.$.$mol_state_session.value( key, true )
}
}
}