jaxs 0.2.0 → 0.3.0
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/cypress/e2e/svg-renders.cy.js +10 -0
- package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js +71 -50
- package/cypress/jaxs-apps/dist/add-remove-root-children.3bb9b3f5.js.map +1 -1
- package/cypress/jaxs-apps/dist/svg.04290504.js +644 -0
- package/cypress/jaxs-apps/dist/svg.04290504.js.map +1 -0
- package/cypress/jaxs-apps/dist/svg.html +11 -0
- package/cypress/jaxs-apps/svg.html +11 -0
- package/cypress/jaxs-apps/svg.jsx +15 -0
- package/dist/jaxs.js +67 -34
- package/package.json +3 -2
- package/src/debugging.js +3 -3
- package/src/rendering/change/instructions/attributes.ts +5 -2
- package/src/rendering/change/instructions/children.ts +22 -23
- package/src/rendering/change/instructions/element.ts +8 -1
- package/src/rendering/change/instructions/events.ts +1 -1
- package/src/rendering/change/instructions/generate.ts +2 -2
- package/src/rendering/change/instructions/node.ts +19 -2
- package/src/rendering/change/instructions/text.ts +1 -1
- package/src/rendering/change.ts +17 -9
- package/src/rendering/dom/attributesAndEvents.ts +1 -1
- package/src/rendering/dom/create.ts +1 -1
- package/src/rendering/dom/svg.ts +18 -0
- package/src/rendering/templates/children.ts +10 -2
- package/src/rendering/templates/tag.ts +23 -1
- package/src/types.ts +4 -1
- package/.parcel-cache/6f14daf302269614-BundleGraph-0 +0 -0
- package/.parcel-cache/7d3d872b02d671a6-AssetGraph-0 +0 -0
- package/.parcel-cache/8e029bb14f8992df-RequestGraph-0 +0 -0
- package/.parcel-cache/a5394978e4ece10b-AssetGraph-0 +0 -0
- package/.parcel-cache/b5686051ae060930.txt +0 -2
- package/.parcel-cache/data.mdb +0 -0
- package/.parcel-cache/lock.mdb +0 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
describe('SVG rendering', () => {
|
|
2
|
+
beforeEach(() => {
|
|
3
|
+
cy.visit('http://localhost:1234/svg.html')
|
|
4
|
+
})
|
|
5
|
+
|
|
6
|
+
it('has the correct size because it is correctly setup as svg', () => {
|
|
7
|
+
cy.get('svg').invoke('outerWidth').should('be.eq', 24)
|
|
8
|
+
cy.get('svg').invoke('outerHeight').should('be.eq', 24)
|
|
9
|
+
})
|
|
10
|
+
})
|
|
@@ -654,6 +654,19 @@ var normalizeValueForKey = (object, key, defaultValue = "")=>{
|
|
|
654
654
|
if (object[key] === undefined) return defaultValue;
|
|
655
655
|
return object[key];
|
|
656
656
|
};
|
|
657
|
+
// src/rendering/dom/svg.ts
|
|
658
|
+
var namespace = "http://www.w3.org/2000/svg";
|
|
659
|
+
var isSvgTag = (tagType)=>tagType === "svg";
|
|
660
|
+
var isSvg = (element)=>element.namespaceURI === namespace;
|
|
661
|
+
var createSvgNode = (type, attributes, renderKit)=>{
|
|
662
|
+
const document = renderKit && renderKit.document || window.document;
|
|
663
|
+
const node = document.createElementNS(namespace, type);
|
|
664
|
+
for(const key in attributes){
|
|
665
|
+
if (key === "__self" || key === "xmlns") continue;
|
|
666
|
+
node.setAttributeNS(null, key, attributes[key]);
|
|
667
|
+
}
|
|
668
|
+
return node;
|
|
669
|
+
};
|
|
657
670
|
// src/rendering/templates/text.ts
|
|
658
671
|
class TextTemplate {
|
|
659
672
|
value;
|
|
@@ -697,13 +710,20 @@ var isTextNode = (child)=>{
|
|
|
697
710
|
var textNode = (content)=>{
|
|
698
711
|
return new TextTemplate(content);
|
|
699
712
|
};
|
|
713
|
+
var withSvgFlag = (isSvg2)=>(template)=>{
|
|
714
|
+
template && (template.isSvg = template.isSvg || isSvg2);
|
|
715
|
+
return template;
|
|
716
|
+
};
|
|
700
717
|
class Children {
|
|
701
718
|
collection;
|
|
702
719
|
parentElement;
|
|
703
|
-
|
|
720
|
+
isSvg;
|
|
721
|
+
constructor(jsxChildren, isSvg2 = false){
|
|
704
722
|
this.collection = ensureArray(jsxChildren);
|
|
705
723
|
this.collection = this.collection.map(replaceTextNodes);
|
|
706
724
|
this.collection = this.collection.flat();
|
|
725
|
+
this.collection = this.collection.map(withSvgFlag(isSvg2));
|
|
726
|
+
this.isSvg = isSvg2;
|
|
707
727
|
}
|
|
708
728
|
render(renderKit, parentElement) {
|
|
709
729
|
this.parentElement = parentElement;
|
|
@@ -726,12 +746,14 @@ class Tag {
|
|
|
726
746
|
events;
|
|
727
747
|
attributes;
|
|
728
748
|
children;
|
|
729
|
-
|
|
749
|
+
isSvg;
|
|
750
|
+
constructor(tagType, combinedAttributes, children2, isSvg2 = false){
|
|
730
751
|
this.type = tagType;
|
|
731
752
|
const { events, attributes } = separateAttrsAndEvents(combinedAttributes);
|
|
732
753
|
this.events = events;
|
|
733
754
|
this.attributes = attributes;
|
|
734
|
-
this.
|
|
755
|
+
this.isSvg = isSvg2 || isSvgTag(this.type);
|
|
756
|
+
this.children = new Children(children2, this.isSvg);
|
|
735
757
|
}
|
|
736
758
|
render(renderKit) {
|
|
737
759
|
const dom = this.generateDom(renderKit);
|
|
@@ -742,10 +764,19 @@ class Tag {
|
|
|
742
764
|
];
|
|
743
765
|
}
|
|
744
766
|
generateDom(renderKit) {
|
|
767
|
+
if (this.isSvg) return this.generateSvnDom(renderKit);
|
|
768
|
+
else return this.generateHtmlDom(renderKit);
|
|
769
|
+
}
|
|
770
|
+
generateHtmlDom(renderKit) {
|
|
745
771
|
const node = createDecoratedNode(this.type, this.attributes, this.events, renderKit);
|
|
746
772
|
node.__jsx = this.key();
|
|
747
773
|
return node;
|
|
748
774
|
}
|
|
775
|
+
generateSvnDom(renderKit) {
|
|
776
|
+
const node = createSvgNode(this.type, this.attributes, renderKit);
|
|
777
|
+
node.__jsx = this.key();
|
|
778
|
+
return node;
|
|
779
|
+
}
|
|
749
780
|
key() {
|
|
750
781
|
return this.attributes.key || this.source() || this.createKey();
|
|
751
782
|
}
|
|
@@ -1101,7 +1132,7 @@ var createIdMap = (list)=>{
|
|
|
1101
1132
|
return map;
|
|
1102
1133
|
};
|
|
1103
1134
|
// src/rendering/change/instructions/attributes.ts
|
|
1104
|
-
var compileForAttributes = (source, target)=>{
|
|
1135
|
+
var compileForAttributes = (source, target, isSvg2 = false)=>{
|
|
1105
1136
|
const instructions = [];
|
|
1106
1137
|
const sourceAttributes = source.attributes;
|
|
1107
1138
|
const sourceLength = sourceAttributes.length;
|
|
@@ -1123,11 +1154,13 @@ var compileForAttributes = (source, target)=>{
|
|
|
1123
1154
|
}
|
|
1124
1155
|
}
|
|
1125
1156
|
if (!matchingAttribute) instructions.push(removeAttribute(source, target, {
|
|
1126
|
-
name: sourceAttribute.name
|
|
1157
|
+
name: sourceAttribute.name,
|
|
1158
|
+
isSvg: isSvg2
|
|
1127
1159
|
}));
|
|
1128
1160
|
else if (sourceAttribute.value !== matchingAttribute.value) instructions.push(updateAttribute(source, target, {
|
|
1129
1161
|
name: sourceAttribute.name,
|
|
1130
|
-
value: matchingAttribute.value
|
|
1162
|
+
value: matchingAttribute.value,
|
|
1163
|
+
isSvg: isSvg2
|
|
1131
1164
|
}));
|
|
1132
1165
|
}
|
|
1133
1166
|
for(index = 0; index < targetLength; index++){
|
|
@@ -1144,7 +1177,8 @@ var compileForAttributes = (source, target)=>{
|
|
|
1144
1177
|
}
|
|
1145
1178
|
if (!matchingAttribute) instructions.push(addAttribute(source, target, {
|
|
1146
1179
|
name: targetAttribute.name,
|
|
1147
|
-
value: targetAttribute.value
|
|
1180
|
+
value: targetAttribute.value,
|
|
1181
|
+
isSvg: isSvg2
|
|
1148
1182
|
}));
|
|
1149
1183
|
}
|
|
1150
1184
|
return instructions;
|
|
@@ -1186,6 +1220,9 @@ var compileForElement = (source, target)=>{
|
|
|
1186
1220
|
const valueInstructions = compileForInputValue(source, target);
|
|
1187
1221
|
return attributeInstructions.concat(eventInstructions).concat(valueInstructions);
|
|
1188
1222
|
};
|
|
1223
|
+
var compileForSvg = (source, target)=>{
|
|
1224
|
+
return compileForAttributes(source, target, true);
|
|
1225
|
+
};
|
|
1189
1226
|
var compileForInputValue = (sourceElement, targetElement)=>{
|
|
1190
1227
|
const instructions = [];
|
|
1191
1228
|
if (sourceElement.tagName !== "INPUT") return instructions;
|
|
@@ -1212,7 +1249,13 @@ var NodeTypes;
|
|
|
1212
1249
|
})(NodeTypes || (NodeTypes = {}));
|
|
1213
1250
|
var compileForNodeGenerator = (compileForCollection)=>(source, target)=>{
|
|
1214
1251
|
let instructions = [];
|
|
1215
|
-
if (source.nodeType === NodeTypes.ElementNode) {
|
|
1252
|
+
if (source.nodeType === NodeTypes.ElementNode && isSvg(source)) {
|
|
1253
|
+
const sourceElement = source;
|
|
1254
|
+
const targetElement = target;
|
|
1255
|
+
const baseInstructions = compileForSvg(sourceElement, targetElement);
|
|
1256
|
+
const childrenInstructions = compileForCollection(sourceElement.childNodes, targetElement.childNodes, sourceElement);
|
|
1257
|
+
instructions = baseInstructions.concat(childrenInstructions);
|
|
1258
|
+
} else if (source.nodeType === NodeTypes.ElementNode) {
|
|
1216
1259
|
const sourceElement = source;
|
|
1217
1260
|
const targetElement = target;
|
|
1218
1261
|
const baseInstructions = compileForElement(sourceElement, targetElement);
|
|
@@ -1221,8 +1264,6 @@ var compileForNodeGenerator = (compileForCollection)=>(source, target)=>{
|
|
|
1221
1264
|
} else if (source.nodeType === NodeTypes.TextNode) instructions = compileForText(source, target);
|
|
1222
1265
|
return instructions;
|
|
1223
1266
|
};
|
|
1224
|
-
// src/debugging.js
|
|
1225
|
-
var debug = (...message)=>{};
|
|
1226
1267
|
// src/rendering/change/instructions/children.ts
|
|
1227
1268
|
var compileChildren = (sourceList, targetList, parent)=>{
|
|
1228
1269
|
const baseInstructions = [];
|
|
@@ -1234,55 +1275,37 @@ var compileChildren = (sourceList, targetList, parent)=>{
|
|
|
1234
1275
|
for(; index < length; index++){
|
|
1235
1276
|
const source = sourceList[index];
|
|
1236
1277
|
const target = targetList[index];
|
|
1237
|
-
debug("\n", "loop index", index, source && source.__jsx, target && target.__jsx);
|
|
1238
1278
|
if (target && targetMap.check(target)) {
|
|
1239
|
-
debug("target", target.__jsx, "index", index);
|
|
1240
1279
|
const matchingSource = sourceMap.pullMatch(target);
|
|
1241
1280
|
targetMap.clear(target);
|
|
1242
1281
|
if (matchingSource.element) {
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
parent,
|
|
1248
|
-
index
|
|
1249
|
-
}));
|
|
1250
|
-
}
|
|
1251
|
-
debug("updating to match target", matchingSource.element.__jsx, matchingSource.element.classList, target.__jsx, target.classList);
|
|
1282
|
+
if (matchingSource.index !== index) baseInstructions.push(insertNode(matchingSource.element, {
|
|
1283
|
+
parent,
|
|
1284
|
+
index
|
|
1285
|
+
}));
|
|
1252
1286
|
nodesPairsToDiff.push({
|
|
1253
1287
|
source: matchingSource.element,
|
|
1254
1288
|
target
|
|
1255
1289
|
});
|
|
1256
1290
|
} else if (source) {
|
|
1257
|
-
|
|
1258
|
-
if (targetMap.check(source)) {
|
|
1259
|
-
debug("adding", target.__jsx, "at", index);
|
|
1260
|
-
baseInstructions.push(insertNode(target, {
|
|
1261
|
-
parent,
|
|
1262
|
-
index
|
|
1263
|
-
}));
|
|
1264
|
-
} else {
|
|
1265
|
-
debug("replacing", source.__jsx, target.__jsx, "at", index);
|
|
1266
|
-
sourceMap.clear(source);
|
|
1267
|
-
baseInstructions.push(replaceNode(source, target));
|
|
1268
|
-
}
|
|
1269
|
-
} else {
|
|
1270
|
-
debug("adding target to end", target.__jsx);
|
|
1271
|
-
baseInstructions.push(insertNode(target, {
|
|
1291
|
+
if (targetMap.check(source)) baseInstructions.push(insertNode(target, {
|
|
1272
1292
|
parent,
|
|
1273
1293
|
index
|
|
1274
1294
|
}));
|
|
1275
|
-
|
|
1295
|
+
else {
|
|
1296
|
+
sourceMap.clear(source);
|
|
1297
|
+
baseInstructions.push(replaceNode(source, target));
|
|
1298
|
+
}
|
|
1299
|
+
} else baseInstructions.push(insertNode(target, {
|
|
1300
|
+
parent,
|
|
1301
|
+
index
|
|
1302
|
+
}));
|
|
1276
1303
|
} else if (source) {
|
|
1277
1304
|
const matchingSource = sourceMap.pullMatch(source);
|
|
1278
|
-
if (matchingSource.element)
|
|
1279
|
-
debug("removing", source.__jsx);
|
|
1280
|
-
baseInstructions.push(removeNode(source));
|
|
1281
|
-
}
|
|
1305
|
+
if (matchingSource.element) baseInstructions.push(removeNode(source));
|
|
1282
1306
|
}
|
|
1283
1307
|
}
|
|
1284
1308
|
sourceMap.remaining().forEach(({ element: element2 })=>{
|
|
1285
|
-
debug("removing", element2.__jsx);
|
|
1286
1309
|
baseInstructions.push(removeNode(element2));
|
|
1287
1310
|
});
|
|
1288
1311
|
const nodeInstructions = nodesPairsToDiff.reduce((collection, { source, target })=>{
|
|
@@ -1304,7 +1327,6 @@ var compileForNode = compileForNodeGenerator(compileChildren);
|
|
|
1304
1327
|
// src/rendering/change.ts
|
|
1305
1328
|
var change = (source, target, parent)=>{
|
|
1306
1329
|
const instructions = compileChildren(source, target, parent);
|
|
1307
|
-
debug("instructions", instructions.map((instruction)=>instruction.type));
|
|
1308
1330
|
instructions.forEach((instruction)=>{
|
|
1309
1331
|
performInstruction(instruction);
|
|
1310
1332
|
});
|
|
@@ -1321,7 +1343,6 @@ var changeText2 = (instruction)=>{
|
|
|
1321
1343
|
var removeNode2 = (instruction)=>{
|
|
1322
1344
|
const { source } = instruction;
|
|
1323
1345
|
source.remove();
|
|
1324
|
-
debug("removeNode called on", source.nodeName);
|
|
1325
1346
|
};
|
|
1326
1347
|
var insertNode2 = (instruction)=>{
|
|
1327
1348
|
const { target, data } = instruction;
|
|
@@ -1333,18 +1354,18 @@ var insertNode2 = (instruction)=>{
|
|
|
1333
1354
|
var replaceNode2 = (instruction)=>{
|
|
1334
1355
|
const { source, target } = instruction;
|
|
1335
1356
|
source.replaceWith(target);
|
|
1336
|
-
debug("replaceNode called on", source.nodeName, "with", target.nodeName);
|
|
1337
|
-
debug("parent", source.parentElement);
|
|
1338
1357
|
};
|
|
1339
1358
|
var removeAttribute2 = (instruction)=>{
|
|
1340
1359
|
const { source, data } = instruction;
|
|
1341
|
-
const { name } = data;
|
|
1342
|
-
source.
|
|
1360
|
+
const { name, isSvg: isSvg2 } = data;
|
|
1361
|
+
if (isSvg2) source.removeAttributeNS(null, name);
|
|
1362
|
+
else source.removeAttribute(name);
|
|
1343
1363
|
};
|
|
1344
1364
|
var addAttribute2 = (instruction)=>{
|
|
1345
1365
|
const { source, data } = instruction;
|
|
1346
|
-
const { name, value } = data;
|
|
1347
|
-
source.
|
|
1366
|
+
const { name, value, isSvg: isSvg2 } = data;
|
|
1367
|
+
if (isSvg2) source.setAttributeNS(null, name, value);
|
|
1368
|
+
else source.setAttribute(name, value);
|
|
1348
1369
|
};
|
|
1349
1370
|
var updateAttribute2 = (instruction)=>{
|
|
1350
1371
|
addAttribute2(instruction);
|