Fix clone & child handling

This gets webcomponents (Et2Box) working in nextmatch
This commit is contained in:
nathan 2021-09-03 11:20:53 -06:00
parent ef1239b017
commit dccf43f3e3
3 changed files with 66 additions and 10 deletions

View File

@ -11,8 +11,9 @@
import {css, html, LitElement} from "@lion/core";
import {Et2Widget} from "../Et2Widget/Et2Widget";
import {et2_IDetachedDOM} from "../et2_core_interfaces";
export class Et2Box extends Et2Widget(LitElement)
export class Et2Box extends Et2Widget(LitElement) implements et2_IDetachedDOM
{
static get styles()
{
@ -60,6 +61,36 @@ export class Et2Box extends Et2Widget(LitElement)
{
return true;
}
/**
* Code for implementing et2_IDetachedDOM
*
* Individual widgets are detected and handled by the grid, but the interface is needed for this to happen
*
* @param {array} _attrs array to add further attributes to
*/
getDetachedAttributes(_attrs)
{
_attrs.push('data');
}
getDetachedNodes()
{
return [this.getDOMNode()];
}
setDetachedAttributes(_nodes, _values)
{
if(_values.data)
{
var pairs = _values.data.split(/,/g);
for(var i = 0; i < pairs.length; ++i)
{
var name_value = pairs[i].split(':');
jQuery(_nodes[0]).attr('data-' + name_value[0], name_value[1]);
}
}
}
}
customElements.define("et2-box", Et2Box);

View File

@ -469,7 +469,7 @@ const Et2WidgetMixin = (superClass) =>
iterateOver(_callback : Function, _context, _type)
{
if(et2_implements_registry[_type] && et2_implements_registry[_type](this))
if(typeof _type == "undefined" || et2_implements_registry[_type] && et2_implements_registry[_type](this))
{
_callback.call(_context, this);
}
@ -500,9 +500,9 @@ const Et2WidgetMixin = (superClass) =>
this.getParent().getDOMNode(this).append(this);
}
for(let i = 0; i < this._legacy_children.length; i++)
for(let i = 0; i < this.getChildren().length; i++)
{
let child = this._legacy_children[i];
let child = this.getChildren()[i];
let child_node = typeof child.getDOMNode !== "undefined" ? child.getDOMNode(child) : null;
if(child_node && child_node !== this)
{
@ -640,16 +640,26 @@ const Et2WidgetMixin = (superClass) =>
}
// Create the copy
var copy = <Et2WidgetClass>this.cloneNode(true);
var copy = <Et2WidgetClass>this.cloneNode();
// Create a clone of all child widgets of the given object
for(var i = 0; i < copy.getChildren().length; i++)
if(_parent)
{
copy.addChild(copy.getChildren()[i].clone(this));
copy.setParent(_parent);
}
else
{
// Copy a reference to the content array manager
copy.setArrayMgrs(this.getArrayMgrs());
// Pass on instance too
copy.setInstanceManager(this.getInstanceManager());
}
// Copy a reference to the content array manager
copy.setArrayMgrs(this.getArrayMgrs());
// Create a clone of all child widgets of the given object
for(var i = 0; i < this.getChildren().length; i++)
{
this.getChildren()[i].clone(copy);
}
return copy;
}
@ -767,6 +777,16 @@ const Et2WidgetMixin = (superClass) =>
}
}
/**
* Set the instance manager
* Normally this is not needed as it's set on the top-level container, and we just return that reference
*
*/
setInstanceManager(manager : etemplate2)
{
this._inst = manager;
}
/**
* Returns the instance manager
*

View File

@ -282,6 +282,11 @@ export class et2_nextmatch_rowProvider
// Get all attribute values
for (const key in _widget.attributes)
{
if(typeof _widget.attributes[key] !== "object")
{
continue;
}
if(!_widget.attributes[key].ignore &&
typeof _widget.options[key] != "undefined")
{