@viewfly/core 0.5.3 → 0.6.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/bundles/foundation/_utils.d.ts +22 -4
- package/bundles/foundation/component.d.ts +12 -13
- package/bundles/foundation/injection-tokens.d.ts +1 -0
- package/bundles/foundation/jsx-element.d.ts +8 -28
- package/bundles/foundation/memo.d.ts +1 -1
- package/bundles/foundation/types.d.ts +4 -4
- package/bundles/index.esm.js +222 -237
- package/bundles/index.js +222 -239
- package/bundles/viewfly.d.ts +1 -1
- package/package.json +2 -2
package/bundles/index.js
CHANGED
|
@@ -658,25 +658,16 @@ class Component extends ReflectiveInjector {
|
|
|
658
658
|
return this._changed;
|
|
659
659
|
}
|
|
660
660
|
constructor(parentComponent, type, props, key) {
|
|
661
|
-
super(parentComponent, [
|
|
662
|
-
provide: Injector,
|
|
663
|
-
useFactory: () => this
|
|
664
|
-
}], type.scope);
|
|
661
|
+
super(parentComponent, [], type.scope);
|
|
665
662
|
this.parentComponent = parentComponent;
|
|
666
663
|
this.type = type;
|
|
667
664
|
this.props = props;
|
|
668
665
|
this.key = key;
|
|
669
|
-
this.$$typeOf = this.type;
|
|
670
666
|
this.changedSubComponents = new Set();
|
|
671
|
-
this.unmountedCallbacks = [];
|
|
672
|
-
this.mountCallbacks = [];
|
|
673
|
-
this.propsChangedCallbacks = [];
|
|
674
|
-
this.updatedCallbacks = [];
|
|
675
|
-
this.updatedDestroyCallbacks = [];
|
|
676
|
-
this.propsChangedDestroyCallbacks = [];
|
|
677
667
|
this._dirty = true;
|
|
678
668
|
this._changed = true;
|
|
679
669
|
this.isFirstRendering = true;
|
|
670
|
+
this.refs = null;
|
|
680
671
|
}
|
|
681
672
|
markAsDirtied() {
|
|
682
673
|
this._dirty = true;
|
|
@@ -714,17 +705,20 @@ class Component extends ReflectiveInjector {
|
|
|
714
705
|
const render = this.type(proxiesProps);
|
|
715
706
|
const isRenderFn = typeof render === 'function';
|
|
716
707
|
this.instance = isRenderFn ? { $render: render } : render;
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
708
|
+
const refs = toRefs(this.props.ref);
|
|
709
|
+
if (refs.length) {
|
|
710
|
+
this.refs = refs;
|
|
711
|
+
onMounted(() => {
|
|
712
|
+
for (const ref of refs) {
|
|
713
|
+
ref.bind(this.instance);
|
|
714
|
+
}
|
|
715
|
+
return () => {
|
|
716
|
+
for (const ref of refs) {
|
|
717
|
+
ref.unBind(this.instance);
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
});
|
|
721
|
+
}
|
|
728
722
|
isSetup = false;
|
|
729
723
|
componentSetupStack.pop();
|
|
730
724
|
signalDepsStack.push([]);
|
|
@@ -749,17 +743,19 @@ class Component extends ReflectiveInjector {
|
|
|
749
743
|
return this.template;
|
|
750
744
|
}
|
|
751
745
|
const newRefs = toRefs(newProps.ref);
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
746
|
+
if (this.refs) {
|
|
747
|
+
for (const oldRef of this.refs) {
|
|
748
|
+
if (!newRefs.includes(oldRef)) {
|
|
749
|
+
oldRef.unBind(this.instance);
|
|
750
|
+
}
|
|
755
751
|
}
|
|
756
752
|
}
|
|
757
753
|
for (const newRef of newRefs) {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
754
|
+
newRef.bind(this.instance);
|
|
755
|
+
}
|
|
756
|
+
if (newRefs.length) {
|
|
757
|
+
this.refs = newRefs;
|
|
761
758
|
}
|
|
762
|
-
this.refs = newRefs;
|
|
763
759
|
if (!forceUpdate && typeof this.instance.$useMemo === 'function') {
|
|
764
760
|
if (this.instance.$useMemo(newProps, oldProps)) {
|
|
765
761
|
return this.template;
|
|
@@ -796,55 +792,73 @@ class Component extends ReflectiveInjector {
|
|
|
796
792
|
}
|
|
797
793
|
}
|
|
798
794
|
destroy() {
|
|
795
|
+
var _a, _b, _c;
|
|
799
796
|
this.unWatch();
|
|
800
|
-
this.updatedDestroyCallbacks.forEach(fn => {
|
|
797
|
+
(_a = this.updatedDestroyCallbacks) === null || _a === void 0 ? void 0 : _a.forEach(fn => {
|
|
801
798
|
fn();
|
|
802
799
|
});
|
|
803
|
-
this.
|
|
804
|
-
this.propsChangedDestroyCallbacks.forEach(fn => {
|
|
800
|
+
(_b = this.propsChangedDestroyCallbacks) === null || _b === void 0 ? void 0 : _b.forEach(fn => {
|
|
805
801
|
fn();
|
|
806
802
|
});
|
|
807
|
-
this.
|
|
808
|
-
for (const fn of this.unmountedCallbacks) {
|
|
803
|
+
(_c = this.unmountedCallbacks) === null || _c === void 0 ? void 0 : _c.forEach(fn => {
|
|
809
804
|
fn();
|
|
810
|
-
}
|
|
811
|
-
this.
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
805
|
+
});
|
|
806
|
+
this.propsChangedDestroyCallbacks =
|
|
807
|
+
this.updatedDestroyCallbacks =
|
|
808
|
+
this.mountCallbacks =
|
|
809
|
+
this.updatedCallbacks =
|
|
810
|
+
this.propsChangedCallbacks =
|
|
811
|
+
this.unmountedCallbacks = null;
|
|
815
812
|
}
|
|
816
813
|
invokePropsChangedHooks(newProps) {
|
|
817
814
|
const oldProps = this.props;
|
|
818
815
|
this.props = newProps;
|
|
819
|
-
this.
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
816
|
+
if (this.propsChangedCallbacks) {
|
|
817
|
+
if (this.propsChangedDestroyCallbacks) {
|
|
818
|
+
this.propsChangedDestroyCallbacks.forEach(fn => {
|
|
819
|
+
fn();
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
const propsChangedDestroyCallbacks = [];
|
|
823
|
+
for (const fn of this.propsChangedCallbacks) {
|
|
824
|
+
const destroyFn = fn(newProps, oldProps);
|
|
825
|
+
if (typeof destroyFn === 'function') {
|
|
826
|
+
propsChangedDestroyCallbacks.push(destroyFn);
|
|
827
|
+
}
|
|
827
828
|
}
|
|
829
|
+
this.propsChangedDestroyCallbacks = propsChangedDestroyCallbacks.length ? propsChangedDestroyCallbacks : null;
|
|
828
830
|
}
|
|
829
831
|
}
|
|
830
832
|
invokeMountHooks() {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
833
|
+
const unmountedCallbacks = [];
|
|
834
|
+
if (this.mountCallbacks) {
|
|
835
|
+
for (const fn of this.mountCallbacks) {
|
|
836
|
+
const destroyFn = fn();
|
|
837
|
+
if (typeof destroyFn === 'function') {
|
|
838
|
+
unmountedCallbacks.push(destroyFn);
|
|
839
|
+
}
|
|
835
840
|
}
|
|
836
841
|
}
|
|
842
|
+
if (unmountedCallbacks.length) {
|
|
843
|
+
this.unmountedCallbacks = unmountedCallbacks;
|
|
844
|
+
}
|
|
845
|
+
this.mountCallbacks = null;
|
|
837
846
|
}
|
|
838
847
|
invokeUpdatedHooks() {
|
|
839
|
-
this.
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
const destroyFn = fn();
|
|
845
|
-
if (typeof destroyFn === 'function') {
|
|
846
|
-
this.updatedDestroyCallbacks.push(destroyFn);
|
|
848
|
+
if (this.updatedCallbacks) {
|
|
849
|
+
if (this.updatedDestroyCallbacks) {
|
|
850
|
+
this.updatedDestroyCallbacks.forEach(fn => {
|
|
851
|
+
fn();
|
|
852
|
+
});
|
|
847
853
|
}
|
|
854
|
+
const updatedDestroyCallbacks = [];
|
|
855
|
+
for (const fn of this.updatedCallbacks) {
|
|
856
|
+
const destroyFn = fn();
|
|
857
|
+
if (typeof destroyFn === 'function') {
|
|
858
|
+
updatedDestroyCallbacks.push(destroyFn);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
this.updatedDestroyCallbacks = updatedDestroyCallbacks.length ? updatedDestroyCallbacks : null;
|
|
848
862
|
}
|
|
849
863
|
}
|
|
850
864
|
}
|
|
@@ -867,6 +881,9 @@ function toRefs(ref) {
|
|
|
867
881
|
*/
|
|
868
882
|
function onMounted(callback) {
|
|
869
883
|
const component = getSetupContext();
|
|
884
|
+
if (!component.mountCallbacks) {
|
|
885
|
+
component.mountCallbacks = [];
|
|
886
|
+
}
|
|
870
887
|
component.mountCallbacks.push(callback);
|
|
871
888
|
}
|
|
872
889
|
/**
|
|
@@ -886,6 +903,9 @@ function onMounted(callback) {
|
|
|
886
903
|
*/
|
|
887
904
|
function onUpdated(callback) {
|
|
888
905
|
const component = getSetupContext();
|
|
906
|
+
if (!component.updatedCallbacks) {
|
|
907
|
+
component.updatedCallbacks = [];
|
|
908
|
+
}
|
|
889
909
|
component.updatedCallbacks.push(callback);
|
|
890
910
|
return () => {
|
|
891
911
|
const index = component.updatedCallbacks.indexOf(callback);
|
|
@@ -915,6 +935,9 @@ function onUpdated(callback) {
|
|
|
915
935
|
*/
|
|
916
936
|
function onPropsChanged(callback) {
|
|
917
937
|
const component = getSetupContext();
|
|
938
|
+
if (!component.propsChangedCallbacks) {
|
|
939
|
+
component.propsChangedCallbacks = [];
|
|
940
|
+
}
|
|
918
941
|
component.propsChangedCallbacks.push(callback);
|
|
919
942
|
return () => {
|
|
920
943
|
const index = component.propsChangedCallbacks.indexOf(callback);
|
|
@@ -929,6 +952,9 @@ function onPropsChanged(callback) {
|
|
|
929
952
|
*/
|
|
930
953
|
function onUnmounted(callback) {
|
|
931
954
|
const component = getSetupContext();
|
|
955
|
+
if (!component.unmountedCallbacks) {
|
|
956
|
+
component.unmountedCallbacks = [];
|
|
957
|
+
}
|
|
932
958
|
component.unmountedCallbacks.push(callback);
|
|
933
959
|
}
|
|
934
960
|
class DynamicRef {
|
|
@@ -1123,6 +1149,9 @@ function createDerived(callback, isContinue) {
|
|
|
1123
1149
|
const component = getSetupContext(false);
|
|
1124
1150
|
const unListen = listen(signal, deps, callback, isContinue);
|
|
1125
1151
|
if (component) {
|
|
1152
|
+
if (!component.unmountedCallbacks) {
|
|
1153
|
+
component.unmountedCallbacks = [];
|
|
1154
|
+
}
|
|
1126
1155
|
component.unmountedCallbacks.push(() => {
|
|
1127
1156
|
unListen();
|
|
1128
1157
|
});
|
|
@@ -1155,7 +1184,7 @@ function watch(deps, callback) {
|
|
|
1155
1184
|
return;
|
|
1156
1185
|
}
|
|
1157
1186
|
isClean = true;
|
|
1158
|
-
if (component) {
|
|
1187
|
+
if (component === null || component === void 0 ? void 0 : component.unmountedCallbacks) {
|
|
1159
1188
|
const index = component.unmountedCallbacks.indexOf(destroyFn);
|
|
1160
1189
|
component.unmountedCallbacks.splice(index, 1);
|
|
1161
1190
|
}
|
|
@@ -1164,6 +1193,9 @@ function watch(deps, callback) {
|
|
|
1164
1193
|
}
|
|
1165
1194
|
};
|
|
1166
1195
|
if (component) {
|
|
1196
|
+
if (!component.unmountedCallbacks) {
|
|
1197
|
+
component.unmountedCallbacks = [];
|
|
1198
|
+
}
|
|
1167
1199
|
component.unmountedCallbacks.push(destroyFn);
|
|
1168
1200
|
}
|
|
1169
1201
|
return destroyFn;
|
|
@@ -1198,48 +1230,19 @@ function Fragment(props) {
|
|
|
1198
1230
|
return props.children;
|
|
1199
1231
|
};
|
|
1200
1232
|
}
|
|
1201
|
-
function jsx(
|
|
1202
|
-
|
|
1203
|
-
return JSXElement.createInstance(setup, props, key);
|
|
1204
|
-
}
|
|
1205
|
-
return JSXComponent.createInstance(setup, props, function (context) {
|
|
1206
|
-
return new Component(context, setup, props, key);
|
|
1207
|
-
}, key);
|
|
1233
|
+
function jsx(type, props, key) {
|
|
1234
|
+
return JSXNodeFactory.createNode(type, props, key);
|
|
1208
1235
|
}
|
|
1209
1236
|
const jsxs = jsx;
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
}
|
|
1217
|
-
class JSXElement {
|
|
1218
|
-
static createInstance(type, props, key) {
|
|
1219
|
-
return new JSXElement(type, props, key);
|
|
1220
|
-
}
|
|
1221
|
-
constructor(type, props, key) {
|
|
1222
|
-
this.type = type;
|
|
1223
|
-
this.props = props;
|
|
1224
|
-
this.key = key;
|
|
1225
|
-
this.$$typeOf = this.type;
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
class JSXComponent {
|
|
1229
|
-
static createInstance(type, props, factory, key) {
|
|
1230
|
-
return new JSXComponent(type, props, factory, key);
|
|
1231
|
-
}
|
|
1232
|
-
constructor(type, props, factory, key) {
|
|
1233
|
-
this.type = type;
|
|
1234
|
-
this.props = props;
|
|
1235
|
-
this.factory = factory;
|
|
1236
|
-
this.key = key;
|
|
1237
|
-
this.$$typeOf = this.type;
|
|
1238
|
-
}
|
|
1239
|
-
createInstance(parentComponent) {
|
|
1240
|
-
return this.factory(parentComponent);
|
|
1237
|
+
const JSXNodeFactory = {
|
|
1238
|
+
createNode(type, props, key) {
|
|
1239
|
+
return {
|
|
1240
|
+
type,
|
|
1241
|
+
props,
|
|
1242
|
+
key
|
|
1243
|
+
};
|
|
1241
1244
|
}
|
|
1242
|
-
}
|
|
1245
|
+
};
|
|
1243
1246
|
|
|
1244
1247
|
function withMemo(canUseMemo, render) {
|
|
1245
1248
|
return {
|
|
@@ -1248,14 +1251,15 @@ function withMemo(canUseMemo, render) {
|
|
|
1248
1251
|
};
|
|
1249
1252
|
}
|
|
1250
1253
|
|
|
1254
|
+
const listenerReg = /^on(?=[A-Z])/;
|
|
1251
1255
|
function createRenderer(component, nativeRenderer) {
|
|
1252
1256
|
let isInit = true;
|
|
1253
1257
|
return function render(host) {
|
|
1254
1258
|
if (isInit) {
|
|
1255
1259
|
isInit = false;
|
|
1256
1260
|
const atom = {
|
|
1261
|
+
type: 'component',
|
|
1257
1262
|
jsxNode: component,
|
|
1258
|
-
parent: null,
|
|
1259
1263
|
sibling: null,
|
|
1260
1264
|
child: null,
|
|
1261
1265
|
nativeNode: null,
|
|
@@ -1273,35 +1277,26 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1273
1277
|
};
|
|
1274
1278
|
}
|
|
1275
1279
|
function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
1276
|
-
|
|
1277
|
-
|
|
1280
|
+
const { jsxNode, type } = atom;
|
|
1281
|
+
if (type === 'component') {
|
|
1282
|
+
const component = new Component(parentComponent, jsxNode.type, jsxNode.props, jsxNode.key);
|
|
1278
1283
|
atom.jsxNode = component;
|
|
1279
1284
|
componentRender(nativeRenderer, component, atom, context);
|
|
1280
1285
|
}
|
|
1281
1286
|
else {
|
|
1282
1287
|
let nativeNode;
|
|
1283
1288
|
let applyRefs = null;
|
|
1284
|
-
if (
|
|
1285
|
-
const { nativeNode: n, applyRefs: a } = createElement(nativeRenderer,
|
|
1289
|
+
if (type === 'element') {
|
|
1290
|
+
const { nativeNode: n, applyRefs: a } = createElement(nativeRenderer, jsxNode, atom.isSvg);
|
|
1286
1291
|
nativeNode = n;
|
|
1287
1292
|
applyRefs = a;
|
|
1288
1293
|
}
|
|
1289
1294
|
else {
|
|
1290
|
-
nativeNode = createTextNode(nativeRenderer,
|
|
1295
|
+
nativeNode = createTextNode(nativeRenderer, jsxNode, atom.isSvg);
|
|
1291
1296
|
}
|
|
1292
1297
|
atom.nativeNode = nativeNode;
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
nativeRenderer.appendChild(context.host, nativeNode, atom.isSvg);
|
|
1296
|
-
}
|
|
1297
|
-
else {
|
|
1298
|
-
nativeRenderer.prependChild(context.host, nativeNode, atom.isSvg);
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
else {
|
|
1302
|
-
nativeRenderer.insertAfter(nativeNode, context.host, atom.isSvg);
|
|
1303
|
-
}
|
|
1304
|
-
if (atom.jsxNode instanceof JSXElement) {
|
|
1298
|
+
insertNode(nativeRenderer, atom, context);
|
|
1299
|
+
if (type === 'element') {
|
|
1305
1300
|
const childContext = {
|
|
1306
1301
|
isParent: true,
|
|
1307
1302
|
host: nativeNode,
|
|
@@ -1336,12 +1331,7 @@ function applyChanges(nativeRenderer, component) {
|
|
|
1336
1331
|
const { atom, host, isParent, rootHost } = component.$$view;
|
|
1337
1332
|
const diffAtom = atom.child;
|
|
1338
1333
|
const template = component.update(component.props, true);
|
|
1339
|
-
|
|
1340
|
-
linkTemplate(template, component, atom);
|
|
1341
|
-
}
|
|
1342
|
-
else {
|
|
1343
|
-
atom.child = null;
|
|
1344
|
-
}
|
|
1334
|
+
atom.child = createChildChain(template, atom.isSvg);
|
|
1345
1335
|
const context = {
|
|
1346
1336
|
host,
|
|
1347
1337
|
isParent,
|
|
@@ -1408,30 +1398,27 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1408
1398
|
}
|
|
1409
1399
|
function createChanges(newAtom, expectIndex, diffAtomIndexed, nativeRenderer, commits, context, parentComponent, effect) {
|
|
1410
1400
|
const startDiffAtom = diffAtomIndexed;
|
|
1411
|
-
const
|
|
1401
|
+
const { jsxNode: newJsxNode, type } = newAtom;
|
|
1402
|
+
const key = newJsxNode.key;
|
|
1412
1403
|
while (diffAtomIndexed) {
|
|
1413
1404
|
const { atom: diffAtom, index: diffIndex } = diffAtomIndexed;
|
|
1414
|
-
|
|
1415
|
-
if (key !== undefined) {
|
|
1416
|
-
if (diffKey !== key) {
|
|
1417
|
-
diffAtomIndexed = diffAtomIndexed.next;
|
|
1418
|
-
continue;
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
else if (diffKey !== undefined) {
|
|
1422
|
-
diffAtomIndexed = diffAtomIndexed.next;
|
|
1423
|
-
continue;
|
|
1424
|
-
}
|
|
1425
|
-
if (newAtom.jsxNode.$$typeOf === diffAtom.jsxNode.$$typeOf) {
|
|
1405
|
+
if (type === diffAtom.type) {
|
|
1426
1406
|
let commit;
|
|
1427
|
-
if (
|
|
1428
|
-
commit = updateElement(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context, parentComponent);
|
|
1429
|
-
}
|
|
1430
|
-
else if (newAtom.jsxNode instanceof JSXText) {
|
|
1407
|
+
if (type === 'text') {
|
|
1431
1408
|
commit = updateText(newAtom, diffAtom, nativeRenderer, context);
|
|
1432
1409
|
}
|
|
1433
1410
|
else {
|
|
1434
|
-
|
|
1411
|
+
const { key: diffKey, type: diffType } = diffAtom.jsxNode;
|
|
1412
|
+
if (diffKey !== key || newJsxNode.type !== diffType) {
|
|
1413
|
+
diffAtomIndexed = diffAtomIndexed.next;
|
|
1414
|
+
continue;
|
|
1415
|
+
}
|
|
1416
|
+
if (type === 'component') {
|
|
1417
|
+
commit = updateComponent(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context);
|
|
1418
|
+
}
|
|
1419
|
+
else {
|
|
1420
|
+
commit = updateElement(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context, parentComponent);
|
|
1421
|
+
}
|
|
1435
1422
|
}
|
|
1436
1423
|
commits.push(commit);
|
|
1437
1424
|
const next = diffAtomIndexed.next;
|
|
@@ -1463,8 +1450,8 @@ function createNewView(start, nativeRenderer, context, parentComponent, effect)
|
|
|
1463
1450
|
function updateText(newAtom, oldAtom, nativeRenderer, context) {
|
|
1464
1451
|
return function () {
|
|
1465
1452
|
const nativeNode = oldAtom.nativeNode;
|
|
1466
|
-
if (newAtom.jsxNode
|
|
1467
|
-
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode
|
|
1453
|
+
if (newAtom.jsxNode !== oldAtom.jsxNode) {
|
|
1454
|
+
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode, newAtom.isSvg);
|
|
1468
1455
|
}
|
|
1469
1456
|
newAtom.nativeNode = nativeNode;
|
|
1470
1457
|
context.host = nativeNode;
|
|
@@ -1474,19 +1461,8 @@ function updateText(newAtom, oldAtom, nativeRenderer, context) {
|
|
|
1474
1461
|
function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer, context, parentComponent) {
|
|
1475
1462
|
return function (offset) {
|
|
1476
1463
|
newAtom.nativeNode = oldAtom.nativeNode;
|
|
1477
|
-
const host = context.host;
|
|
1478
1464
|
if (expectIndex - offset !== oldIndex) {
|
|
1479
|
-
|
|
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
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
else {
|
|
1488
|
-
nativeRenderer.insertAfter(newAtom.nativeNode, host, newAtom.isSvg);
|
|
1489
|
-
}
|
|
1465
|
+
insertNode(nativeRenderer, newAtom, context);
|
|
1490
1466
|
}
|
|
1491
1467
|
context.host = newAtom.nativeNode;
|
|
1492
1468
|
context.isParent = false;
|
|
@@ -1500,8 +1476,9 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
|
|
|
1500
1476
|
}
|
|
1501
1477
|
else if (oldAtom.child) {
|
|
1502
1478
|
let atom = oldAtom.child;
|
|
1479
|
+
nativeRenderer.cleanChildren(oldAtom.nativeNode, oldAtom.isSvg);
|
|
1503
1480
|
while (atom) {
|
|
1504
|
-
cleanView(nativeRenderer, atom,
|
|
1481
|
+
cleanView(nativeRenderer, atom, true);
|
|
1505
1482
|
atom = atom.sibling;
|
|
1506
1483
|
}
|
|
1507
1484
|
}
|
|
@@ -1524,7 +1501,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
|
|
|
1524
1501
|
return;
|
|
1525
1502
|
}
|
|
1526
1503
|
if (newTemplate) {
|
|
1527
|
-
|
|
1504
|
+
newAtom.child = createChildChain(newTemplate, newAtom.isSvg);
|
|
1528
1505
|
}
|
|
1529
1506
|
if (newAtom.child) {
|
|
1530
1507
|
diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
|
|
@@ -1542,12 +1519,6 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
|
|
|
1542
1519
|
function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
|
|
1543
1520
|
let child = reusedAtom.child;
|
|
1544
1521
|
newAtom.child = child;
|
|
1545
|
-
const children = [];
|
|
1546
|
-
while (child) {
|
|
1547
|
-
children.push(child);
|
|
1548
|
-
child.parent = newAtom;
|
|
1549
|
-
child = child.sibling;
|
|
1550
|
-
}
|
|
1551
1522
|
const updateContext = (atom) => {
|
|
1552
1523
|
if (atom.jsxNode instanceof Component) {
|
|
1553
1524
|
let child = atom.child;
|
|
@@ -1558,40 +1529,34 @@ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveVi
|
|
|
1558
1529
|
}
|
|
1559
1530
|
else {
|
|
1560
1531
|
if (moveView) {
|
|
1561
|
-
|
|
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
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
else {
|
|
1570
|
-
nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.isSvg);
|
|
1571
|
-
}
|
|
1532
|
+
insertNode(nativeRenderer, atom, context);
|
|
1572
1533
|
}
|
|
1573
1534
|
context.isParent = false;
|
|
1574
1535
|
context.host = atom.nativeNode;
|
|
1575
1536
|
}
|
|
1576
1537
|
};
|
|
1577
|
-
|
|
1578
|
-
updateContext(
|
|
1538
|
+
while (child) {
|
|
1539
|
+
updateContext(child);
|
|
1540
|
+
child = child.sibling;
|
|
1579
1541
|
}
|
|
1580
1542
|
}
|
|
1581
|
-
function cleanView(nativeRenderer, atom,
|
|
1543
|
+
function cleanView(nativeRenderer, atom, needClean) {
|
|
1582
1544
|
if (atom.nativeNode) {
|
|
1583
|
-
if (!
|
|
1545
|
+
if (!needClean) {
|
|
1584
1546
|
nativeRenderer.remove(atom.nativeNode, atom.isSvg);
|
|
1585
|
-
|
|
1547
|
+
needClean = true;
|
|
1586
1548
|
}
|
|
1587
|
-
if (atom.
|
|
1549
|
+
if (atom.type === 'element') {
|
|
1588
1550
|
const ref = atom.jsxNode.props[refKey];
|
|
1589
1551
|
applyRefs(ref, atom.nativeNode, false);
|
|
1590
1552
|
}
|
|
1591
1553
|
}
|
|
1592
1554
|
let child = atom.child;
|
|
1593
1555
|
while (child) {
|
|
1594
|
-
|
|
1556
|
+
if (child.jsxNode instanceof Component && child.jsxNode.instance.$portalHost) {
|
|
1557
|
+
needClean = false;
|
|
1558
|
+
}
|
|
1559
|
+
cleanView(nativeRenderer, child, needClean);
|
|
1595
1560
|
child = child.sibling;
|
|
1596
1561
|
}
|
|
1597
1562
|
if (atom.jsxNode instanceof Component) {
|
|
@@ -1600,9 +1565,7 @@ function cleanView(nativeRenderer, atom, isClean) {
|
|
|
1600
1565
|
}
|
|
1601
1566
|
function componentRender(nativeRenderer, component, from, context) {
|
|
1602
1567
|
const { template, portalHost } = component.render();
|
|
1603
|
-
|
|
1604
|
-
linkTemplate(template, component, from);
|
|
1605
|
-
}
|
|
1568
|
+
from.child = createChildChain(template, from.isSvg);
|
|
1606
1569
|
context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
|
|
1607
1570
|
component.$$view = Object.assign({ atom: from }, context);
|
|
1608
1571
|
let child = from.child;
|
|
@@ -1612,69 +1575,89 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1612
1575
|
}
|
|
1613
1576
|
component.rendered();
|
|
1614
1577
|
}
|
|
1615
|
-
function
|
|
1616
|
-
|
|
1578
|
+
function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
|
|
1579
|
+
const atom = {
|
|
1580
|
+
type: 'component',
|
|
1617
1581
|
jsxNode,
|
|
1618
|
-
parent,
|
|
1619
1582
|
sibling: null,
|
|
1620
1583
|
child: null,
|
|
1621
1584
|
nativeNode: null,
|
|
1622
1585
|
isSvg
|
|
1623
1586
|
};
|
|
1587
|
+
prevAtom.sibling = atom;
|
|
1588
|
+
return atom;
|
|
1624
1589
|
}
|
|
1625
|
-
function
|
|
1590
|
+
function createChainByJSXText(jsxNode, prevAtom, isSvg) {
|
|
1591
|
+
const atom = {
|
|
1592
|
+
type: 'text',
|
|
1593
|
+
jsxNode,
|
|
1594
|
+
sibling: null,
|
|
1595
|
+
child: null,
|
|
1596
|
+
nativeNode: null,
|
|
1597
|
+
isSvg
|
|
1598
|
+
};
|
|
1599
|
+
prevAtom.sibling = atom;
|
|
1600
|
+
return atom;
|
|
1601
|
+
}
|
|
1602
|
+
function createChainByJSXElement(element, prevAtom, isSvg) {
|
|
1626
1603
|
isSvg = isSvg || element.type === 'svg';
|
|
1627
1604
|
const atom = {
|
|
1605
|
+
type: 'element',
|
|
1628
1606
|
jsxNode: element,
|
|
1629
|
-
parent,
|
|
1630
1607
|
sibling: null,
|
|
1631
1608
|
child: null,
|
|
1632
1609
|
nativeNode: null,
|
|
1633
1610
|
isSvg
|
|
1634
1611
|
};
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
const children = createChainByChildren(component, Array.isArray(jsxChildren) ? jsxChildren : [jsxChildren], atom, [], isSvg);
|
|
1638
|
-
link(atom, children);
|
|
1639
|
-
}
|
|
1612
|
+
prevAtom.sibling = atom;
|
|
1613
|
+
atom.child = createChildChain(element.props.children, isSvg);
|
|
1640
1614
|
return atom;
|
|
1641
1615
|
}
|
|
1642
|
-
function
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1616
|
+
function createChainByNode(jsxNode, prevAtom, isSvg) {
|
|
1617
|
+
const type = typeof jsxNode;
|
|
1618
|
+
if (jsxNode !== null && type !== 'undefined' && type !== 'boolean') {
|
|
1619
|
+
if (typeof jsxNode === 'string') {
|
|
1620
|
+
return createChainByJSXText(jsxNode, prevAtom, isSvg);
|
|
1621
|
+
}
|
|
1622
|
+
if (Array.isArray(jsxNode)) {
|
|
1623
|
+
return createChainByChildren(jsxNode, prevAtom, isSvg);
|
|
1624
|
+
}
|
|
1625
|
+
if (type === 'object') {
|
|
1626
|
+
const nodeType = typeof jsxNode.type;
|
|
1627
|
+
if (nodeType === 'string') {
|
|
1628
|
+
return createChainByJSXElement(jsxNode, prevAtom, isSvg);
|
|
1652
1629
|
}
|
|
1653
|
-
if (
|
|
1654
|
-
|
|
1655
|
-
continue;
|
|
1630
|
+
else if (nodeType === 'function') {
|
|
1631
|
+
return createChainByJSXComponent(jsxNode, prevAtom, isSvg);
|
|
1656
1632
|
}
|
|
1657
|
-
if (item instanceof JSXComponent) {
|
|
1658
|
-
const childAtom = createChainByJSXComponentOrJSXText(item, parent, isSvg);
|
|
1659
|
-
atoms.push(childAtom);
|
|
1660
|
-
continue;
|
|
1661
|
-
}
|
|
1662
|
-
atoms.push(createChainByJSXComponentOrJSXText(new JSXText(String(item)), parent, isSvg));
|
|
1663
1633
|
}
|
|
1634
|
+
return createChainByJSXText(String(jsxNode), prevAtom, isSvg);
|
|
1635
|
+
}
|
|
1636
|
+
return prevAtom;
|
|
1637
|
+
}
|
|
1638
|
+
function createChainByChildren(children, prevAtom, isSvg) {
|
|
1639
|
+
for (const item of children) {
|
|
1640
|
+
prevAtom = createChainByNode(item, prevAtom, isSvg);
|
|
1664
1641
|
}
|
|
1665
|
-
return
|
|
1642
|
+
return prevAtom;
|
|
1666
1643
|
}
|
|
1667
|
-
function
|
|
1668
|
-
const
|
|
1669
|
-
|
|
1670
|
-
|
|
1644
|
+
function createChildChain(template, isSvg) {
|
|
1645
|
+
const beforeAtom = { sibling: null };
|
|
1646
|
+
createChainByNode(template, beforeAtom, isSvg);
|
|
1647
|
+
return beforeAtom.sibling;
|
|
1671
1648
|
}
|
|
1672
|
-
function
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1649
|
+
function insertNode(nativeRenderer, atom, context) {
|
|
1650
|
+
if (context.isParent) {
|
|
1651
|
+
if (context.host === context.rootHost) {
|
|
1652
|
+
nativeRenderer.appendChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1653
|
+
}
|
|
1654
|
+
else {
|
|
1655
|
+
nativeRenderer.prependChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
else {
|
|
1659
|
+
nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.isSvg);
|
|
1676
1660
|
}
|
|
1677
|
-
parent.child = children[0] || null;
|
|
1678
1661
|
}
|
|
1679
1662
|
function createElement(nativeRenderer, vNode, isSvg) {
|
|
1680
1663
|
const nativeNode = nativeRenderer.createElement(vNode.type, isSvg);
|
|
@@ -1698,7 +1681,7 @@ function createElement(nativeRenderer, vNode, isSvg) {
|
|
|
1698
1681
|
}
|
|
1699
1682
|
continue;
|
|
1700
1683
|
}
|
|
1701
|
-
if (
|
|
1684
|
+
if (listenerReg.test(key)) {
|
|
1702
1685
|
const listener = props[key];
|
|
1703
1686
|
if (typeof listener === 'function') {
|
|
1704
1687
|
bindEvent(nativeRenderer, vNode, key, nativeNode, listener, isSvg);
|
|
@@ -1718,8 +1701,8 @@ function createElement(nativeRenderer, vNode, isSvg) {
|
|
|
1718
1701
|
}
|
|
1719
1702
|
};
|
|
1720
1703
|
}
|
|
1721
|
-
function createTextNode(nativeRenderer,
|
|
1722
|
-
return nativeRenderer.createTextNode(
|
|
1704
|
+
function createTextNode(nativeRenderer, text, isSvg) {
|
|
1705
|
+
return nativeRenderer.createTextNode(text, isSvg);
|
|
1723
1706
|
}
|
|
1724
1707
|
function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNode, isSvg) {
|
|
1725
1708
|
const changes = getObjectChanges(newVNode.props, oldVNode.props);
|
|
@@ -1740,9 +1723,9 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1740
1723
|
}
|
|
1741
1724
|
continue;
|
|
1742
1725
|
}
|
|
1743
|
-
if (
|
|
1726
|
+
if (listenerReg.test(key)) {
|
|
1744
1727
|
if (typeof value === 'function') {
|
|
1745
|
-
const type = key.replace(
|
|
1728
|
+
const type = key.replace(listenerReg, '').toLowerCase();
|
|
1746
1729
|
const oldOn = oldVNode.on;
|
|
1747
1730
|
nativeRenderer.unListen(nativeNode, type, oldOn[type].delegate, isSvg);
|
|
1748
1731
|
Reflect.deleteProperty(oldOn, type);
|
|
@@ -1777,8 +1760,8 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1777
1760
|
}
|
|
1778
1761
|
continue;
|
|
1779
1762
|
}
|
|
1780
|
-
if (
|
|
1781
|
-
const listenType = key.replace(
|
|
1763
|
+
if (listenerReg.test(key)) {
|
|
1764
|
+
const listenType = key.replace(listenerReg, '').toLowerCase();
|
|
1782
1765
|
newVNode.on[listenType].listenFn = newValue;
|
|
1783
1766
|
continue;
|
|
1784
1767
|
}
|
|
@@ -1804,7 +1787,7 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1804
1787
|
}
|
|
1805
1788
|
continue;
|
|
1806
1789
|
}
|
|
1807
|
-
if (
|
|
1790
|
+
if (listenerReg.test(key)) {
|
|
1808
1791
|
if (typeof value === 'function') {
|
|
1809
1792
|
bindEvent(nativeRenderer, newVNode, key, nativeNode, value, isSvg);
|
|
1810
1793
|
}
|
|
@@ -1822,10 +1805,12 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1822
1805
|
};
|
|
1823
1806
|
}
|
|
1824
1807
|
function applyRefs(refs, nativeNode, binding) {
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1808
|
+
if (refs) {
|
|
1809
|
+
const refList = Array.isArray(refs) ? refs : [refs];
|
|
1810
|
+
for (const item of refList) {
|
|
1811
|
+
if (item instanceof DynamicRef) {
|
|
1812
|
+
binding ? item.bind(nativeNode) : item.unBind(nativeNode);
|
|
1813
|
+
}
|
|
1829
1814
|
}
|
|
1830
1815
|
}
|
|
1831
1816
|
}
|
|
@@ -1834,7 +1819,7 @@ function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn, isSvg) {
|
|
|
1834
1819
|
if (!on) {
|
|
1835
1820
|
vNode.on = on = {};
|
|
1836
1821
|
}
|
|
1837
|
-
const type = key.replace(
|
|
1822
|
+
const type = key.replace(listenerReg, '').toLowerCase();
|
|
1838
1823
|
const delegateObj = {
|
|
1839
1824
|
delegate(...args) {
|
|
1840
1825
|
return delegateObj.listenFn.apply(this, args);
|
|
@@ -1962,9 +1947,7 @@ exports.Inject = Inject;
|
|
|
1962
1947
|
exports.Injectable = Injectable;
|
|
1963
1948
|
exports.InjectionToken = InjectionToken;
|
|
1964
1949
|
exports.Injector = Injector;
|
|
1965
|
-
exports.
|
|
1966
|
-
exports.JSXElement = JSXElement;
|
|
1967
|
-
exports.JSXText = JSXText;
|
|
1950
|
+
exports.JSXNodeFactory = JSXNodeFactory;
|
|
1968
1951
|
exports.NativeRenderer = NativeRenderer;
|
|
1969
1952
|
exports.NullInjector = NullInjector;
|
|
1970
1953
|
exports.Optional = Optional;
|