@viewfly/core 0.2.1 → 0.2.3
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/bundles/foundation/_utils.d.ts +1 -0
- package/bundles/foundation/injection-tokens.d.ts +14 -14
- package/bundles/index.esm.js +95 -89
- package/bundles/index.js +95 -89
- package/package.json +2 -2
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export type NativeNode = Record<string, any>;
|
|
2
2
|
export declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode = NativeNode> {
|
|
3
|
-
abstract createElement(name: string): ElementNode;
|
|
4
|
-
abstract createTextNode(textContent: string): TextNode;
|
|
5
|
-
abstract setProperty(node: ElementNode, key: string, value: any): void;
|
|
6
|
-
abstract appendChild(parent: ElementNode, newChild: ElementNode | TextNode): void;
|
|
7
|
-
abstract prependChild(parent: ElementNode, newChild: ElementNode | TextNode): void;
|
|
8
|
-
abstract removeProperty(node: ElementNode, key: string): void;
|
|
9
|
-
abstract setStyle(target: ElementNode, key: string, value: any): void;
|
|
10
|
-
abstract removeStyle(target: ElementNode, key: string): void;
|
|
11
|
-
abstract setClass(target: ElementNode, value: string): void;
|
|
12
|
-
abstract listen<T = any>(node: ElementNode, type: string, callback: (ev: T) => any): void;
|
|
13
|
-
abstract unListen(node: ElementNode, type: string, callback: (ev: any) => any): void;
|
|
14
|
-
abstract remove(node: ElementNode | TextNode): void;
|
|
15
|
-
abstract syncTextContent(target: TextNode, content: string): void;
|
|
16
|
-
abstract insertAfter(newNode: ElementNode | TextNode, ref: ElementNode | TextNode): void;
|
|
3
|
+
abstract createElement(name: string, isSvg: boolean): ElementNode;
|
|
4
|
+
abstract createTextNode(textContent: string, isSvg: boolean): TextNode;
|
|
5
|
+
abstract setProperty(node: ElementNode, key: string, value: any, isSvg: boolean): void;
|
|
6
|
+
abstract appendChild(parent: ElementNode, newChild: ElementNode | TextNode, isSvg: boolean): void;
|
|
7
|
+
abstract prependChild(parent: ElementNode, newChild: ElementNode | TextNode, isSvg: boolean): void;
|
|
8
|
+
abstract removeProperty(node: ElementNode, key: string, isSvg: boolean): void;
|
|
9
|
+
abstract setStyle(target: ElementNode, key: string, value: any, isSvg: boolean): void;
|
|
10
|
+
abstract removeStyle(target: ElementNode, key: string, isSvg: boolean): void;
|
|
11
|
+
abstract setClass(target: ElementNode, value: string, isSvg: boolean): void;
|
|
12
|
+
abstract listen<T = any>(node: ElementNode, type: string, callback: (ev: T) => any, isSvg: boolean): void;
|
|
13
|
+
abstract unListen(node: ElementNode, type: string, callback: (ev: any) => any, isSvg: boolean): void;
|
|
14
|
+
abstract remove(node: ElementNode | TextNode, isSvg: boolean): void;
|
|
15
|
+
abstract syncTextContent(target: TextNode, content: string, isSvg: boolean): void;
|
|
16
|
+
abstract insertAfter(newNode: ElementNode | TextNode, ref: ElementNode | TextNode, isSvg: boolean): void;
|
|
17
17
|
}
|
package/bundles/index.esm.js
CHANGED
|
@@ -1212,14 +1212,15 @@ function createRenderer(component, nativeRenderer, version) {
|
|
|
1212
1212
|
let isInit = true;
|
|
1213
1213
|
return function render(host) {
|
|
1214
1214
|
if (isInit) {
|
|
1215
|
-
nativeRenderer.setProperty(host, 'viewfly-version', version);
|
|
1215
|
+
nativeRenderer.setProperty(host, 'viewfly-version', version, false);
|
|
1216
1216
|
isInit = false;
|
|
1217
1217
|
const atom = {
|
|
1218
1218
|
jsxNode: component,
|
|
1219
1219
|
parent: null,
|
|
1220
1220
|
sibling: null,
|
|
1221
1221
|
child: null,
|
|
1222
|
-
nativeNode: null
|
|
1222
|
+
nativeNode: null,
|
|
1223
|
+
isSvg: false
|
|
1223
1224
|
};
|
|
1224
1225
|
componentRender(nativeRenderer, component, atom, {
|
|
1225
1226
|
isParent: true,
|
|
@@ -1241,19 +1242,19 @@ function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
|
1241
1242
|
let nativeNode;
|
|
1242
1243
|
let applyRefs = null;
|
|
1243
1244
|
if (atom.jsxNode instanceof JSXElement) {
|
|
1244
|
-
const { nativeNode: n, applyRefs: a } = createElement(nativeRenderer, atom.jsxNode);
|
|
1245
|
+
const { nativeNode: n, applyRefs: a } = createElement(nativeRenderer, atom.jsxNode, atom.isSvg);
|
|
1245
1246
|
nativeNode = n;
|
|
1246
1247
|
applyRefs = a;
|
|
1247
1248
|
}
|
|
1248
1249
|
else {
|
|
1249
|
-
nativeNode = createTextNode(nativeRenderer, atom.jsxNode);
|
|
1250
|
+
nativeNode = createTextNode(nativeRenderer, atom.jsxNode, atom.isSvg);
|
|
1250
1251
|
}
|
|
1251
1252
|
atom.nativeNode = nativeNode;
|
|
1252
1253
|
if (context.isParent) {
|
|
1253
|
-
nativeRenderer.prependChild(context.host, nativeNode);
|
|
1254
|
+
nativeRenderer.prependChild(context.host, nativeNode, atom.isSvg);
|
|
1254
1255
|
}
|
|
1255
1256
|
else {
|
|
1256
|
-
nativeRenderer.insertAfter(nativeNode, context.host);
|
|
1257
|
+
nativeRenderer.insertAfter(nativeNode, context.host, atom.isSvg);
|
|
1257
1258
|
}
|
|
1258
1259
|
if (atom.jsxNode instanceof JSXElement) {
|
|
1259
1260
|
const childContext = {
|
|
@@ -1332,7 +1333,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1332
1333
|
}
|
|
1333
1334
|
const commits = [];
|
|
1334
1335
|
const changeCommits = {
|
|
1335
|
-
updateComponent: (newAtom, reusedAtom, expectIndex,
|
|
1336
|
+
updateComponent: (newAtom, reusedAtom, expectIndex, oldIndex) => {
|
|
1336
1337
|
commits.push((offset) => {
|
|
1337
1338
|
const instance = reusedAtom.jsxNode;
|
|
1338
1339
|
const newProps = newAtom.jsxNode.props;
|
|
@@ -1341,7 +1342,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1341
1342
|
instance.$$view = Object.assign({ atom: newAtom }, context);
|
|
1342
1343
|
newAtom.jsxNode = instance;
|
|
1343
1344
|
if (newTemplate === oldTemplate) {
|
|
1344
|
-
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex
|
|
1345
|
+
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
|
|
1345
1346
|
updateView(nativeRenderer, instance);
|
|
1346
1347
|
return;
|
|
1347
1348
|
}
|
|
@@ -1349,7 +1350,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1349
1350
|
linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
|
|
1350
1351
|
}
|
|
1351
1352
|
if (newAtom.child) {
|
|
1352
|
-
diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex,
|
|
1353
|
+
diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
|
|
1353
1354
|
}
|
|
1354
1355
|
else if (reusedAtom.child) {
|
|
1355
1356
|
let atom = reusedAtom.child;
|
|
@@ -1365,17 +1366,17 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1365
1366
|
commits.push((offset) => {
|
|
1366
1367
|
newAtom.nativeNode = oldAtom.nativeNode;
|
|
1367
1368
|
const host = context.host;
|
|
1368
|
-
if (expectIndex !== oldIndex
|
|
1369
|
+
if (expectIndex - offset !== oldIndex) {
|
|
1369
1370
|
if (context.isParent) {
|
|
1370
|
-
nativeRenderer.prependChild(host, newAtom.nativeNode);
|
|
1371
|
+
nativeRenderer.prependChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1371
1372
|
}
|
|
1372
1373
|
else {
|
|
1373
|
-
nativeRenderer.insertAfter(newAtom.nativeNode, host);
|
|
1374
|
+
nativeRenderer.insertAfter(newAtom.nativeNode, host, newAtom.isSvg);
|
|
1374
1375
|
}
|
|
1375
1376
|
}
|
|
1376
1377
|
context.host = newAtom.nativeNode;
|
|
1377
1378
|
context.isParent = false;
|
|
1378
|
-
const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode);
|
|
1379
|
+
const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode, newAtom.isSvg);
|
|
1379
1380
|
if (newAtom.child) {
|
|
1380
1381
|
diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
|
|
1381
1382
|
host: newAtom.nativeNode,
|
|
@@ -1396,7 +1397,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1396
1397
|
commits.push(() => {
|
|
1397
1398
|
const nativeNode = oldAtom.nativeNode;
|
|
1398
1399
|
if (newAtom.jsxNode.text !== oldAtom.jsxNode.text) {
|
|
1399
|
-
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode.text);
|
|
1400
|
+
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode.text, newAtom.isSvg);
|
|
1400
1401
|
}
|
|
1401
1402
|
newAtom.nativeNode = nativeNode;
|
|
1402
1403
|
context.host = nativeNode;
|
|
@@ -1406,6 +1407,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1406
1407
|
create: (start) => {
|
|
1407
1408
|
commits.push(() => {
|
|
1408
1409
|
buildView(nativeRenderer, parentComponent, start, context);
|
|
1410
|
+
offset++;
|
|
1409
1411
|
});
|
|
1410
1412
|
}
|
|
1411
1413
|
};
|
|
@@ -1424,7 +1426,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1424
1426
|
const commit = commits[i];
|
|
1425
1427
|
while (firstDiffAtomIndexed) {
|
|
1426
1428
|
if (firstDiffAtomIndexed.index <= i) {
|
|
1427
|
-
offset
|
|
1429
|
+
offset--;
|
|
1428
1430
|
firstDiffAtomIndexed = firstDiffAtomIndexed.next;
|
|
1429
1431
|
continue;
|
|
1430
1432
|
}
|
|
@@ -1433,40 +1435,6 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1433
1435
|
commit(offset);
|
|
1434
1436
|
}
|
|
1435
1437
|
}
|
|
1436
|
-
function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
|
|
1437
|
-
let child = reusedAtom.child;
|
|
1438
|
-
newAtom.child = child;
|
|
1439
|
-
const children = [];
|
|
1440
|
-
while (child) {
|
|
1441
|
-
children.push(child);
|
|
1442
|
-
child.parent = newAtom;
|
|
1443
|
-
child = child.sibling;
|
|
1444
|
-
}
|
|
1445
|
-
const updateContext = (atom) => {
|
|
1446
|
-
if (atom.jsxNode instanceof Component) {
|
|
1447
|
-
let child = atom.child;
|
|
1448
|
-
while (child) {
|
|
1449
|
-
updateContext(child);
|
|
1450
|
-
child = child.sibling;
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
else {
|
|
1454
|
-
if (moveView) {
|
|
1455
|
-
if (context.isParent) {
|
|
1456
|
-
nativeRenderer.prependChild(context.host, atom.nativeNode);
|
|
1457
|
-
}
|
|
1458
|
-
else {
|
|
1459
|
-
nativeRenderer.insertAfter(atom.nativeNode, context.host);
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
context.isParent = false;
|
|
1463
|
-
context.host = atom.nativeNode;
|
|
1464
|
-
}
|
|
1465
|
-
};
|
|
1466
|
-
for (const atom of children) {
|
|
1467
|
-
updateContext(atom);
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
1438
|
function createChanges(newAtom, expectIndex, diffAtomIndexed, changeCommits) {
|
|
1471
1439
|
const startDiffAtom = diffAtomIndexed;
|
|
1472
1440
|
while (diffAtomIndexed) {
|
|
@@ -1509,10 +1477,44 @@ function createChanges(newAtom, expectIndex, diffAtomIndexed, changeCommits) {
|
|
|
1509
1477
|
changeCommits.create(newAtom);
|
|
1510
1478
|
return startDiffAtom;
|
|
1511
1479
|
}
|
|
1480
|
+
function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
|
|
1481
|
+
let child = reusedAtom.child;
|
|
1482
|
+
newAtom.child = child;
|
|
1483
|
+
const children = [];
|
|
1484
|
+
while (child) {
|
|
1485
|
+
children.push(child);
|
|
1486
|
+
child.parent = newAtom;
|
|
1487
|
+
child = child.sibling;
|
|
1488
|
+
}
|
|
1489
|
+
const updateContext = (atom) => {
|
|
1490
|
+
if (atom.jsxNode instanceof Component) {
|
|
1491
|
+
let child = atom.child;
|
|
1492
|
+
while (child) {
|
|
1493
|
+
updateContext(child);
|
|
1494
|
+
child = child.sibling;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
else {
|
|
1498
|
+
if (moveView) {
|
|
1499
|
+
if (context.isParent) {
|
|
1500
|
+
nativeRenderer.prependChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1501
|
+
}
|
|
1502
|
+
else {
|
|
1503
|
+
nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.isSvg);
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
context.isParent = false;
|
|
1507
|
+
context.host = atom.nativeNode;
|
|
1508
|
+
}
|
|
1509
|
+
};
|
|
1510
|
+
for (const atom of children) {
|
|
1511
|
+
updateContext(atom);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1512
1514
|
function cleanView(nativeRenderer, atom, isClean) {
|
|
1513
1515
|
if (atom.nativeNode) {
|
|
1514
1516
|
if (!isClean) {
|
|
1515
|
-
nativeRenderer.remove(atom.nativeNode);
|
|
1517
|
+
nativeRenderer.remove(atom.nativeNode, atom.isSvg);
|
|
1516
1518
|
isClean = true;
|
|
1517
1519
|
}
|
|
1518
1520
|
if (atom.jsxNode instanceof JSXElement) {
|
|
@@ -1542,67 +1544,71 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1542
1544
|
}
|
|
1543
1545
|
component.rendered();
|
|
1544
1546
|
}
|
|
1545
|
-
function createChainByComponentFactory(jsxComponent, parent) {
|
|
1547
|
+
function createChainByComponentFactory(jsxComponent, parent, isSvg) {
|
|
1546
1548
|
return {
|
|
1547
1549
|
jsxNode: jsxComponent,
|
|
1548
1550
|
parent,
|
|
1549
1551
|
sibling: null,
|
|
1550
1552
|
child: null,
|
|
1551
|
-
nativeNode: null
|
|
1553
|
+
nativeNode: null,
|
|
1554
|
+
isSvg
|
|
1552
1555
|
};
|
|
1553
1556
|
}
|
|
1554
|
-
function createChainByJSXElement(component, element, parent) {
|
|
1557
|
+
function createChainByJSXElement(component, element, parent, isSvg) {
|
|
1558
|
+
isSvg = element.type === 'svg' || isSvg;
|
|
1555
1559
|
const atom = {
|
|
1556
1560
|
jsxNode: element,
|
|
1557
1561
|
parent,
|
|
1558
1562
|
sibling: null,
|
|
1559
1563
|
child: null,
|
|
1560
|
-
nativeNode: null
|
|
1564
|
+
nativeNode: null,
|
|
1565
|
+
isSvg
|
|
1561
1566
|
};
|
|
1562
1567
|
if (Reflect.has(element.props, 'children')) {
|
|
1563
1568
|
const jsxChildren = element.props.children;
|
|
1564
|
-
const children = createChainByChildren(component, Array.isArray(jsxChildren) ? jsxChildren : [jsxChildren], atom, []);
|
|
1569
|
+
const children = createChainByChildren(component, Array.isArray(jsxChildren) ? jsxChildren : [jsxChildren], atom, [], isSvg);
|
|
1565
1570
|
link(atom, children);
|
|
1566
1571
|
}
|
|
1567
1572
|
return atom;
|
|
1568
1573
|
}
|
|
1569
|
-
function createChainByJSXText(node, parent) {
|
|
1574
|
+
function createChainByJSXText(node, parent, isSvg) {
|
|
1570
1575
|
return {
|
|
1571
1576
|
jsxNode: node,
|
|
1572
1577
|
parent,
|
|
1573
1578
|
sibling: null,
|
|
1574
1579
|
child: null,
|
|
1575
|
-
nativeNode: null
|
|
1580
|
+
nativeNode: null,
|
|
1581
|
+
isSvg
|
|
1576
1582
|
};
|
|
1577
1583
|
}
|
|
1578
|
-
function createChainByChildren(component, children, parent, atoms) {
|
|
1584
|
+
function createChainByChildren(component, children, parent, atoms, isSvg) {
|
|
1579
1585
|
for (const item of children) {
|
|
1580
|
-
if (item !== null && typeof item !== 'undefined') {
|
|
1586
|
+
if (item !== null && typeof item !== 'undefined' && typeof item !== 'boolean') {
|
|
1581
1587
|
if (item instanceof JSXElement) {
|
|
1582
|
-
atoms.push(createChainByJSXElement(component, item, parent));
|
|
1588
|
+
atoms.push(createChainByJSXElement(component, item, parent, isSvg));
|
|
1583
1589
|
continue;
|
|
1584
1590
|
}
|
|
1585
1591
|
if (item instanceof JSXComponent) {
|
|
1586
|
-
const childAtom = createChainByComponentFactory(item, parent);
|
|
1592
|
+
const childAtom = createChainByComponentFactory(item, parent, isSvg);
|
|
1587
1593
|
atoms.push(childAtom);
|
|
1588
1594
|
continue;
|
|
1589
1595
|
}
|
|
1590
1596
|
if (typeof item === 'string' && item.length) {
|
|
1591
|
-
atoms.push(createChainByJSXText(new JSXText(item), parent));
|
|
1597
|
+
atoms.push(createChainByJSXText(new JSXText(item), parent, isSvg));
|
|
1592
1598
|
continue;
|
|
1593
1599
|
}
|
|
1594
1600
|
if (Array.isArray(item)) {
|
|
1595
|
-
createChainByChildren(component, item, parent, atoms);
|
|
1601
|
+
createChainByChildren(component, item, parent, atoms, isSvg);
|
|
1596
1602
|
continue;
|
|
1597
1603
|
}
|
|
1598
|
-
atoms.push(createChainByJSXText(new JSXText(String(item)), parent));
|
|
1604
|
+
atoms.push(createChainByJSXText(new JSXText(String(item)), parent, isSvg));
|
|
1599
1605
|
}
|
|
1600
1606
|
}
|
|
1601
1607
|
return atoms;
|
|
1602
1608
|
}
|
|
1603
1609
|
function linkTemplate(template, component, parent) {
|
|
1604
1610
|
const children = Array.isArray(template) ? template : [template];
|
|
1605
|
-
const newChildren = createChainByChildren(component, children, parent, []);
|
|
1611
|
+
const newChildren = createChainByChildren(component, children, parent, [], parent.isSvg);
|
|
1606
1612
|
link(parent, newChildren);
|
|
1607
1613
|
}
|
|
1608
1614
|
function link(parent, children) {
|
|
@@ -1612,8 +1618,8 @@ function link(parent, children) {
|
|
|
1612
1618
|
}
|
|
1613
1619
|
parent.child = children[0] || null;
|
|
1614
1620
|
}
|
|
1615
|
-
function createElement(nativeRenderer, vNode) {
|
|
1616
|
-
const nativeNode = nativeRenderer.createElement(vNode.type);
|
|
1621
|
+
function createElement(nativeRenderer, vNode, isSvg) {
|
|
1622
|
+
const nativeNode = nativeRenderer.createElement(vNode.type, isSvg);
|
|
1617
1623
|
const props = vNode.props;
|
|
1618
1624
|
let bindingRefs;
|
|
1619
1625
|
const keys = Object.keys(props);
|
|
@@ -1624,21 +1630,21 @@ function createElement(nativeRenderer, vNode) {
|
|
|
1624
1630
|
if (key === 'class') {
|
|
1625
1631
|
const className = classToString(props[key]);
|
|
1626
1632
|
if (className) {
|
|
1627
|
-
nativeRenderer.setClass(nativeNode, className);
|
|
1633
|
+
nativeRenderer.setClass(nativeNode, className, isSvg);
|
|
1628
1634
|
}
|
|
1629
1635
|
continue;
|
|
1630
1636
|
}
|
|
1631
1637
|
if (key === 'style') {
|
|
1632
1638
|
const style = styleToObject(props.style);
|
|
1633
1639
|
Object.keys(style).forEach(key => {
|
|
1634
|
-
nativeRenderer.setStyle(nativeNode, key, style[key]);
|
|
1640
|
+
nativeRenderer.setStyle(nativeNode, key, style[key], isSvg);
|
|
1635
1641
|
});
|
|
1636
1642
|
continue;
|
|
1637
1643
|
}
|
|
1638
1644
|
if (/^on[A-Z]/.test(key)) {
|
|
1639
1645
|
const listener = props[key];
|
|
1640
1646
|
if (typeof listener === 'function') {
|
|
1641
|
-
bindEvent(nativeRenderer, vNode, key, nativeNode, listener);
|
|
1647
|
+
bindEvent(nativeRenderer, vNode, key, nativeNode, listener, isSvg);
|
|
1642
1648
|
}
|
|
1643
1649
|
continue;
|
|
1644
1650
|
}
|
|
@@ -1646,7 +1652,7 @@ function createElement(nativeRenderer, vNode) {
|
|
|
1646
1652
|
bindingRefs = props[key];
|
|
1647
1653
|
continue;
|
|
1648
1654
|
}
|
|
1649
|
-
nativeRenderer.setProperty(nativeNode, key, props[key]);
|
|
1655
|
+
nativeRenderer.setProperty(nativeNode, key, props[key], isSvg);
|
|
1650
1656
|
}
|
|
1651
1657
|
return {
|
|
1652
1658
|
nativeNode,
|
|
@@ -1655,10 +1661,10 @@ function createElement(nativeRenderer, vNode) {
|
|
|
1655
1661
|
}
|
|
1656
1662
|
};
|
|
1657
1663
|
}
|
|
1658
|
-
function createTextNode(nativeRenderer, child) {
|
|
1659
|
-
return nativeRenderer.createTextNode(child.text);
|
|
1664
|
+
function createTextNode(nativeRenderer, child, isSvg) {
|
|
1665
|
+
return nativeRenderer.createTextNode(child.text, isSvg);
|
|
1660
1666
|
}
|
|
1661
|
-
function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNode) {
|
|
1667
|
+
function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNode, isSvg) {
|
|
1662
1668
|
const changes = getObjectChanges(newVNode.props, oldVNode.props);
|
|
1663
1669
|
let unBindRefs;
|
|
1664
1670
|
let bindRefs;
|
|
@@ -1667,12 +1673,12 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1667
1673
|
continue;
|
|
1668
1674
|
}
|
|
1669
1675
|
if (key === 'class') {
|
|
1670
|
-
nativeRenderer.setClass(nativeNode, '');
|
|
1676
|
+
nativeRenderer.setClass(nativeNode, '', isSvg);
|
|
1671
1677
|
continue;
|
|
1672
1678
|
}
|
|
1673
1679
|
if (key === 'style') {
|
|
1674
1680
|
Object.keys(styleToObject(value)).forEach(styleName => {
|
|
1675
|
-
nativeRenderer.removeStyle(nativeNode, styleName);
|
|
1681
|
+
nativeRenderer.removeStyle(nativeNode, styleName, isSvg);
|
|
1676
1682
|
});
|
|
1677
1683
|
continue;
|
|
1678
1684
|
}
|
|
@@ -1680,7 +1686,7 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1680
1686
|
if (typeof value === 'function') {
|
|
1681
1687
|
const type = key.replace(/^on/, '').toLowerCase();
|
|
1682
1688
|
const oldOn = oldVNode.on;
|
|
1683
|
-
nativeRenderer.unListen(nativeNode, type, oldOn[type].delegate);
|
|
1689
|
+
nativeRenderer.unListen(nativeNode, type, oldOn[type].delegate, isSvg);
|
|
1684
1690
|
Reflect.deleteProperty(oldOn, type);
|
|
1685
1691
|
}
|
|
1686
1692
|
continue;
|
|
@@ -1689,7 +1695,7 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1689
1695
|
unBindRefs = value;
|
|
1690
1696
|
continue;
|
|
1691
1697
|
}
|
|
1692
|
-
nativeRenderer.removeProperty(nativeNode, key);
|
|
1698
|
+
nativeRenderer.removeProperty(nativeNode, key, isSvg);
|
|
1693
1699
|
}
|
|
1694
1700
|
for (const [key, newValue, oldValue] of changes.replace) {
|
|
1695
1701
|
if (key === 'children') {
|
|
@@ -1699,17 +1705,17 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1699
1705
|
const oldClassName = classToString(oldValue);
|
|
1700
1706
|
const newClassName = classToString(newValue);
|
|
1701
1707
|
if (oldClassName !== newClassName) {
|
|
1702
|
-
nativeRenderer.setClass(nativeNode, newClassName);
|
|
1708
|
+
nativeRenderer.setClass(nativeNode, newClassName, isSvg);
|
|
1703
1709
|
}
|
|
1704
1710
|
continue;
|
|
1705
1711
|
}
|
|
1706
1712
|
if (key === 'style') {
|
|
1707
1713
|
const styleChanges = getObjectChanges(styleToObject(newValue) || {}, styleToObject(oldValue) || {});
|
|
1708
1714
|
for (const [styleName] of styleChanges.remove) {
|
|
1709
|
-
nativeRenderer.removeStyle(nativeNode, styleName);
|
|
1715
|
+
nativeRenderer.removeStyle(nativeNode, styleName, isSvg);
|
|
1710
1716
|
}
|
|
1711
1717
|
for (const [styleName, styleValue] of [...styleChanges.add, ...styleChanges.replace]) {
|
|
1712
|
-
nativeRenderer.setStyle(nativeNode, styleName, styleValue);
|
|
1718
|
+
nativeRenderer.setStyle(nativeNode, styleName, styleValue, isSvg);
|
|
1713
1719
|
}
|
|
1714
1720
|
continue;
|
|
1715
1721
|
}
|
|
@@ -1724,26 +1730,26 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1724
1730
|
bindRefs = newValue;
|
|
1725
1731
|
continue;
|
|
1726
1732
|
}
|
|
1727
|
-
nativeRenderer.setProperty(nativeNode, key, newValue);
|
|
1733
|
+
nativeRenderer.setProperty(nativeNode, key, newValue, isSvg);
|
|
1728
1734
|
}
|
|
1729
1735
|
for (const [key, value] of changes.add) {
|
|
1730
1736
|
if (key === 'children') {
|
|
1731
1737
|
continue;
|
|
1732
1738
|
}
|
|
1733
1739
|
if (key === 'class') {
|
|
1734
|
-
nativeRenderer.setClass(nativeNode, classToString(value));
|
|
1740
|
+
nativeRenderer.setClass(nativeNode, classToString(value), isSvg);
|
|
1735
1741
|
continue;
|
|
1736
1742
|
}
|
|
1737
1743
|
if (key === 'style') {
|
|
1738
1744
|
const styleObj = styleToObject(value);
|
|
1739
1745
|
Object.keys(styleObj).forEach(styleName => {
|
|
1740
|
-
nativeRenderer.setStyle(nativeNode, styleName, styleObj[styleName]);
|
|
1746
|
+
nativeRenderer.setStyle(nativeNode, styleName, styleObj[styleName], isSvg);
|
|
1741
1747
|
});
|
|
1742
1748
|
continue;
|
|
1743
1749
|
}
|
|
1744
1750
|
if (/^on[A-Z]/.test(key)) {
|
|
1745
1751
|
if (typeof value === 'function') {
|
|
1746
|
-
bindEvent(nativeRenderer, newVNode, key, nativeNode, value);
|
|
1752
|
+
bindEvent(nativeRenderer, newVNode, key, nativeNode, value, isSvg);
|
|
1747
1753
|
}
|
|
1748
1754
|
continue;
|
|
1749
1755
|
}
|
|
@@ -1751,7 +1757,7 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1751
1757
|
bindRefs = value;
|
|
1752
1758
|
continue;
|
|
1753
1759
|
}
|
|
1754
|
-
nativeRenderer.setProperty(nativeNode, key, value);
|
|
1760
|
+
nativeRenderer.setProperty(nativeNode, key, value, isSvg);
|
|
1755
1761
|
}
|
|
1756
1762
|
return () => {
|
|
1757
1763
|
applyRefs(unBindRefs, nativeNode, false);
|
|
@@ -1766,7 +1772,7 @@ function applyRefs(refs, nativeNode, binding) {
|
|
|
1766
1772
|
}
|
|
1767
1773
|
}
|
|
1768
1774
|
}
|
|
1769
|
-
function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn) {
|
|
1775
|
+
function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn, isSvg) {
|
|
1770
1776
|
let on = vNode.on;
|
|
1771
1777
|
if (!on) {
|
|
1772
1778
|
vNode.on = on = {};
|
|
@@ -1780,7 +1786,7 @@ function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn) {
|
|
|
1780
1786
|
listenFn
|
|
1781
1787
|
};
|
|
1782
1788
|
on[type] = delegateObj;
|
|
1783
|
-
nativeRenderer.listen(nativeNode, type, delegate);
|
|
1789
|
+
nativeRenderer.listen(nativeNode, type, delegate, isSvg);
|
|
1784
1790
|
}
|
|
1785
1791
|
|
|
1786
1792
|
/**
|
|
@@ -1802,7 +1808,7 @@ class RootComponent extends Component {
|
|
|
1802
1808
|
}
|
|
1803
1809
|
|
|
1804
1810
|
const viewflyErrorFn = makeError('Viewfly');
|
|
1805
|
-
const VERSION = "0.2.
|
|
1811
|
+
const VERSION = "0.2.2";
|
|
1806
1812
|
function viewfly(config) {
|
|
1807
1813
|
const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
|
|
1808
1814
|
const appProviders = [];
|
package/bundles/index.js
CHANGED
|
@@ -1214,14 +1214,15 @@ function createRenderer(component, nativeRenderer, version) {
|
|
|
1214
1214
|
let isInit = true;
|
|
1215
1215
|
return function render(host) {
|
|
1216
1216
|
if (isInit) {
|
|
1217
|
-
nativeRenderer.setProperty(host, 'viewfly-version', version);
|
|
1217
|
+
nativeRenderer.setProperty(host, 'viewfly-version', version, false);
|
|
1218
1218
|
isInit = false;
|
|
1219
1219
|
const atom = {
|
|
1220
1220
|
jsxNode: component,
|
|
1221
1221
|
parent: null,
|
|
1222
1222
|
sibling: null,
|
|
1223
1223
|
child: null,
|
|
1224
|
-
nativeNode: null
|
|
1224
|
+
nativeNode: null,
|
|
1225
|
+
isSvg: false
|
|
1225
1226
|
};
|
|
1226
1227
|
componentRender(nativeRenderer, component, atom, {
|
|
1227
1228
|
isParent: true,
|
|
@@ -1243,19 +1244,19 @@ function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
|
1243
1244
|
let nativeNode;
|
|
1244
1245
|
let applyRefs = null;
|
|
1245
1246
|
if (atom.jsxNode instanceof JSXElement) {
|
|
1246
|
-
const { nativeNode: n, applyRefs: a } = createElement(nativeRenderer, atom.jsxNode);
|
|
1247
|
+
const { nativeNode: n, applyRefs: a } = createElement(nativeRenderer, atom.jsxNode, atom.isSvg);
|
|
1247
1248
|
nativeNode = n;
|
|
1248
1249
|
applyRefs = a;
|
|
1249
1250
|
}
|
|
1250
1251
|
else {
|
|
1251
|
-
nativeNode = createTextNode(nativeRenderer, atom.jsxNode);
|
|
1252
|
+
nativeNode = createTextNode(nativeRenderer, atom.jsxNode, atom.isSvg);
|
|
1252
1253
|
}
|
|
1253
1254
|
atom.nativeNode = nativeNode;
|
|
1254
1255
|
if (context.isParent) {
|
|
1255
|
-
nativeRenderer.prependChild(context.host, nativeNode);
|
|
1256
|
+
nativeRenderer.prependChild(context.host, nativeNode, atom.isSvg);
|
|
1256
1257
|
}
|
|
1257
1258
|
else {
|
|
1258
|
-
nativeRenderer.insertAfter(nativeNode, context.host);
|
|
1259
|
+
nativeRenderer.insertAfter(nativeNode, context.host, atom.isSvg);
|
|
1259
1260
|
}
|
|
1260
1261
|
if (atom.jsxNode instanceof JSXElement) {
|
|
1261
1262
|
const childContext = {
|
|
@@ -1334,7 +1335,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1334
1335
|
}
|
|
1335
1336
|
const commits = [];
|
|
1336
1337
|
const changeCommits = {
|
|
1337
|
-
updateComponent: (newAtom, reusedAtom, expectIndex,
|
|
1338
|
+
updateComponent: (newAtom, reusedAtom, expectIndex, oldIndex) => {
|
|
1338
1339
|
commits.push((offset) => {
|
|
1339
1340
|
const instance = reusedAtom.jsxNode;
|
|
1340
1341
|
const newProps = newAtom.jsxNode.props;
|
|
@@ -1343,7 +1344,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1343
1344
|
instance.$$view = Object.assign({ atom: newAtom }, context);
|
|
1344
1345
|
newAtom.jsxNode = instance;
|
|
1345
1346
|
if (newTemplate === oldTemplate) {
|
|
1346
|
-
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex
|
|
1347
|
+
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
|
|
1347
1348
|
updateView(nativeRenderer, instance);
|
|
1348
1349
|
return;
|
|
1349
1350
|
}
|
|
@@ -1351,7 +1352,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1351
1352
|
linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
|
|
1352
1353
|
}
|
|
1353
1354
|
if (newAtom.child) {
|
|
1354
|
-
diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex,
|
|
1355
|
+
diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
|
|
1355
1356
|
}
|
|
1356
1357
|
else if (reusedAtom.child) {
|
|
1357
1358
|
let atom = reusedAtom.child;
|
|
@@ -1367,17 +1368,17 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1367
1368
|
commits.push((offset) => {
|
|
1368
1369
|
newAtom.nativeNode = oldAtom.nativeNode;
|
|
1369
1370
|
const host = context.host;
|
|
1370
|
-
if (expectIndex !== oldIndex
|
|
1371
|
+
if (expectIndex - offset !== oldIndex) {
|
|
1371
1372
|
if (context.isParent) {
|
|
1372
|
-
nativeRenderer.prependChild(host, newAtom.nativeNode);
|
|
1373
|
+
nativeRenderer.prependChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1373
1374
|
}
|
|
1374
1375
|
else {
|
|
1375
|
-
nativeRenderer.insertAfter(newAtom.nativeNode, host);
|
|
1376
|
+
nativeRenderer.insertAfter(newAtom.nativeNode, host, newAtom.isSvg);
|
|
1376
1377
|
}
|
|
1377
1378
|
}
|
|
1378
1379
|
context.host = newAtom.nativeNode;
|
|
1379
1380
|
context.isParent = false;
|
|
1380
|
-
const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode);
|
|
1381
|
+
const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode, newAtom.isSvg);
|
|
1381
1382
|
if (newAtom.child) {
|
|
1382
1383
|
diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
|
|
1383
1384
|
host: newAtom.nativeNode,
|
|
@@ -1398,7 +1399,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1398
1399
|
commits.push(() => {
|
|
1399
1400
|
const nativeNode = oldAtom.nativeNode;
|
|
1400
1401
|
if (newAtom.jsxNode.text !== oldAtom.jsxNode.text) {
|
|
1401
|
-
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode.text);
|
|
1402
|
+
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode.text, newAtom.isSvg);
|
|
1402
1403
|
}
|
|
1403
1404
|
newAtom.nativeNode = nativeNode;
|
|
1404
1405
|
context.host = nativeNode;
|
|
@@ -1408,6 +1409,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1408
1409
|
create: (start) => {
|
|
1409
1410
|
commits.push(() => {
|
|
1410
1411
|
buildView(nativeRenderer, parentComponent, start, context);
|
|
1412
|
+
offset++;
|
|
1411
1413
|
});
|
|
1412
1414
|
}
|
|
1413
1415
|
};
|
|
@@ -1426,7 +1428,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1426
1428
|
const commit = commits[i];
|
|
1427
1429
|
while (firstDiffAtomIndexed) {
|
|
1428
1430
|
if (firstDiffAtomIndexed.index <= i) {
|
|
1429
|
-
offset
|
|
1431
|
+
offset--;
|
|
1430
1432
|
firstDiffAtomIndexed = firstDiffAtomIndexed.next;
|
|
1431
1433
|
continue;
|
|
1432
1434
|
}
|
|
@@ -1435,40 +1437,6 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1435
1437
|
commit(offset);
|
|
1436
1438
|
}
|
|
1437
1439
|
}
|
|
1438
|
-
function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
|
|
1439
|
-
let child = reusedAtom.child;
|
|
1440
|
-
newAtom.child = child;
|
|
1441
|
-
const children = [];
|
|
1442
|
-
while (child) {
|
|
1443
|
-
children.push(child);
|
|
1444
|
-
child.parent = newAtom;
|
|
1445
|
-
child = child.sibling;
|
|
1446
|
-
}
|
|
1447
|
-
const updateContext = (atom) => {
|
|
1448
|
-
if (atom.jsxNode instanceof Component) {
|
|
1449
|
-
let child = atom.child;
|
|
1450
|
-
while (child) {
|
|
1451
|
-
updateContext(child);
|
|
1452
|
-
child = child.sibling;
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
else {
|
|
1456
|
-
if (moveView) {
|
|
1457
|
-
if (context.isParent) {
|
|
1458
|
-
nativeRenderer.prependChild(context.host, atom.nativeNode);
|
|
1459
|
-
}
|
|
1460
|
-
else {
|
|
1461
|
-
nativeRenderer.insertAfter(atom.nativeNode, context.host);
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
context.isParent = false;
|
|
1465
|
-
context.host = atom.nativeNode;
|
|
1466
|
-
}
|
|
1467
|
-
};
|
|
1468
|
-
for (const atom of children) {
|
|
1469
|
-
updateContext(atom);
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
1440
|
function createChanges(newAtom, expectIndex, diffAtomIndexed, changeCommits) {
|
|
1473
1441
|
const startDiffAtom = diffAtomIndexed;
|
|
1474
1442
|
while (diffAtomIndexed) {
|
|
@@ -1511,10 +1479,44 @@ function createChanges(newAtom, expectIndex, diffAtomIndexed, changeCommits) {
|
|
|
1511
1479
|
changeCommits.create(newAtom);
|
|
1512
1480
|
return startDiffAtom;
|
|
1513
1481
|
}
|
|
1482
|
+
function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
|
|
1483
|
+
let child = reusedAtom.child;
|
|
1484
|
+
newAtom.child = child;
|
|
1485
|
+
const children = [];
|
|
1486
|
+
while (child) {
|
|
1487
|
+
children.push(child);
|
|
1488
|
+
child.parent = newAtom;
|
|
1489
|
+
child = child.sibling;
|
|
1490
|
+
}
|
|
1491
|
+
const updateContext = (atom) => {
|
|
1492
|
+
if (atom.jsxNode instanceof Component) {
|
|
1493
|
+
let child = atom.child;
|
|
1494
|
+
while (child) {
|
|
1495
|
+
updateContext(child);
|
|
1496
|
+
child = child.sibling;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
else {
|
|
1500
|
+
if (moveView) {
|
|
1501
|
+
if (context.isParent) {
|
|
1502
|
+
nativeRenderer.prependChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1503
|
+
}
|
|
1504
|
+
else {
|
|
1505
|
+
nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.isSvg);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
context.isParent = false;
|
|
1509
|
+
context.host = atom.nativeNode;
|
|
1510
|
+
}
|
|
1511
|
+
};
|
|
1512
|
+
for (const atom of children) {
|
|
1513
|
+
updateContext(atom);
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1514
1516
|
function cleanView(nativeRenderer, atom, isClean) {
|
|
1515
1517
|
if (atom.nativeNode) {
|
|
1516
1518
|
if (!isClean) {
|
|
1517
|
-
nativeRenderer.remove(atom.nativeNode);
|
|
1519
|
+
nativeRenderer.remove(atom.nativeNode, atom.isSvg);
|
|
1518
1520
|
isClean = true;
|
|
1519
1521
|
}
|
|
1520
1522
|
if (atom.jsxNode instanceof JSXElement) {
|
|
@@ -1544,67 +1546,71 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1544
1546
|
}
|
|
1545
1547
|
component.rendered();
|
|
1546
1548
|
}
|
|
1547
|
-
function createChainByComponentFactory(jsxComponent, parent) {
|
|
1549
|
+
function createChainByComponentFactory(jsxComponent, parent, isSvg) {
|
|
1548
1550
|
return {
|
|
1549
1551
|
jsxNode: jsxComponent,
|
|
1550
1552
|
parent,
|
|
1551
1553
|
sibling: null,
|
|
1552
1554
|
child: null,
|
|
1553
|
-
nativeNode: null
|
|
1555
|
+
nativeNode: null,
|
|
1556
|
+
isSvg
|
|
1554
1557
|
};
|
|
1555
1558
|
}
|
|
1556
|
-
function createChainByJSXElement(component, element, parent) {
|
|
1559
|
+
function createChainByJSXElement(component, element, parent, isSvg) {
|
|
1560
|
+
isSvg = element.type === 'svg' || isSvg;
|
|
1557
1561
|
const atom = {
|
|
1558
1562
|
jsxNode: element,
|
|
1559
1563
|
parent,
|
|
1560
1564
|
sibling: null,
|
|
1561
1565
|
child: null,
|
|
1562
|
-
nativeNode: null
|
|
1566
|
+
nativeNode: null,
|
|
1567
|
+
isSvg
|
|
1563
1568
|
};
|
|
1564
1569
|
if (Reflect.has(element.props, 'children')) {
|
|
1565
1570
|
const jsxChildren = element.props.children;
|
|
1566
|
-
const children = createChainByChildren(component, Array.isArray(jsxChildren) ? jsxChildren : [jsxChildren], atom, []);
|
|
1571
|
+
const children = createChainByChildren(component, Array.isArray(jsxChildren) ? jsxChildren : [jsxChildren], atom, [], isSvg);
|
|
1567
1572
|
link(atom, children);
|
|
1568
1573
|
}
|
|
1569
1574
|
return atom;
|
|
1570
1575
|
}
|
|
1571
|
-
function createChainByJSXText(node, parent) {
|
|
1576
|
+
function createChainByJSXText(node, parent, isSvg) {
|
|
1572
1577
|
return {
|
|
1573
1578
|
jsxNode: node,
|
|
1574
1579
|
parent,
|
|
1575
1580
|
sibling: null,
|
|
1576
1581
|
child: null,
|
|
1577
|
-
nativeNode: null
|
|
1582
|
+
nativeNode: null,
|
|
1583
|
+
isSvg
|
|
1578
1584
|
};
|
|
1579
1585
|
}
|
|
1580
|
-
function createChainByChildren(component, children, parent, atoms) {
|
|
1586
|
+
function createChainByChildren(component, children, parent, atoms, isSvg) {
|
|
1581
1587
|
for (const item of children) {
|
|
1582
|
-
if (item !== null && typeof item !== 'undefined') {
|
|
1588
|
+
if (item !== null && typeof item !== 'undefined' && typeof item !== 'boolean') {
|
|
1583
1589
|
if (item instanceof JSXElement) {
|
|
1584
|
-
atoms.push(createChainByJSXElement(component, item, parent));
|
|
1590
|
+
atoms.push(createChainByJSXElement(component, item, parent, isSvg));
|
|
1585
1591
|
continue;
|
|
1586
1592
|
}
|
|
1587
1593
|
if (item instanceof JSXComponent) {
|
|
1588
|
-
const childAtom = createChainByComponentFactory(item, parent);
|
|
1594
|
+
const childAtom = createChainByComponentFactory(item, parent, isSvg);
|
|
1589
1595
|
atoms.push(childAtom);
|
|
1590
1596
|
continue;
|
|
1591
1597
|
}
|
|
1592
1598
|
if (typeof item === 'string' && item.length) {
|
|
1593
|
-
atoms.push(createChainByJSXText(new JSXText(item), parent));
|
|
1599
|
+
atoms.push(createChainByJSXText(new JSXText(item), parent, isSvg));
|
|
1594
1600
|
continue;
|
|
1595
1601
|
}
|
|
1596
1602
|
if (Array.isArray(item)) {
|
|
1597
|
-
createChainByChildren(component, item, parent, atoms);
|
|
1603
|
+
createChainByChildren(component, item, parent, atoms, isSvg);
|
|
1598
1604
|
continue;
|
|
1599
1605
|
}
|
|
1600
|
-
atoms.push(createChainByJSXText(new JSXText(String(item)), parent));
|
|
1606
|
+
atoms.push(createChainByJSXText(new JSXText(String(item)), parent, isSvg));
|
|
1601
1607
|
}
|
|
1602
1608
|
}
|
|
1603
1609
|
return atoms;
|
|
1604
1610
|
}
|
|
1605
1611
|
function linkTemplate(template, component, parent) {
|
|
1606
1612
|
const children = Array.isArray(template) ? template : [template];
|
|
1607
|
-
const newChildren = createChainByChildren(component, children, parent, []);
|
|
1613
|
+
const newChildren = createChainByChildren(component, children, parent, [], parent.isSvg);
|
|
1608
1614
|
link(parent, newChildren);
|
|
1609
1615
|
}
|
|
1610
1616
|
function link(parent, children) {
|
|
@@ -1614,8 +1620,8 @@ function link(parent, children) {
|
|
|
1614
1620
|
}
|
|
1615
1621
|
parent.child = children[0] || null;
|
|
1616
1622
|
}
|
|
1617
|
-
function createElement(nativeRenderer, vNode) {
|
|
1618
|
-
const nativeNode = nativeRenderer.createElement(vNode.type);
|
|
1623
|
+
function createElement(nativeRenderer, vNode, isSvg) {
|
|
1624
|
+
const nativeNode = nativeRenderer.createElement(vNode.type, isSvg);
|
|
1619
1625
|
const props = vNode.props;
|
|
1620
1626
|
let bindingRefs;
|
|
1621
1627
|
const keys = Object.keys(props);
|
|
@@ -1626,21 +1632,21 @@ function createElement(nativeRenderer, vNode) {
|
|
|
1626
1632
|
if (key === 'class') {
|
|
1627
1633
|
const className = classToString(props[key]);
|
|
1628
1634
|
if (className) {
|
|
1629
|
-
nativeRenderer.setClass(nativeNode, className);
|
|
1635
|
+
nativeRenderer.setClass(nativeNode, className, isSvg);
|
|
1630
1636
|
}
|
|
1631
1637
|
continue;
|
|
1632
1638
|
}
|
|
1633
1639
|
if (key === 'style') {
|
|
1634
1640
|
const style = styleToObject(props.style);
|
|
1635
1641
|
Object.keys(style).forEach(key => {
|
|
1636
|
-
nativeRenderer.setStyle(nativeNode, key, style[key]);
|
|
1642
|
+
nativeRenderer.setStyle(nativeNode, key, style[key], isSvg);
|
|
1637
1643
|
});
|
|
1638
1644
|
continue;
|
|
1639
1645
|
}
|
|
1640
1646
|
if (/^on[A-Z]/.test(key)) {
|
|
1641
1647
|
const listener = props[key];
|
|
1642
1648
|
if (typeof listener === 'function') {
|
|
1643
|
-
bindEvent(nativeRenderer, vNode, key, nativeNode, listener);
|
|
1649
|
+
bindEvent(nativeRenderer, vNode, key, nativeNode, listener, isSvg);
|
|
1644
1650
|
}
|
|
1645
1651
|
continue;
|
|
1646
1652
|
}
|
|
@@ -1648,7 +1654,7 @@ function createElement(nativeRenderer, vNode) {
|
|
|
1648
1654
|
bindingRefs = props[key];
|
|
1649
1655
|
continue;
|
|
1650
1656
|
}
|
|
1651
|
-
nativeRenderer.setProperty(nativeNode, key, props[key]);
|
|
1657
|
+
nativeRenderer.setProperty(nativeNode, key, props[key], isSvg);
|
|
1652
1658
|
}
|
|
1653
1659
|
return {
|
|
1654
1660
|
nativeNode,
|
|
@@ -1657,10 +1663,10 @@ function createElement(nativeRenderer, vNode) {
|
|
|
1657
1663
|
}
|
|
1658
1664
|
};
|
|
1659
1665
|
}
|
|
1660
|
-
function createTextNode(nativeRenderer, child) {
|
|
1661
|
-
return nativeRenderer.createTextNode(child.text);
|
|
1666
|
+
function createTextNode(nativeRenderer, child, isSvg) {
|
|
1667
|
+
return nativeRenderer.createTextNode(child.text, isSvg);
|
|
1662
1668
|
}
|
|
1663
|
-
function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNode) {
|
|
1669
|
+
function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNode, isSvg) {
|
|
1664
1670
|
const changes = getObjectChanges(newVNode.props, oldVNode.props);
|
|
1665
1671
|
let unBindRefs;
|
|
1666
1672
|
let bindRefs;
|
|
@@ -1669,12 +1675,12 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1669
1675
|
continue;
|
|
1670
1676
|
}
|
|
1671
1677
|
if (key === 'class') {
|
|
1672
|
-
nativeRenderer.setClass(nativeNode, '');
|
|
1678
|
+
nativeRenderer.setClass(nativeNode, '', isSvg);
|
|
1673
1679
|
continue;
|
|
1674
1680
|
}
|
|
1675
1681
|
if (key === 'style') {
|
|
1676
1682
|
Object.keys(styleToObject(value)).forEach(styleName => {
|
|
1677
|
-
nativeRenderer.removeStyle(nativeNode, styleName);
|
|
1683
|
+
nativeRenderer.removeStyle(nativeNode, styleName, isSvg);
|
|
1678
1684
|
});
|
|
1679
1685
|
continue;
|
|
1680
1686
|
}
|
|
@@ -1682,7 +1688,7 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1682
1688
|
if (typeof value === 'function') {
|
|
1683
1689
|
const type = key.replace(/^on/, '').toLowerCase();
|
|
1684
1690
|
const oldOn = oldVNode.on;
|
|
1685
|
-
nativeRenderer.unListen(nativeNode, type, oldOn[type].delegate);
|
|
1691
|
+
nativeRenderer.unListen(nativeNode, type, oldOn[type].delegate, isSvg);
|
|
1686
1692
|
Reflect.deleteProperty(oldOn, type);
|
|
1687
1693
|
}
|
|
1688
1694
|
continue;
|
|
@@ -1691,7 +1697,7 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1691
1697
|
unBindRefs = value;
|
|
1692
1698
|
continue;
|
|
1693
1699
|
}
|
|
1694
|
-
nativeRenderer.removeProperty(nativeNode, key);
|
|
1700
|
+
nativeRenderer.removeProperty(nativeNode, key, isSvg);
|
|
1695
1701
|
}
|
|
1696
1702
|
for (const [key, newValue, oldValue] of changes.replace) {
|
|
1697
1703
|
if (key === 'children') {
|
|
@@ -1701,17 +1707,17 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1701
1707
|
const oldClassName = classToString(oldValue);
|
|
1702
1708
|
const newClassName = classToString(newValue);
|
|
1703
1709
|
if (oldClassName !== newClassName) {
|
|
1704
|
-
nativeRenderer.setClass(nativeNode, newClassName);
|
|
1710
|
+
nativeRenderer.setClass(nativeNode, newClassName, isSvg);
|
|
1705
1711
|
}
|
|
1706
1712
|
continue;
|
|
1707
1713
|
}
|
|
1708
1714
|
if (key === 'style') {
|
|
1709
1715
|
const styleChanges = getObjectChanges(styleToObject(newValue) || {}, styleToObject(oldValue) || {});
|
|
1710
1716
|
for (const [styleName] of styleChanges.remove) {
|
|
1711
|
-
nativeRenderer.removeStyle(nativeNode, styleName);
|
|
1717
|
+
nativeRenderer.removeStyle(nativeNode, styleName, isSvg);
|
|
1712
1718
|
}
|
|
1713
1719
|
for (const [styleName, styleValue] of [...styleChanges.add, ...styleChanges.replace]) {
|
|
1714
|
-
nativeRenderer.setStyle(nativeNode, styleName, styleValue);
|
|
1720
|
+
nativeRenderer.setStyle(nativeNode, styleName, styleValue, isSvg);
|
|
1715
1721
|
}
|
|
1716
1722
|
continue;
|
|
1717
1723
|
}
|
|
@@ -1726,26 +1732,26 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1726
1732
|
bindRefs = newValue;
|
|
1727
1733
|
continue;
|
|
1728
1734
|
}
|
|
1729
|
-
nativeRenderer.setProperty(nativeNode, key, newValue);
|
|
1735
|
+
nativeRenderer.setProperty(nativeNode, key, newValue, isSvg);
|
|
1730
1736
|
}
|
|
1731
1737
|
for (const [key, value] of changes.add) {
|
|
1732
1738
|
if (key === 'children') {
|
|
1733
1739
|
continue;
|
|
1734
1740
|
}
|
|
1735
1741
|
if (key === 'class') {
|
|
1736
|
-
nativeRenderer.setClass(nativeNode, classToString(value));
|
|
1742
|
+
nativeRenderer.setClass(nativeNode, classToString(value), isSvg);
|
|
1737
1743
|
continue;
|
|
1738
1744
|
}
|
|
1739
1745
|
if (key === 'style') {
|
|
1740
1746
|
const styleObj = styleToObject(value);
|
|
1741
1747
|
Object.keys(styleObj).forEach(styleName => {
|
|
1742
|
-
nativeRenderer.setStyle(nativeNode, styleName, styleObj[styleName]);
|
|
1748
|
+
nativeRenderer.setStyle(nativeNode, styleName, styleObj[styleName], isSvg);
|
|
1743
1749
|
});
|
|
1744
1750
|
continue;
|
|
1745
1751
|
}
|
|
1746
1752
|
if (/^on[A-Z]/.test(key)) {
|
|
1747
1753
|
if (typeof value === 'function') {
|
|
1748
|
-
bindEvent(nativeRenderer, newVNode, key, nativeNode, value);
|
|
1754
|
+
bindEvent(nativeRenderer, newVNode, key, nativeNode, value, isSvg);
|
|
1749
1755
|
}
|
|
1750
1756
|
continue;
|
|
1751
1757
|
}
|
|
@@ -1753,7 +1759,7 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1753
1759
|
bindRefs = value;
|
|
1754
1760
|
continue;
|
|
1755
1761
|
}
|
|
1756
|
-
nativeRenderer.setProperty(nativeNode, key, value);
|
|
1762
|
+
nativeRenderer.setProperty(nativeNode, key, value, isSvg);
|
|
1757
1763
|
}
|
|
1758
1764
|
return () => {
|
|
1759
1765
|
applyRefs(unBindRefs, nativeNode, false);
|
|
@@ -1768,7 +1774,7 @@ function applyRefs(refs, nativeNode, binding) {
|
|
|
1768
1774
|
}
|
|
1769
1775
|
}
|
|
1770
1776
|
}
|
|
1771
|
-
function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn) {
|
|
1777
|
+
function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn, isSvg) {
|
|
1772
1778
|
let on = vNode.on;
|
|
1773
1779
|
if (!on) {
|
|
1774
1780
|
vNode.on = on = {};
|
|
@@ -1782,7 +1788,7 @@ function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn) {
|
|
|
1782
1788
|
listenFn
|
|
1783
1789
|
};
|
|
1784
1790
|
on[type] = delegateObj;
|
|
1785
|
-
nativeRenderer.listen(nativeNode, type, delegate);
|
|
1791
|
+
nativeRenderer.listen(nativeNode, type, delegate, isSvg);
|
|
1786
1792
|
}
|
|
1787
1793
|
|
|
1788
1794
|
/**
|
|
@@ -1804,7 +1810,7 @@ class RootComponent extends Component {
|
|
|
1804
1810
|
}
|
|
1805
1811
|
|
|
1806
1812
|
const viewflyErrorFn = makeError('Viewfly');
|
|
1807
|
-
const VERSION = "0.2.
|
|
1813
|
+
const VERSION = "0.2.2";
|
|
1808
1814
|
function viewfly(config) {
|
|
1809
1815
|
const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
|
|
1810
1816
|
const appProviders = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"bugs": {
|
|
48
48
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "1640dcd27dc51ead16d55964f95c56a94271ea8d"
|
|
51
51
|
}
|