From 047cead873074c67e3504959b21d418dc065dae1 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 8 Mar 2020 17:34:15 +0300 Subject: [PATCH] started porting experiments to browse2.js... Signed-off-by: Alex A. Naanou --- ui (gen4)/lib/widget/browse2.html | 3 +- ui (gen4)/lib/widget/browse2.js | 110 ++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/ui (gen4)/lib/widget/browse2.html b/ui (gen4)/lib/widget/browse2.html index 2f0da2fa..776c9c19 100755 --- a/ui (gen4)/lib/widget/browse2.html +++ b/ui (gen4)/lib/widget/browse2.html @@ -215,7 +215,8 @@ requirejs([ make.Heading('Heading'), make.Confirm('Confirm', function(){ console.log('confirm') }, - function(){ console.log('reject') }) + function(){ console.log('reject') }), + make.field('field', 'value') ]) make.nest(make.Heading('$Dynamic Items', { doc: 'Item generator examples...', diff --git a/ui (gen4)/lib/widget/browse2.js b/ui (gen4)/lib/widget/browse2.js index c9e85824..0c109e5b 100755 --- a/ui (gen4)/lib/widget/browse2.js +++ b/ui (gen4)/lib/widget/browse2.js @@ -203,6 +203,74 @@ object.mixinFlat(function(){}, { }, + // Utils... + + // Make a nested context... + // + // Make a nested context object... + // .makeSubContext(name[, obj]) + // -> context + // + // Make a nested context function... + // .makeSubContext(name, func[, obj]) + // -> context + // + // + // The context inherits from .items / make(..) + // + // If the context is callable it will be called in the context of make(..) + // + // If the context is constructed recursively it will return self + // + // XXX TEST... + makeSubContext: function(name, obj){ + // arse args... + var args = [...arguments].slice(1) + var func = args[0] instanceof Function ? + args.shift() + : null + obj = args.shift() + + var n = '__'+ name + Object.defineProperty(this, name, { + get: function(){ + var that = this + if(!this.hasOwnProperty(n)){ + // build the context object... + var nested = + func ? + // NOTE: we always call func(..) in the root context... + function(){ + // XXX should the client be able to override shorthands??? + var shorthands = (that.dialog.options || {}).elementShorthand || {} + return arguments[0] in shorthands ? + that.call(that, ...arguments) + : func.call(that, ...arguments) } + //return func.call(that, ...arguments) } + : this instanceof Function ? + function(){ + return that.call(this, ...arguments) } + : {} + nested.__proto__ = this + + // mixin parent/obj... + Object.assign(nested, + this[n] || obj || {}) + + // NOTE: this will prevent constructing a nested context + // (see test above)... + this[n] = nested[n] = nested + } + return this[n] }, + }) + return this[name] }, + + // XXX + batch: function(spec, callback){ + // XXX + }, + + // Getters... // Last item created... @@ -461,6 +529,48 @@ object.mixinFlat(function(){}, { }) +// Sub-context: .field +// +Items.makeSubContext('field', + // base field handler... + // + // .field(title, value[, options]) + // + // NOTE: this is a shorthand to: + // make([title, value], ..) + Object.assign(function(title, value, options){ + var args = [...arguments].slice(1) + value = (args[0] instanceof Function + || !(args[0] instanceof Object)) ? + args.shift() + : undefined + options = args.shift() || {} + value = value || options.value + Object.assign( + options, + { + title, + value, + }) + return this([ + title, + options.value instanceof Function ? + options.value(this) + : options.value + ], options) }, + { + // XXX + Editable: function(title, value, options){ + }, + + // Value toggle field... + // + // XXX + Toggle: function(title, options){ + }, + })) + + var Make = module.Make = object.Constructor('Make', Items)