tutuca 0.9.7 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -1
- package/dist/tutuca-dev.js +57 -71
- package/dist/tutuca-dev.min.js +3 -3
- package/dist/tutuca-extra.js +57 -71
- package/dist/tutuca-extra.min.js +3 -3
- package/dist/tutuca.js +57 -71
- package/dist/tutuca.min.js +3 -3
- package/package.json +22 -1
package/dist/tutuca.js
CHANGED
|
@@ -1089,6 +1089,10 @@ class ANode extends BaseNode {
|
|
|
1089
1089
|
return px.addNodeIf(RenderItNode, vp.bindValIt, as);
|
|
1090
1090
|
case "render-each":
|
|
1091
1091
|
return RenderEachNode.parse(px, vp, value, as, attrs);
|
|
1092
|
+
case "show":
|
|
1093
|
+
return px.addNodeIf(ShowNode, vp.parseCondValue(value, px), maybeFragment(childs));
|
|
1094
|
+
case "hide":
|
|
1095
|
+
return px.addNodeIf(HideNode, vp.parseCondValue(value, px), maybeFragment(childs));
|
|
1092
1096
|
}
|
|
1093
1097
|
return new CommentNode(`Error: InvalidSpecialTagOp ${name}=${value}`);
|
|
1094
1098
|
} else if (tag.charCodeAt(1) === 58 && tag.charCodeAt(0) === 88) {
|
|
@@ -6902,9 +6906,8 @@ function basicGetSeqInfo(seq) {
|
|
|
6902
6906
|
}
|
|
6903
6907
|
|
|
6904
6908
|
// src/vdom.js
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
}
|
|
6909
|
+
var isHtmlAttribute = (propName) => propName[4] === "-" && (propName[0] === "d" || propName[0] === "a");
|
|
6910
|
+
var isObject = (v) => v !== null && typeof v === "object";
|
|
6908
6911
|
function applyProperties(node, props, previous) {
|
|
6909
6912
|
for (const propName in props) {
|
|
6910
6913
|
const propValue = props[propName];
|
|
@@ -6914,7 +6917,7 @@ function applyProperties(node, props, previous) {
|
|
|
6914
6917
|
node.setAttribute(propName, propValue);
|
|
6915
6918
|
} else if (propName === "dangerouslySetInnerHTML") {
|
|
6916
6919
|
node.innerHTML = propValue.__html ?? "";
|
|
6917
|
-
} else if (
|
|
6920
|
+
} else if (isObject(propValue)) {
|
|
6918
6921
|
patchObject(node, previous, propName, propValue);
|
|
6919
6922
|
} else if (propName === "className") {
|
|
6920
6923
|
node.setAttribute("class", propValue);
|
|
@@ -6927,11 +6930,7 @@ function removeProperty(node, propName, previous) {
|
|
|
6927
6930
|
const previousValue = previous[propName];
|
|
6928
6931
|
if (propName === "dangerouslySetInnerHTML") {
|
|
6929
6932
|
node.innerHTML = "";
|
|
6930
|
-
} else if (isHtmlAttribute(propName)) {
|
|
6931
|
-
node.removeAttribute(propName);
|
|
6932
|
-
} else if (typeof previousValue === "string") {
|
|
6933
|
-
if (propName !== "className")
|
|
6934
|
-
node[propName] = "";
|
|
6933
|
+
} else if (typeof previousValue === "string" || isHtmlAttribute(propName)) {
|
|
6935
6934
|
const attrName = propName === "className" ? "class" : propName === "htmlFor" ? "for" : propName;
|
|
6936
6935
|
node.removeAttribute(attrName);
|
|
6937
6936
|
} else {
|
|
@@ -6940,12 +6939,12 @@ function removeProperty(node, propName, previous) {
|
|
|
6940
6939
|
}
|
|
6941
6940
|
function patchObject(node, previous, propName, propValue) {
|
|
6942
6941
|
const previousValue = previous?.[propName];
|
|
6943
|
-
if (previousValue &&
|
|
6942
|
+
if (isObject(previousValue) && Object.getPrototypeOf(previousValue) !== Object.getPrototypeOf(propValue)) {
|
|
6944
6943
|
node[propName] = propValue;
|
|
6945
6944
|
return;
|
|
6946
6945
|
}
|
|
6947
6946
|
let current = node[propName];
|
|
6948
|
-
if (
|
|
6947
|
+
if (!isObject(current)) {
|
|
6949
6948
|
node[propName] = {};
|
|
6950
6949
|
current = node[propName];
|
|
6951
6950
|
}
|
|
@@ -6963,16 +6962,11 @@ class VBase {
|
|
|
6963
6962
|
return null;
|
|
6964
6963
|
}
|
|
6965
6964
|
}
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
}
|
|
6969
|
-
function isIterable(obj) {
|
|
6970
|
-
return obj != null && typeof obj !== "string" && typeof obj[Symbol.iterator] === "function";
|
|
6971
|
-
}
|
|
6965
|
+
var getKey = (child) => child instanceof VNode2 ? child.key : undefined;
|
|
6966
|
+
var isIterable = (obj) => obj != null && typeof obj !== "string" && typeof obj[Symbol.iterator] === "function";
|
|
6972
6967
|
function addChild(normalizedChildren, child) {
|
|
6973
|
-
if (child == null)
|
|
6968
|
+
if (child == null)
|
|
6974
6969
|
return;
|
|
6975
|
-
}
|
|
6976
6970
|
if (isIterable(child)) {
|
|
6977
6971
|
for (const c of child) {
|
|
6978
6972
|
addChild(normalizedChildren, c);
|
|
@@ -7023,9 +7017,8 @@ class VComment extends VBase {
|
|
|
7023
7017
|
class VFragment extends VBase {
|
|
7024
7018
|
constructor(childs) {
|
|
7025
7019
|
super();
|
|
7026
|
-
|
|
7027
|
-
addChild(
|
|
7028
|
-
this.childs = normalized;
|
|
7020
|
+
this.childs = [];
|
|
7021
|
+
addChild(this.childs, childs);
|
|
7029
7022
|
}
|
|
7030
7023
|
get nodeType() {
|
|
7031
7024
|
return 11;
|
|
@@ -7109,7 +7102,7 @@ function diffProps(a, b) {
|
|
|
7109
7102
|
}
|
|
7110
7103
|
const aValue = a[aKey];
|
|
7111
7104
|
const bValue = b[aKey];
|
|
7112
|
-
if (aValue === bValue) {} else if (
|
|
7105
|
+
if (aValue === bValue) {} else if (isObject(aValue) && isObject(bValue)) {
|
|
7113
7106
|
if (Object.getPrototypeOf(bValue) !== Object.getPrototypeOf(aValue)) {
|
|
7114
7107
|
diff ??= {};
|
|
7115
7108
|
diff[aKey] = bValue;
|
|
@@ -7141,14 +7134,15 @@ function replaceNode(domNode, vnode, options) {
|
|
|
7141
7134
|
}
|
|
7142
7135
|
return newNode || domNode;
|
|
7143
7136
|
}
|
|
7137
|
+
var bothInstanceOf = (a, b, C) => a instanceof C && b instanceof C;
|
|
7144
7138
|
function morphNode(domNode, source, target, opts) {
|
|
7145
7139
|
if (source === target || source.isEqualTo(target))
|
|
7146
7140
|
return domNode;
|
|
7147
|
-
if (source
|
|
7141
|
+
if (bothInstanceOf(source, target, VText) || bothInstanceOf(source, target, VComment)) {
|
|
7148
7142
|
domNode.data = target.text;
|
|
7149
7143
|
return domNode;
|
|
7150
7144
|
}
|
|
7151
|
-
if (source
|
|
7145
|
+
if (bothInstanceOf(source, target, VNode2) && source.tag === target.tag && source.namespace === target.namespace && source.key === target.key) {
|
|
7152
7146
|
const propsDiff = diffProps(source.attrs, target.attrs);
|
|
7153
7147
|
if (propsDiff) {
|
|
7154
7148
|
applyProperties(domNode, propsDiff, source.attrs);
|
|
@@ -7158,7 +7152,7 @@ function morphNode(domNode, source, target, opts) {
|
|
|
7158
7152
|
}
|
|
7159
7153
|
return domNode;
|
|
7160
7154
|
}
|
|
7161
|
-
if (source
|
|
7155
|
+
if (bothInstanceOf(source, target, VFragment)) {
|
|
7162
7156
|
morphChildren(domNode, source.childs, target.childs, null, opts);
|
|
7163
7157
|
return domNode;
|
|
7164
7158
|
}
|
|
@@ -7235,10 +7229,8 @@ function render(vnode, container, options) {
|
|
|
7235
7229
|
if (wasFragment === isFragment) {
|
|
7236
7230
|
const rootNode = wasFragment ? container : cached.dom;
|
|
7237
7231
|
const newDom = morphNode(rootNode, cached.vnode, vnode, options);
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
dom: isFragment ? container : newDom
|
|
7241
|
-
});
|
|
7232
|
+
const domToCache = isFragment ? container : newDom;
|
|
7233
|
+
renderCache.set(container, { vnode, dom: domToCache });
|
|
7242
7234
|
return newDom;
|
|
7243
7235
|
}
|
|
7244
7236
|
renderCache.delete(container);
|
|
@@ -7247,32 +7239,33 @@ function render(vnode, container, options) {
|
|
|
7247
7239
|
if (domNode) {
|
|
7248
7240
|
container.innerHTML = "";
|
|
7249
7241
|
container.appendChild(domNode);
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
dom: isFragment ? container : domNode
|
|
7253
|
-
});
|
|
7242
|
+
const domToCache = isFragment ? container : domNode;
|
|
7243
|
+
renderCache.set(container, { vnode, dom: domToCache });
|
|
7254
7244
|
}
|
|
7255
7245
|
return domNode;
|
|
7256
7246
|
}
|
|
7257
7247
|
function h(tagName, properties, children) {
|
|
7258
7248
|
const tag = tagName.toUpperCase();
|
|
7259
7249
|
const props = {};
|
|
7260
|
-
let key;
|
|
7261
|
-
let namespace;
|
|
7250
|
+
let key, namespace;
|
|
7262
7251
|
if (properties) {
|
|
7263
7252
|
for (const propName in properties) {
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
|
|
7271
|
-
|
|
7272
|
-
|
|
7273
|
-
|
|
7274
|
-
|
|
7275
|
-
|
|
7253
|
+
const propVal = properties[propName];
|
|
7254
|
+
switch (propName) {
|
|
7255
|
+
case "key":
|
|
7256
|
+
key = propVal;
|
|
7257
|
+
break;
|
|
7258
|
+
case "namespace":
|
|
7259
|
+
namespace = propVal;
|
|
7260
|
+
break;
|
|
7261
|
+
case "class":
|
|
7262
|
+
props.className = propVal;
|
|
7263
|
+
break;
|
|
7264
|
+
case "for":
|
|
7265
|
+
props.htmlFor = propVal;
|
|
7266
|
+
break;
|
|
7267
|
+
default:
|
|
7268
|
+
props[propName] = isHtmlAttribute(propName) ? String(propVal) : propVal;
|
|
7276
7269
|
}
|
|
7277
7270
|
}
|
|
7278
7271
|
}
|
|
@@ -7422,14 +7415,8 @@ class FieldString extends Field {
|
|
|
7422
7415
|
constructor(name, defaultValue = "") {
|
|
7423
7416
|
super("text", name, CHECK_TYPE_STRING, stringCoercer, defaultValue);
|
|
7424
7417
|
}
|
|
7425
|
-
extendProtoForType(proto,
|
|
7426
|
-
|
|
7427
|
-
proto[`${name}IsEmpty`] = function() {
|
|
7428
|
-
return this.get(name, "").length === 0;
|
|
7429
|
-
};
|
|
7430
|
-
proto[`${name}Len`] = function() {
|
|
7431
|
-
return this.get(name, "").length;
|
|
7432
|
-
};
|
|
7418
|
+
extendProtoForType(proto, uname) {
|
|
7419
|
+
extendProtoSized(proto, this.name, uname, "", "length");
|
|
7433
7420
|
}
|
|
7434
7421
|
}
|
|
7435
7422
|
var intCoercer = (v) => Number.isFinite(v) ? Math.trunc(v) : null;
|
|
@@ -7472,7 +7459,7 @@ class FieldComp extends Field {
|
|
|
7472
7459
|
}
|
|
7473
7460
|
var NONE2 = Symbol("NONE");
|
|
7474
7461
|
function extendProtoForKeyed(proto, name, uname) {
|
|
7475
|
-
|
|
7462
|
+
extendProtoSized(proto, name, uname, EMPTY_LIST);
|
|
7476
7463
|
proto[`setIn${uname}At`] = function(i, v) {
|
|
7477
7464
|
return this.set(name, this.get(name).set(i, v));
|
|
7478
7465
|
};
|
|
@@ -7488,11 +7475,13 @@ function extendProtoForKeyed(proto, name, uname) {
|
|
|
7488
7475
|
console.warn("key", i, "not found in", name, col);
|
|
7489
7476
|
return this;
|
|
7490
7477
|
};
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
proto[`deleteIn${uname}
|
|
7495
|
-
|
|
7478
|
+
extendDeleteInAt(proto, name, `${uname}At`);
|
|
7479
|
+
}
|
|
7480
|
+
function extendDeleteInAt(proto, name, uname) {
|
|
7481
|
+
proto[`deleteIn${uname}`] = function(v) {
|
|
7482
|
+
return this.set(name, this.get(name).delete(v));
|
|
7483
|
+
};
|
|
7484
|
+
proto[`removeIn${uname}`] = proto[`deleteIn${uname}`];
|
|
7496
7485
|
}
|
|
7497
7486
|
var EMPTY_LIST = List();
|
|
7498
7487
|
var listCoercer = (v) => Array.isArray(v) ? List(v) : null;
|
|
@@ -7532,12 +7521,12 @@ class FieldOMap extends Field {
|
|
|
7532
7521
|
extendProtoForKeyed(proto, this.name, uname);
|
|
7533
7522
|
}
|
|
7534
7523
|
}
|
|
7535
|
-
function
|
|
7536
|
-
proto[
|
|
7537
|
-
return this.get(name, defaultEmpty)
|
|
7524
|
+
function extendProtoSized(proto, name, uname, defaultEmpty, propName = "size") {
|
|
7525
|
+
proto[`is${uname}Empty`] = function() {
|
|
7526
|
+
return this.get(name, defaultEmpty)[propName] === 0;
|
|
7538
7527
|
};
|
|
7539
7528
|
proto[`${name}Len`] = function() {
|
|
7540
|
-
return this.get(name, defaultEmpty)
|
|
7529
|
+
return this.get(name, defaultEmpty)[propName];
|
|
7541
7530
|
};
|
|
7542
7531
|
}
|
|
7543
7532
|
var EMPTY_SET2 = Set2();
|
|
@@ -7549,14 +7538,11 @@ class FieldSet extends Field {
|
|
|
7549
7538
|
}
|
|
7550
7539
|
extendProtoForType(proto, uname) {
|
|
7551
7540
|
const { name } = this;
|
|
7552
|
-
|
|
7541
|
+
extendProtoSized(proto, name, uname, EMPTY_SET2);
|
|
7553
7542
|
proto[`addIn${uname}`] = function(v) {
|
|
7554
7543
|
return this.set(name, this.get(name).add(v));
|
|
7555
7544
|
};
|
|
7556
|
-
proto
|
|
7557
|
-
return this.set(name, this.get(name).delete(v));
|
|
7558
|
-
};
|
|
7559
|
-
proto[`removeIn${uname}`] = proto[`deleteIn${uname}`];
|
|
7545
|
+
extendDeleteInAt(proto, name, uname);
|
|
7560
7546
|
proto[`hasIn${uname}`] = function(v) {
|
|
7561
7547
|
return this.get(name).has(v);
|
|
7562
7548
|
};
|