Skip to content

Commit

Permalink
Port to CRUS
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Feb 9, 2024
1 parent 3b1e2e0 commit 1cdbf63
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 54 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!doctype html>
<html style=" height: 100% ">
<html mol_view_root>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1">
</head>

<body style=" width: 100%; height: 100%; margin: 0 ">
<body mol_view_root>
<div mol_view_root="$my_wiki"></div>
<script src="web.js"></script>
</body>
Expand Down
29 changes: 7 additions & 22 deletions note/note.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
namespace $.$$ {

export class $my_wiki_note extends $mol_object2 {
export class $my_wiki_note extends $hyoo_crus_entity.with({
Body: $hyoo_crus_text,
}) {

state() {
return null as any as $mol_state_shared
@ $mol_mem
body_selection( next?: readonly[ begin: number, end: number ] ) {
return this.Body.selection( this.land().lord()!.ref(), next )
}

details( next?: string ) {

if( next !== undefined ) {
this.changed_moment( new $mol_time_moment )
}

return this.state().sub( 'details' ).text( next )
}

details_selection( next?: number[] ) {
return this.state().sub( 'details' ).selection( next )
}

changed_moment( next?: $mol_time_moment ) {
const str = this.state().sub( 'changed_moment' ).value( next && next.toString() ) as string
return str ? new $mol_time_moment( str ) : null
}


}

}
24 changes: 22 additions & 2 deletions wiki.view.css.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
namespace $ {

const { rem } = $mol_style_unit

$mol_style_define( $my_wiki, {

Body: {
padding: $mol_gap.block,
View_page: {
margin: [ 0, 'auto' ],
flex: {
basis: rem(60),
grow: 0,
},
},

Note_changed_moment: {
align: {
self: 'flex-end',
},
},

Edit_page: {
margin: [ 0, 'auto' ],
flex: {
basis: rem(60),
grow: 0,
},
},

} )
Expand Down
64 changes: 52 additions & 12 deletions wiki.view.tree
Original file line number Diff line number Diff line change
@@ -1,12 +1,52 @@
$my_wiki $mol_page
state $mol_state_shared
note!id $my_wiki_note
title \My Wiki
tools /
<= Changed_moment $mol_date
value_moment <= changed_moment $mol_time_moment
body /
<= Details $mol_textarea
hint \Details
value?val <=> details?val \
selection?val <=> details_selection?val /number
$my_wiki $mol_book2
realm $hyoo_crus_realm
note* $my_wiki_note
note_current $my_wiki_note
Placeholder null
plugins /
<= Theme $mol_theme_auto
pages /
<= View_page $mol_page
title <= note_title
tools /
<= Lights $mol_lights_toggle
<= Source $mol_link_source
uri \https://github.com/hyoo-ru/dragon-way/
<= Add $mol_button_minor
hint \Make new page
click? <=> add? null
sub /
<= Add_icon $mol_icon_plus
<= Edit_toggle $mol_check_icon
hint \Edit page
checked? <=> editing? false
Icon <= Edit_icon $mol_icon_pencil
<= Profile $mol_link
hint \Profile
arg <= profile_arg *
sub /
<= Profile_icon $mol_icon_account
body /
<= Content $mol_list rows /
<= Body $mol_text
text <= note_body
<= Note_changed_moment $mol_date
value_moment <= note_changed_moment $mol_time_moment
enabled false
<= Edit_page $mol_page
head /
<= Title $mol_string
hint \Title
value? <=> note_title? \
enabled <= editable
selection? <=> title_selection? /
<= Edit_close $mol_button_minor
hint \Close editor
click? <=> edit_close? null
sub / <= Edit_close_icon $mol_icon_cross
body /
<= Body_edit $mol_textarea
hint \Node Content
value? <=> note_body? \
enabled <= editable
selection? <=> note_body_selection?
63 changes: 47 additions & 16 deletions wiki.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,65 @@ namespace $.$$ {
export class $my_wiki extends $.$my_wiki {

@ $mol_mem_key
note( id: string ) {
const obj = new $my_wiki_note
obj.state = $mol_const( this.state().doc( 'note' ).doc( id ) )
return obj
note( ref: $hyoo_crus_ref ) {
return this.realm().Node( ref, $my_wiki_note )
}

note_id() {
return this.$.$mol_state_arg.value( '' ) ?? ''
note_current() {
const str = this.$.$mol_state_arg.value( '' )
if( !str ) return null!
const ref = $hyoo_crus_ref( str )
return this.note( ref )
}

note_current() {
return this.note( this.note_id() )
note_title( next?: string ) {
return this.note_current().title( next ) ?? ''
}

note_body( next?: string ) {
return this.note_current().body( next ) ?? ''
}

note_body_selection( next?: readonly[ begin: number, end: number ] ) {
return this.note_current().body_selection( next )
}

note_changed_moment() {
return this.note_current().last_change()!
}

@ $mol_action
add() {

const land = this.realm().home().Land_new( 0 )

this.$.$mol_dom_context.location.href = '#!=' + land.ref().description
this.editing( true )

}

title() {
return this.note_id().replace( /_/g, ' ' ) || super.title()
@ $mol_mem
profile_arg() {
return {
'': this.realm().home().Profile( '$my_wiki', $my_wiki_note, null )!.ref().description
}
}

details( next?: string ) {
return this.note_current().details( next )
@ $mol_mem
editing( next?: boolean ) {
return this.$.$mol_state_history.value( 'edit', next ) ?? false
}

details_selection( next?: number[] ) {
return this.note_current().details_selection( next )
edit_close() {
this.editing( false )
}

changed_moment( next?: $mol_time_moment ) {
return this.note_current().changed_moment( next ) ?? new $mol_time_moment
@ $mol_mem
pages() {
return [
this.View_page(),
... this.editing() ? [ this.Edit_page() ] : [],
]
}

}
Expand Down

0 comments on commit 1cdbf63

Please sign in to comment.