2
0
mirror of https://github.com/esiur/iui.git synced 2025-06-27 09:23:12 +00:00
This commit is contained in:
2024-07-10 23:36:25 +03:00
parent e6b3023406
commit 4b2a3f3834
14 changed files with 188 additions and 169 deletions

View File

@ -107,7 +107,7 @@ export class Binding {
let scopeValues = Object.values(scope);
try {
let args = ["data", "d", "context", "_test",
let args = ["data", "d", "radix", "context", "_test",
...scopeKeys]
if (isAsync)
@ -153,7 +153,7 @@ export class Binding {
let proxy = new Proxy(map, detector);
try {
let d = this.func.apply(thisArg, [proxy, proxy, {}, true
let d = this.func.apply(thisArg, [proxy, proxy, null, {}, true
, ...this.scopeValues]);
this.map = map;
@ -165,12 +165,12 @@ export class Binding {
}
}
async _execute(thisArg, data) {
async _execute(thisArg, data, radix) {
if (!this.checked)
this._findMap(thisArg);
let context = {};
var rt = this.func.apply(thisArg, [data, data, context, false,
var rt = this.func.apply(thisArg, [data, data, radix, context, false,
...this.scopeValues]);
@ -243,7 +243,7 @@ export class Binding {
async render(data) {
async render(data, radix) {
// @TODO: Checking properties bindings moved here
if (data != this.data)
@ -252,7 +252,7 @@ export class Binding {
try {
if (this.type === BindingType.IUIElement) {
let d = await this._execute(this.target, data);
let d = await this._execute(this.target, data, radix);
await this.target.setData(d);
}
@ -260,7 +260,7 @@ export class Binding {
try {
let d = await this._execute(this.target.parentElement, data);
let d = await this._execute(this.target.parentElement, data, radix);
if (d === undefined)
return false;
@ -282,7 +282,7 @@ export class Binding {
let targetElement = this.target.ownerElement;
let d = await this._execute(targetElement, data);
let d = await this._execute(targetElement, data, radix);
if (d === undefined)
return false;
@ -303,13 +303,13 @@ export class Binding {
}
else if (this.type == BindingType.IfAttribute)
{
let d = await this._execute(this.target.ownerElement, data);
let d = await this._execute(this.target.ownerElement, data, radix);
this.target.ownerElement.style.display = d ? "" : "none";
}
else if (this.type == BindingType.RevertAttribute)
{
let d = await this._execute(this.target.ownerElement, data);
let d = await this._execute(this.target.ownerElement, data, radix);
if (d === undefined)
return false;
@ -317,7 +317,7 @@ export class Binding {
// Attribute
else if (this.type === BindingType.Attribute) {
let d = await this._execute(this.target.ownerElement, data);
let d = await this._execute(this.target.ownerElement, data, radix);
if (d === undefined)
return false;
@ -336,14 +336,15 @@ export class Binding {
// Data Attribute of IUI Element
else if (this.type === BindingType.IUIElementDataAttribute) {
let d = await this._execute(this.target.ownerElement, data);
let d = await this._execute(this.target.ownerElement, data, radix);
await this.target.ownerElement.setData(d);
// radix is data
await this.target.ownerElement.setData(d, data);
}
// Data Attribute of HTML Element
else if (this.type == BindingType.HTMLElementDataAttribute) {
let d = await this._execute(this.target.ownerElement, data);
let d = await this._execute(this.target.ownerElement, data, radix);
if (d === undefined)
return false;
this.target.ownerElement.data = d;

View File

@ -344,7 +344,7 @@ export class IUI {
element.__i_bindings = bindings;
}
static async render(element, data, textNodesOnly = false) {
static async render(element, data, textNodesOnly = false, radix = null) {
if (!element.__i_bindings) {
return;
@ -355,11 +355,11 @@ export class IUI {
if (textNodesOnly) {
for (var i = 0; i < bindings.length; i++)
if (bindings[i].type == BindingType.TextNode)
await bindings[i].render(data);
await bindings[i].render(data, radix);
} else {
// render attributes & text nodes
for (var i = 0; i < bindings.length; i++)
await bindings[i].render(data);
await bindings[i].render(data, radix);
}
// render children
@ -369,7 +369,7 @@ export class IUI {
// @TODO should check if the element depends on parent or not
if (el.dataMap != null) {
// if map function failed to call setData, we will render without it
if (!(await el.dataMap.render(data))){
if (!(await el.dataMap.render(data, radix))){
// @BUG @TODO this causes stackoverflow
// await el.render();
}
@ -380,11 +380,11 @@ export class IUI {
}
else {
if (el.dataMap != null)
await el.dataMap.render(data);
await el.dataMap.render(data, radix);
else
el.data = data;
await IUI.render(el, el.data);
await IUI.render(el, el.data, textNodesOnly, data);
}
}
}

View File

@ -54,10 +54,10 @@ export default class IUIElement extends HTMLElement {
return undefined;
}
async setData(value) {
async setData(value, radix) {
this._data = value;
this._emit("data", {data: value});
await IUI.render(this, value);
await IUI.render(this, value, false, radix);
// notify updated callback
await this.updated();

View File

@ -28,9 +28,9 @@ export default IUI.module(class Form extends IUIElement {
}
async setData(value) {
async setData(value, radix) {
this.original = value;
super.setData(new Modifiable(this.original, true));
super.setData(new Modifiable(this.original, true), radix);
}

View File

@ -54,7 +54,16 @@ export default IUI.module(class Repeat extends IUIElement
this._repeatNode.innerHTML = this.childNodes[0].data.trim();
}
this.innerHTML = "";
// keep script
var toBeRemoved = [];
for(let i = 0; i < this.childNodes.length; i++)
if (this.childNodes[i].tagName != "SCRIPT")
toBeRemoved.push(this.childNodes[i]);
for(let i = 0; i < toBeRemoved.length; i++)
this.removeChild(toBeRemoved[i]);
//this.innerHTML = "";
this._container = this;
}
@ -111,7 +120,7 @@ export default IUI.module(class Repeat extends IUIElement
}
async setData(value)
async setData(value, radix)
{
@ -135,7 +144,7 @@ export default IUI.module(class Repeat extends IUIElement
//debugger;
await super.setData(value);
await super.setData(value, radix);
for (let i = 0; i < value.length; i++) {
@ -166,23 +175,24 @@ export default IUI.module(class Repeat extends IUIElement
// @TODO should check if the element depends on parent or not
if (el.dataMap != null) {
// if map function failed to call setData, we will render without it
if (!(await el.dataMap.render(value[i]))) {
if (!(await el.dataMap.render(value[i], radix))) {
// @BUG @TODO this causes stackoverflow
// await el.render();
}
}
else {
await el.setData(value[i]);
await el.setData(value[i], radix);
}
}
else
{
if (el.dataMap != null)
await el.dataMap.render(value[i]);
await el.dataMap.render(value[i], radix);
else
el.data = value[i];
await IUI.render(el, el.data, false);
// data is now the radix
await IUI.render(el, el.data, false, value[i]);
}
}

View File

@ -16,10 +16,10 @@ export default IUI.module(
this._register("load");
}
async setData(value) {
async setData(value, radix) {
if (this.hasAttribute("debug")) debugger;
return await super.setData(value);
return await super.setData(value, radix);
}
get scope() {

View File

@ -32,8 +32,8 @@ export default IUI.module(class Check extends IUIElement {
this.field = this.getAttribute("field");
}
async setData(value) {
await super.setData(value);
async setData(value, radix) {
await super.setData(value, radix);
if (value != null && this.field != null)
this.value = value[this.field];
else if (this.field != null)

View File

@ -296,14 +296,16 @@ export default IUI.module(class DateTimePicker extends IUIElement {
this.clock.children[time / this.layout.time.range].classList.add(this.cssClass + "-time-selected");
}
async setData(value) {
async setData(value, radix) {
await super.setData(value);
await super.setData(value, radix);
if (value != null && this.field != null)
this.value = this.data[this.field];
else
this.value = value;
}
get data() {
@ -311,13 +313,10 @@ export default IUI.module(class DateTimePicker extends IUIElement {
}
async setData(value) {
await super.setData(value);
async setData(value, radix) {
await super.setData(value, radix);
this.value = value;
if (this.isAuto)
this.revert();
}
/*

View File

@ -67,11 +67,11 @@ export default IUI.module(class DropDown extends IUIElement {
}
}
async setData(value){
async setData(value, radix){
//debugger;
await super.setData(value);
await this.menu.setData(value);
await super.setData(value, radix);
await this.menu.setData(value, radix);
}

View File

@ -136,8 +136,8 @@ export default IUI.module(
return !this._input.disabled;
}
async setData(value) {
await super.setData(value);
async setData(value, radix) {
await super.setData(value, radix);
if (this.type == "checkbox") this._input.checked = value;
else if (this.type == "date") {

View File

@ -345,11 +345,11 @@ export default IUI.module(class Select extends IUIElement {
}
async setData(value) {
async setData(value, radix) {
// this.label.innerHTML = "";
await super.setData(value);
await super.setData(value, radix);
try {
//let text = this.formatter(value);

View File

@ -1389,9 +1389,9 @@ export default IUI.module(class Table extends IUIElement {
async setData(value)
async setData(value, radix)
{
await super.setData(value);
await super.setData(value, radix);
this.clear();