Skip to content

Commit

Permalink
$mol_view_tree2 review fixes - right bind, image
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Jan 7, 2024
1 parent 00756fa commit c17a716
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 78 deletions.
4 changes: 2 additions & 2 deletions image/image.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ $mol_image $mol_view
crossOrigin <= cors null
attr *any
^
width <= natural_width? 0
height <= natural_height? 0
width <= natural_width 0
height <= natural_height 0
event *any
load? <=> load? null
minimal_width 16
Expand Down
8 changes: 4 additions & 4 deletions image/image.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ namespace $.$$ {
export class $mol_image extends $.$mol_image {

@ $mol_mem
natural_width( next?: null | number ) {
natural_width( next?: null ) {

const dom = this.dom_node() as HTMLImageElement
if( dom.naturalWidth ) return dom.naturalWidth

const found = this.uri().match( /\bwidth=(\d+)/ )
return found ? Number( found[1] ) : null!
return found ? Number( found[1] ) : null!

}

@ $mol_mem
natural_height( next?: null | number ) {
natural_height( next?: null ) {

const dom = this.dom_node() as HTMLImageElement
if( dom.naturalHeight ) return dom.naturalHeight

const found = this.uri().match( /\bheight=(\d+)/ )
return found ? Number( found[1] ) : null!
return found ? Number( found[1] ) : null!

}

Expand Down
49 changes: 17 additions & 32 deletions view/tree2/class/props.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ namespace $.$$ {
sub /
<= title
<= Close ${d}mol_button
title \close
title \\close
click?event <=> close?event null
Some* ${d}mol_speech
Text => f
g => h
Dog ${d}mol_view_tree2_class_test_dog
Mouth => Dog_mouth
animation => dog_animation
plugins /
<= Speech ${d}mol_speech
Text => a
b => c
d => e
<= Human* ${d}mol_view_tree2_class_test_human
Mouth => Human_mouth
animation => human_animation
text => human_text
`
/*
class A {
Expand All @@ -38,35 +38,20 @@ namespace $.$$ {
sub /
<= Title
<= Close
Some* ${d}mol_speech
Text => f
g => h
plugins / <= Speech
Dog $mol_view_tree2_class_test_dog Mouth => Dog_mouth animation => dog_animation
plugins / <= Human*
Сlose_icon ${d}mol_icon_cross
Title ${d}mol_view sub / <= title
close?event null
Close ${d}mol_button
title \close
title \\close
click?event <=> close?event
f =
Some* ${d}mol_speech Text => f g => h
Text
h =
f
g
a =
Speech ${d}mol_speech Text => a b => c d => e
Text
c =
a
b
e =
c
d
Speech ${d}mol_speech
Text => a
b => c
d => e
Dog_mouth = Dog Mouth
dog_animation = Dog_mouth animation
Human_mouth = Human* Mouth
human_animation = Human_mouth animation
human_text = human_animation text
Human* $mol_view_tree2_class_test_human Mouth => Human_mouth animation => human_animation text => human_text
`, 'reference')

$mol_test({
Expand Down
7 changes: 4 additions & 3 deletions view/tree2/class/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ namespace $ {

add_inner(right.clone([
right.struct('=', [
context.factory,
left.clone([])
context.factory.clone([ left.clone([]) ]),
]),
]))
}

if (right) context = { factory: right.clone([]) }
else if( operator && ! context.factory && $mol_view_tree2_class_match( operator ) ) context = { factory: left }
else if( operator && ! context.factory && $mol_view_tree2_class_match( operator ) ) {
context = { factory: left.clone([]) }
}

return [ left.clone( left.hack( belt, context ) ) ]

Expand Down
71 changes: 37 additions & 34 deletions view/tree2/to/dts/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@ namespace $ {
]
}

function parameters(this: $, klass: $mol_tree2, input: $mol_tree2) {
return [
function parameters(this: $, klass: $mol_tree2, input: $mol_tree2, pick_index?: number) {
const result = [
input.data( 'Parameters< ' ),
klass,
input.data( '[\'' ),
name_of.call(this, input ),
input.data( `'] >`),
]

if (pick_index !== undefined) {
result.push(input.data(`[${pick_index}]`))
}

return result
}

function primitive_type(input: $mol_tree2) {
Expand Down Expand Up @@ -131,6 +137,7 @@ namespace $ {
'<=>': (input) => return_type.call(this, klass.data( klass.type ), this.$mol_view_tree2_child(input)),
'<=': (input) => return_type.call(this, klass.data( klass.type ), this.$mol_view_tree2_child(input)),
'=>': () => [],

'^': (input) => {
const host = input.kids.length ? klass : parent
return return_type.call(
Expand All @@ -139,8 +146,11 @@ namespace $ {
input.kids.length ? input.kids[0] : prop
)
},

'=': (input) => {
const [ left, right ] = input.kids
const left = input.kids[0]
const right = left.kids[0]

const left_parts = this.$mol_view_tree2_prop_parts(left)
const right_parts = this.$mol_view_tree2_prop_parts(right)

Expand All @@ -151,52 +161,45 @@ namespace $ {

if (conflict) {
this.$mol_fail(err`Only one "${conflict}" allowed: ${
left_parts[conflict]} at ${left.span} or ${right_parts[conflict]} at ${right.span}`)
left_parts[conflict]} at ${left.span} or ${
right_parts[conflict]} at ${right.span}`)
}

const main = klass.data(klass.type)
const prop_parts = this.$mol_view_tree2_prop_parts(prop)
const method = prop.data(`${ klass.type }_${prop_parts.name}`)
const second_main = left_parts.key || left_parts.next ? main : left.struct('line',
return_type.call(this, main, left)
)
const second_key = left_parts.next || left_parts.key ? left : right

if (prop_parts.key) {
types.push( type_enforce.call(
this,
method,
parameters.call(this, main, prop, 0),
parameters.call(this, second_main, second_key, 0),
) )
}

if (prop_parts.key || prop_parts.next) {
const prop_params = parameters.call(this, main, prop)

const host = left.kids.length > 0
? left.kids[0].data(left.kids[0].type)
: undefined

if (prop_parts.key) {
const second_key = left_parts.key ? left : right
types.push( type_enforce.call(
this,
method,
[ ...prop_params, prop.data('[0]') ],
[ ...parameters.call(this, right_parts.key && host ? host : main, second_key), second_key.data('[0]') ],
) )
}

if (prop_parts.next) {
const second_next = left_parts.next ? left : right
const second_parts = left_parts.next ? left_parts : right_parts

types.push( type_enforce.call(
this,
method,
[ ...prop_params, prop.data(`[${prop_parts.key ? '1' : '0'}]`) ],
[ ...parameters.call(this, right_parts.next && host ? host : main, second_next),
second_next.data(`[${second_parts.key ? '1' : '0'}]`) ],
) )
}
if (prop_parts.next) {
types.push( type_enforce.call(
this,
method,
parameters.call(this, main, prop, prop_parts.key ? 1 : 0),
parameters.call(this, second_main, second_key, (left_parts.next ? left_parts : right_parts).key ? 1 : 0),
) )
}

return return_type.call(
this,
left.struct('line',
return_type.call(this, main, name_of.call(this, left))
return_type.call(this, main, left)
),
name_of.call(this, right),
)
},

'': ( input, belt, context )=> {

if (input.type[0] === '*') {
Expand Down
18 changes: 15 additions & 3 deletions view/tree2/to/js/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ namespace $ {
return params_of.call(this, prop, bidi)
}

function call_method_name(this: $, child: $mol_tree2) {
return child.struct( '[]', [
child.data( name_of.call( this, child ) )
] )
}

function call_of(this: $, bind: $mol_tree2, bidi = true) {
if( bind.kids.length === 0 ) {
return this.$mol_fail(
Expand All @@ -32,7 +38,7 @@ namespace $ {

for (const child of bind.kids) {
chain.push(
bind.struct( '[]', [ child.data( name_of.call( this, child ) ) ] ),
call_method_name.call(this, child),
params_of.call(this, child, bidi),
)
}
Expand Down Expand Up @@ -113,8 +119,14 @@ namespace $ {
] ),
],

'=': bind => [ call_of.call(this, bind, true) ],

'=': bind => [ bind.struct( '()', [
bind.struct( 'this' ),
call_method_name.call(this, bind.kids[0]),
params_of.call(this, bind.kids[0]),
call_method_name.call(this, bind.kids[0].kids[0]),
params_of.call(this, bind.kids[0].kids[0]),
] ) ],

'': ( input, belt, context )=> {

if( input.type[0] === '*' ) {
Expand Down

0 comments on commit c17a716

Please sign in to comment.