@viewfly/core 0.5.0 → 0.5.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/_api.d.ts +1 -0
- package/bundles/foundation/_utils.d.ts +1 -0
- package/bundles/foundation/component.d.ts +4 -1
- package/bundles/foundation/injection-tokens.d.ts +1 -0
- package/bundles/foundation/types.d.ts +2 -0
- package/bundles/index.esm.js +47 -19
- package/bundles/index.js +47 -19
- package/package.json +2 -2
|
@@ -31,7 +31,10 @@ export declare class Component extends ReflectiveInjector implements JSXTypeof<J
|
|
|
31
31
|
constructor(parentComponent: Injector | null, type: JSXInternal.ComponentSetup, props: Props, key?: Key | undefined);
|
|
32
32
|
markAsDirtied(): void;
|
|
33
33
|
markAsChanged(changedComponent?: Component): void;
|
|
34
|
-
render():
|
|
34
|
+
render(): {
|
|
35
|
+
template: any;
|
|
36
|
+
portalHost: import("./injection-tokens").NativeNode | undefined;
|
|
37
|
+
};
|
|
35
38
|
update(newProps: Props, forceUpdate?: boolean): any;
|
|
36
39
|
provide<T>(providers: Provider<T> | Provider<T>[]): void;
|
|
37
40
|
rendered(): void;
|
|
@@ -3,6 +3,7 @@ export declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode
|
|
|
3
3
|
abstract createElement(name: string, isSvg: boolean): ElementNode;
|
|
4
4
|
abstract createTextNode(textContent: string, isSvg: boolean): TextNode;
|
|
5
5
|
abstract setProperty(node: ElementNode, key: string, value: any, isSvg: boolean): void;
|
|
6
|
+
abstract appendChild(parent: ElementNode, newChild: ElementNode | TextNode, isSvg: boolean): void;
|
|
6
7
|
abstract prependChild(parent: ElementNode, newChild: ElementNode | TextNode, isSvg: boolean): void;
|
|
7
8
|
abstract removeProperty(node: ElementNode, key: string, isSvg: boolean): void;
|
|
8
9
|
abstract setStyle(target: ElementNode, key: string, value: any, isSvg: boolean): void;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Key } from './jsx-element';
|
|
2
2
|
import { ExtractInstanceType, DynamicRef } from './component';
|
|
3
3
|
import { Scope } from '../di/injectable';
|
|
4
|
+
import { NativeNode } from './injection-tokens';
|
|
4
5
|
export type JSXNode = JSXInternal.JSXNode;
|
|
5
6
|
export declare namespace JSXInternal {
|
|
6
7
|
type ClassNames = string | Record<string, unknown> | false | null | undefined | ClassNames[];
|
|
7
8
|
interface ComponentInstance<P> {
|
|
9
|
+
$portalHost?: NativeNode;
|
|
8
10
|
$render(): JSXNode;
|
|
9
11
|
$useMemo?(currentProps: P, prevProps: P): boolean;
|
|
10
12
|
}
|
package/bundles/index.esm.js
CHANGED
|
@@ -732,7 +732,10 @@ class Component extends ReflectiveInjector {
|
|
|
732
732
|
this.markAsDirtied();
|
|
733
733
|
});
|
|
734
734
|
this.template = template;
|
|
735
|
-
return
|
|
735
|
+
return {
|
|
736
|
+
template: template,
|
|
737
|
+
portalHost: this.instance.$portalHost
|
|
738
|
+
};
|
|
736
739
|
}
|
|
737
740
|
update(newProps, forceUpdate = false) {
|
|
738
741
|
const oldProps = this.props;
|
|
@@ -1258,7 +1261,8 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1258
1261
|
};
|
|
1259
1262
|
componentRender(nativeRenderer, component, atom, {
|
|
1260
1263
|
isParent: true,
|
|
1261
|
-
host
|
|
1264
|
+
host,
|
|
1265
|
+
rootHost: host
|
|
1262
1266
|
});
|
|
1263
1267
|
}
|
|
1264
1268
|
else {
|
|
@@ -1285,7 +1289,12 @@ function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
|
1285
1289
|
}
|
|
1286
1290
|
atom.nativeNode = nativeNode;
|
|
1287
1291
|
if (context.isParent) {
|
|
1288
|
-
|
|
1292
|
+
if (context.host === context.rootHost) {
|
|
1293
|
+
nativeRenderer.appendChild(context.host, nativeNode, atom.isSvg);
|
|
1294
|
+
}
|
|
1295
|
+
else {
|
|
1296
|
+
nativeRenderer.prependChild(context.host, nativeNode, atom.isSvg);
|
|
1297
|
+
}
|
|
1289
1298
|
}
|
|
1290
1299
|
else {
|
|
1291
1300
|
nativeRenderer.insertAfter(nativeNode, context.host, atom.isSvg);
|
|
@@ -1293,7 +1302,8 @@ function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
|
1293
1302
|
if (atom.jsxNode instanceof JSXElement) {
|
|
1294
1303
|
const childContext = {
|
|
1295
1304
|
isParent: true,
|
|
1296
|
-
host: nativeNode
|
|
1305
|
+
host: nativeNode,
|
|
1306
|
+
rootHost: context.rootHost
|
|
1297
1307
|
};
|
|
1298
1308
|
let child = atom.child;
|
|
1299
1309
|
while (child) {
|
|
@@ -1321,7 +1331,7 @@ function updateView(nativeRenderer, component) {
|
|
|
1321
1331
|
}
|
|
1322
1332
|
}
|
|
1323
1333
|
function applyChanges(nativeRenderer, component) {
|
|
1324
|
-
const { atom, host, isParent } = component.$$view;
|
|
1334
|
+
const { atom, host, isParent, rootHost } = component.$$view;
|
|
1325
1335
|
const diffAtom = atom.child;
|
|
1326
1336
|
const template = component.update(component.props, true);
|
|
1327
1337
|
if (template) {
|
|
@@ -1332,7 +1342,8 @@ function applyChanges(nativeRenderer, component) {
|
|
|
1332
1342
|
}
|
|
1333
1343
|
const context = {
|
|
1334
1344
|
host,
|
|
1335
|
-
isParent
|
|
1345
|
+
isParent,
|
|
1346
|
+
rootHost
|
|
1336
1347
|
};
|
|
1337
1348
|
diff(nativeRenderer, component, atom.child, diffAtom, context, 0, 0);
|
|
1338
1349
|
const next = atom.sibling;
|
|
@@ -1464,7 +1475,12 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
|
|
|
1464
1475
|
const host = context.host;
|
|
1465
1476
|
if (expectIndex - offset !== oldIndex) {
|
|
1466
1477
|
if (context.isParent) {
|
|
1467
|
-
|
|
1478
|
+
if (host === context.rootHost) {
|
|
1479
|
+
nativeRenderer.appendChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1480
|
+
}
|
|
1481
|
+
else {
|
|
1482
|
+
nativeRenderer.prependChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1483
|
+
}
|
|
1468
1484
|
}
|
|
1469
1485
|
else {
|
|
1470
1486
|
nativeRenderer.insertAfter(newAtom.nativeNode, host, newAtom.isSvg);
|
|
@@ -1476,7 +1492,8 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
|
|
|
1476
1492
|
if (newAtom.child) {
|
|
1477
1493
|
diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
|
|
1478
1494
|
host: newAtom.nativeNode,
|
|
1479
|
-
isParent: true
|
|
1495
|
+
isParent: true,
|
|
1496
|
+
rootHost: context.rootHost
|
|
1480
1497
|
}, 0, 0);
|
|
1481
1498
|
}
|
|
1482
1499
|
else if (oldAtom.child) {
|
|
@@ -1491,22 +1508,24 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
|
|
|
1491
1508
|
}
|
|
1492
1509
|
function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRenderer, context) {
|
|
1493
1510
|
return function (offset) {
|
|
1494
|
-
const
|
|
1511
|
+
const component = reusedAtom.jsxNode;
|
|
1495
1512
|
const newProps = newAtom.jsxNode.props;
|
|
1496
|
-
const oldTemplate =
|
|
1497
|
-
const newTemplate =
|
|
1498
|
-
|
|
1499
|
-
|
|
1513
|
+
const oldTemplate = component.template;
|
|
1514
|
+
const newTemplate = component.update(newProps);
|
|
1515
|
+
const portalHost = component.instance.$portalHost;
|
|
1516
|
+
context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
|
|
1517
|
+
component.$$view = Object.assign({ atom: newAtom }, context);
|
|
1518
|
+
newAtom.jsxNode = component;
|
|
1500
1519
|
if (newTemplate === oldTemplate) {
|
|
1501
1520
|
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
|
|
1502
|
-
updateView(nativeRenderer,
|
|
1521
|
+
updateView(nativeRenderer, component);
|
|
1503
1522
|
return;
|
|
1504
1523
|
}
|
|
1505
1524
|
if (newTemplate) {
|
|
1506
1525
|
linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
|
|
1507
1526
|
}
|
|
1508
1527
|
if (newAtom.child) {
|
|
1509
|
-
diff(nativeRenderer,
|
|
1528
|
+
diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
|
|
1510
1529
|
}
|
|
1511
1530
|
else if (reusedAtom.child) {
|
|
1512
1531
|
let atom = reusedAtom.child;
|
|
@@ -1515,7 +1534,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
|
|
|
1515
1534
|
atom = atom.sibling;
|
|
1516
1535
|
}
|
|
1517
1536
|
}
|
|
1518
|
-
|
|
1537
|
+
component.rendered();
|
|
1519
1538
|
};
|
|
1520
1539
|
}
|
|
1521
1540
|
function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
|
|
@@ -1538,7 +1557,12 @@ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveVi
|
|
|
1538
1557
|
else {
|
|
1539
1558
|
if (moveView) {
|
|
1540
1559
|
if (context.isParent) {
|
|
1541
|
-
|
|
1560
|
+
if (context.host === context.rootHost) {
|
|
1561
|
+
nativeRenderer.appendChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1562
|
+
}
|
|
1563
|
+
else {
|
|
1564
|
+
nativeRenderer.prependChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1565
|
+
}
|
|
1542
1566
|
}
|
|
1543
1567
|
else {
|
|
1544
1568
|
nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.isSvg);
|
|
@@ -1573,10 +1597,11 @@ function cleanView(nativeRenderer, atom, isClean) {
|
|
|
1573
1597
|
}
|
|
1574
1598
|
}
|
|
1575
1599
|
function componentRender(nativeRenderer, component, from, context) {
|
|
1576
|
-
const template = component.render();
|
|
1600
|
+
const { template, portalHost } = component.render();
|
|
1577
1601
|
if (template) {
|
|
1578
1602
|
linkTemplate(template, component, from);
|
|
1579
1603
|
}
|
|
1604
|
+
context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
|
|
1580
1605
|
component.$$view = Object.assign({ atom: from }, context);
|
|
1581
1606
|
let child = from.child;
|
|
1582
1607
|
while (child) {
|
|
@@ -1838,7 +1863,10 @@ class RootComponent extends Component {
|
|
|
1838
1863
|
const viewflyErrorFn = makeError('Viewfly');
|
|
1839
1864
|
function viewfly(config) {
|
|
1840
1865
|
const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
|
|
1841
|
-
const appProviders = [
|
|
1866
|
+
const appProviders = [{
|
|
1867
|
+
provide: NativeRenderer,
|
|
1868
|
+
useValue: nativeRenderer
|
|
1869
|
+
}];
|
|
1842
1870
|
const modules = [];
|
|
1843
1871
|
let destroyed = false;
|
|
1844
1872
|
let appHost = null;
|
package/bundles/index.js
CHANGED
|
@@ -734,7 +734,10 @@ class Component extends ReflectiveInjector {
|
|
|
734
734
|
this.markAsDirtied();
|
|
735
735
|
});
|
|
736
736
|
this.template = template;
|
|
737
|
-
return
|
|
737
|
+
return {
|
|
738
|
+
template: template,
|
|
739
|
+
portalHost: this.instance.$portalHost
|
|
740
|
+
};
|
|
738
741
|
}
|
|
739
742
|
update(newProps, forceUpdate = false) {
|
|
740
743
|
const oldProps = this.props;
|
|
@@ -1260,7 +1263,8 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1260
1263
|
};
|
|
1261
1264
|
componentRender(nativeRenderer, component, atom, {
|
|
1262
1265
|
isParent: true,
|
|
1263
|
-
host
|
|
1266
|
+
host,
|
|
1267
|
+
rootHost: host
|
|
1264
1268
|
});
|
|
1265
1269
|
}
|
|
1266
1270
|
else {
|
|
@@ -1287,7 +1291,12 @@ function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
|
1287
1291
|
}
|
|
1288
1292
|
atom.nativeNode = nativeNode;
|
|
1289
1293
|
if (context.isParent) {
|
|
1290
|
-
|
|
1294
|
+
if (context.host === context.rootHost) {
|
|
1295
|
+
nativeRenderer.appendChild(context.host, nativeNode, atom.isSvg);
|
|
1296
|
+
}
|
|
1297
|
+
else {
|
|
1298
|
+
nativeRenderer.prependChild(context.host, nativeNode, atom.isSvg);
|
|
1299
|
+
}
|
|
1291
1300
|
}
|
|
1292
1301
|
else {
|
|
1293
1302
|
nativeRenderer.insertAfter(nativeNode, context.host, atom.isSvg);
|
|
@@ -1295,7 +1304,8 @@ function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
|
1295
1304
|
if (atom.jsxNode instanceof JSXElement) {
|
|
1296
1305
|
const childContext = {
|
|
1297
1306
|
isParent: true,
|
|
1298
|
-
host: nativeNode
|
|
1307
|
+
host: nativeNode,
|
|
1308
|
+
rootHost: context.rootHost
|
|
1299
1309
|
};
|
|
1300
1310
|
let child = atom.child;
|
|
1301
1311
|
while (child) {
|
|
@@ -1323,7 +1333,7 @@ function updateView(nativeRenderer, component) {
|
|
|
1323
1333
|
}
|
|
1324
1334
|
}
|
|
1325
1335
|
function applyChanges(nativeRenderer, component) {
|
|
1326
|
-
const { atom, host, isParent } = component.$$view;
|
|
1336
|
+
const { atom, host, isParent, rootHost } = component.$$view;
|
|
1327
1337
|
const diffAtom = atom.child;
|
|
1328
1338
|
const template = component.update(component.props, true);
|
|
1329
1339
|
if (template) {
|
|
@@ -1334,7 +1344,8 @@ function applyChanges(nativeRenderer, component) {
|
|
|
1334
1344
|
}
|
|
1335
1345
|
const context = {
|
|
1336
1346
|
host,
|
|
1337
|
-
isParent
|
|
1347
|
+
isParent,
|
|
1348
|
+
rootHost
|
|
1338
1349
|
};
|
|
1339
1350
|
diff(nativeRenderer, component, atom.child, diffAtom, context, 0, 0);
|
|
1340
1351
|
const next = atom.sibling;
|
|
@@ -1466,7 +1477,12 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
|
|
|
1466
1477
|
const host = context.host;
|
|
1467
1478
|
if (expectIndex - offset !== oldIndex) {
|
|
1468
1479
|
if (context.isParent) {
|
|
1469
|
-
|
|
1480
|
+
if (host === context.rootHost) {
|
|
1481
|
+
nativeRenderer.appendChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1482
|
+
}
|
|
1483
|
+
else {
|
|
1484
|
+
nativeRenderer.prependChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1485
|
+
}
|
|
1470
1486
|
}
|
|
1471
1487
|
else {
|
|
1472
1488
|
nativeRenderer.insertAfter(newAtom.nativeNode, host, newAtom.isSvg);
|
|
@@ -1478,7 +1494,8 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
|
|
|
1478
1494
|
if (newAtom.child) {
|
|
1479
1495
|
diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
|
|
1480
1496
|
host: newAtom.nativeNode,
|
|
1481
|
-
isParent: true
|
|
1497
|
+
isParent: true,
|
|
1498
|
+
rootHost: context.rootHost
|
|
1482
1499
|
}, 0, 0);
|
|
1483
1500
|
}
|
|
1484
1501
|
else if (oldAtom.child) {
|
|
@@ -1493,22 +1510,24 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
|
|
|
1493
1510
|
}
|
|
1494
1511
|
function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRenderer, context) {
|
|
1495
1512
|
return function (offset) {
|
|
1496
|
-
const
|
|
1513
|
+
const component = reusedAtom.jsxNode;
|
|
1497
1514
|
const newProps = newAtom.jsxNode.props;
|
|
1498
|
-
const oldTemplate =
|
|
1499
|
-
const newTemplate =
|
|
1500
|
-
|
|
1501
|
-
|
|
1515
|
+
const oldTemplate = component.template;
|
|
1516
|
+
const newTemplate = component.update(newProps);
|
|
1517
|
+
const portalHost = component.instance.$portalHost;
|
|
1518
|
+
context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
|
|
1519
|
+
component.$$view = Object.assign({ atom: newAtom }, context);
|
|
1520
|
+
newAtom.jsxNode = component;
|
|
1502
1521
|
if (newTemplate === oldTemplate) {
|
|
1503
1522
|
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
|
|
1504
|
-
updateView(nativeRenderer,
|
|
1523
|
+
updateView(nativeRenderer, component);
|
|
1505
1524
|
return;
|
|
1506
1525
|
}
|
|
1507
1526
|
if (newTemplate) {
|
|
1508
1527
|
linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
|
|
1509
1528
|
}
|
|
1510
1529
|
if (newAtom.child) {
|
|
1511
|
-
diff(nativeRenderer,
|
|
1530
|
+
diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
|
|
1512
1531
|
}
|
|
1513
1532
|
else if (reusedAtom.child) {
|
|
1514
1533
|
let atom = reusedAtom.child;
|
|
@@ -1517,7 +1536,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
|
|
|
1517
1536
|
atom = atom.sibling;
|
|
1518
1537
|
}
|
|
1519
1538
|
}
|
|
1520
|
-
|
|
1539
|
+
component.rendered();
|
|
1521
1540
|
};
|
|
1522
1541
|
}
|
|
1523
1542
|
function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
|
|
@@ -1540,7 +1559,12 @@ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveVi
|
|
|
1540
1559
|
else {
|
|
1541
1560
|
if (moveView) {
|
|
1542
1561
|
if (context.isParent) {
|
|
1543
|
-
|
|
1562
|
+
if (context.host === context.rootHost) {
|
|
1563
|
+
nativeRenderer.appendChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1564
|
+
}
|
|
1565
|
+
else {
|
|
1566
|
+
nativeRenderer.prependChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1567
|
+
}
|
|
1544
1568
|
}
|
|
1545
1569
|
else {
|
|
1546
1570
|
nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.isSvg);
|
|
@@ -1575,10 +1599,11 @@ function cleanView(nativeRenderer, atom, isClean) {
|
|
|
1575
1599
|
}
|
|
1576
1600
|
}
|
|
1577
1601
|
function componentRender(nativeRenderer, component, from, context) {
|
|
1578
|
-
const template = component.render();
|
|
1602
|
+
const { template, portalHost } = component.render();
|
|
1579
1603
|
if (template) {
|
|
1580
1604
|
linkTemplate(template, component, from);
|
|
1581
1605
|
}
|
|
1606
|
+
context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
|
|
1582
1607
|
component.$$view = Object.assign({ atom: from }, context);
|
|
1583
1608
|
let child = from.child;
|
|
1584
1609
|
while (child) {
|
|
@@ -1840,7 +1865,10 @@ class RootComponent extends Component {
|
|
|
1840
1865
|
const viewflyErrorFn = makeError('Viewfly');
|
|
1841
1866
|
function viewfly(config) {
|
|
1842
1867
|
const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
|
|
1843
|
-
const appProviders = [
|
|
1868
|
+
const appProviders = [{
|
|
1869
|
+
provide: NativeRenderer,
|
|
1870
|
+
useValue: nativeRenderer
|
|
1871
|
+
}];
|
|
1844
1872
|
const modules = [];
|
|
1845
1873
|
let destroyed = false;
|
|
1846
1874
|
let appHost = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/core",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.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,7 +47,7 @@
|
|
|
47
47
|
"bugs": {
|
|
48
48
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "7dadc17107c6fc4b8db6e620e9b95141db09e042",
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"reflect-metadata": "^0.1.13"
|
|
53
53
|
}
|