reworking render....

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-09-17 03:51:02 +03:00
parent d0dad4811a
commit 7d521bdf14

View File

@ -2679,7 +2679,7 @@ var BaseBrowserPrototype = {
throw Stop }) throw Stop })
: pattern ] : pattern ]
// search... // search...
: that.search2(pattern, ...args.slice(1)) }) : that.search(pattern, ...args.slice(1)) })
.flat() .flat()
.unique() .unique()
} catch(e){ } catch(e){
@ -3034,8 +3034,27 @@ var BaseBrowserPrototype = {
// //
// XXX revise options handling... // XXX revise options handling...
// XXX BUG: for some reason these shift more than one position... // XXX BUG: for some reason these shift more than one position...
// dialog.render({from: 17, count: 5}, browser.TextRenderer) // dialog.render({from: 17, count: 5}, browser.TextRenderer)
// dialog.render({from: 18, count: 5}, browser.TextRenderer) // dialog.render({from: 18, count: 5}, browser.TextRenderer)
// ...the indexing seems to get either messed up or not compensated
// for...
// ...count seems to have some odd effect:
// dialog
// .focus('nested')
// .render({around: 'focused', count: 7}, browser.TextRenderer)
// and:
// dialog
// .focus('nested')
// .render({around: 'focused', count: 5}, browser.TextRenderer)
// produce different results in terms of centering and alignment!!!
// XXX BUG: these falls int recursion...
// dialog.render({around: 9, count: 5}, browser.TextRenderer)
// dialog.render({around: 8, count: 3}, browser.TextRenderer)
// ...
// dialog.render({around: 7, count: 1}, browser.TextRenderer)
// dialog.render({from: 7}, browser.TextRenderer)
// XXX BUG: numbering is wrong when elements collapse...
// ...to fix this use .update()
render: function(options, renderer){ render: function(options, renderer){
var that = this var that = this
var args = [...arguments] var args = [...arguments]
@ -3077,55 +3096,53 @@ var BaseBrowserPrototype = {
: section : section
// from/to/around/count... // from/to/around/count...
var get_options = Object.assign( var get = function(x){
Object.create(options), return options[x] instanceof BaseItem ?
{from: null, to: null, around: null, [undefined, undefined, options[x]]
iterateNonIterable: options.iterateNonIterable}) : options[x] != null ?
var normalizeIndex = function(i){ that.get(options[x], function(e, i, p){ return [i, p, e] }, options) || []
return (i !== undefined && typeof(i) != typeof(123)) ? : [undefined, undefined, undefined] }
this.get(i, var [f, from_path, from] = get('from')
function(_, i){ return i }, var [t, _, to] = get('to')
get_options) var [a, _, around] = get('around')
: i }.bind(this)
var from = normalizeIndex(options.from)
var to = normalizeIndex(options.to)
var around = normalizeIndex(options.around)
var count = options.count || null var count = options.count || null
// complete to/from based on count and/or around... // complete to/from based on count and/or around...
// NOTE: we do not care about overflow here... if(count != null){
;(from == null && count != null) from = from
&& (from = options.from = || this.get(
to != null ? (f = Math.max(0,
to - count t != null ?
: around != null ? t - count
around - Math.floor(count/2) : a != null ?
: from) a - Math.floor(count/2)
;(to == null && count != null) : 0)),
&& (to = options.to = options)
from != null ? to = to
from + count || this.get(
: around != null ? (t = f != null ?
around + Math.ceil(count/2) f + count
: to) : a != null ?
// sanity check... a + Math.ceil(count/2)
if(from != null && to != null && to < from){ : -1),
throw new Error(`.render(..): options.from must be less than ` options) }
+`or equal to options.to. (got: from=${from} and to=${to})`) } [options.from, options.to] = [from, to]
// partial render start path... // partial render start path...
// NOTE: used to check if an item is on the path to <from> and // NOTE: used to check if an item is on the path to <from> and
// pass it to the skipped topology constructor... // pass it to the skipped topology constructor...
var from_path = options.from_path = from_path = options.from_path =
options.from_path options.from_path
|| (from != null || from && this.pathOf(from, options)
&& this.get(from, from_path = from_path instanceof Array && from_path
function(e, i, p){ return p },
get_options))
from_path = from_path instanceof Array
&& from_path
// used as a means to calculate lengths of nested blocks rendered // used as a means to calculate lengths of nested blocks rendered
// via .render(..) // via .render(..)
var l var l
// rendering state for partial renders...
// NOTE: when this is null then rendering is done...
var rendering = render.rendering =
'rendering' in render ?
render.rendering
: !from
return ((list == null && render.root === this && section instanceof Array) ? return ((list == null && render.root === this && section instanceof Array) ?
// render list of sections... // render list of sections...
// NOTE: we will only render the section list on the top // NOTE: we will only render the section list on the top
@ -3190,20 +3207,30 @@ var BaseBrowserPrototype = {
.render(options, render, i+1, p)) .render(options, render, i+1, p))
: children(true) } : children(true) }
// maintain rendering state....
// NOTE: render ranges are supported only in 'items' section...
rendering = section != 'items' ?
true
: (render.rendering =
!rendering && from === e ?
true
: rendering && to === e ?
// XXX should we stop() here???
null
: render.rendering)
// do the actual rendering... // do the actual rendering...
return ( return (
// special case: nested <from> elem -> render topology only... // special case: nested <from> elem -> render topology only...
(from_path (from_path
&& i < from && rendering === false
// only for nested... // only for nested...
&& e && e.children && e.children
// only sub-path... // only sub-path...
&& p.cmp(from_path.slice(0, p.length))) ? && p.cmp(from_path.slice(0, p.length))) ?
// XXX BUG: this is not totally correct for nested browsers...
render.nest(null, getChildren(), i, p, options) render.nest(null, getChildren(), i, p, options)
// skip: out of range items... // skip: out of range items...
: ((from != null && i < from) : !rendering ?
|| (to != null && i >= to)) ?
[] []
// inlined... // inlined...
: (e instanceof BaseBrowser || e instanceof Array) ? : (e instanceof BaseBrowser || e instanceof Array) ?