@viewfly/core 3.0.0-alpha.3 → 3.0.0-alpha.5
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/dist/base/_utils.d.ts +0 -1
- package/dist/base/component.d.ts +3 -3
- package/dist/index.esm.js +53 -53
- package/dist/index.js +53 -53
- package/package.json +1 -1
package/dist/base/_utils.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Key, ViewFlyNode } from './jsx-element';
|
|
2
2
|
import { NativeNode } from './injection-tokens';
|
|
3
3
|
import { Component, ComponentSetup } from './component';
|
|
4
|
-
export declare function hasChange(newProps: Record<string, any>, oldProps: Record<string, any>): boolean;
|
|
5
4
|
export declare const refKey = "ref";
|
|
6
5
|
export declare function comparePropsWithCallbacks(oldProps: Record<string, any>, newProps: Record<string, any>, onDeleted: (key: string, oldValue: any) => void, onAdded: (key: string, value: any) => void, onUpdated: (key: string, newValue: any, oldValue: any) => void): void;
|
|
7
6
|
export declare function classToString(config: unknown): string;
|
package/dist/base/component.d.ts
CHANGED
|
@@ -14,10 +14,10 @@ export interface ComponentSetup<P = any> {
|
|
|
14
14
|
}
|
|
15
15
|
export interface ComponentViewMetadata {
|
|
16
16
|
atom: ComponentAtom;
|
|
17
|
-
|
|
17
|
+
anchorNode: NativeNode;
|
|
18
|
+
contextContainer: NativeNode;
|
|
18
19
|
isParent: boolean;
|
|
19
|
-
|
|
20
|
-
expectContainer: NativeNode;
|
|
20
|
+
computedContainer: NativeNode;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Viewfly 组件管理类,用于管理组件的生命周期,上下文等
|
package/dist/index.esm.js
CHANGED
|
@@ -1271,17 +1271,6 @@ function reactive(raw) {
|
|
|
1271
1271
|
}
|
|
1272
1272
|
//#endregion
|
|
1273
1273
|
//#region src/base/_utils.ts
|
|
1274
|
-
function hasChange(newProps, oldProps) {
|
|
1275
|
-
const newKeys = Object.keys(oldProps);
|
|
1276
|
-
const oldKeys = Object.keys(newProps);
|
|
1277
|
-
if (oldKeys.length !== newKeys.length) return true;
|
|
1278
|
-
const len = oldKeys.length;
|
|
1279
|
-
for (let i = 0; i < len; i++) {
|
|
1280
|
-
const key = newKeys[i];
|
|
1281
|
-
if (newProps[key] !== oldProps[key]) return true;
|
|
1282
|
-
}
|
|
1283
|
-
return false;
|
|
1284
|
-
}
|
|
1285
1274
|
function comparePropsWithCallbacks(oldProps, newProps, onDeleted, onAdded, onUpdated) {
|
|
1286
1275
|
for (const key in oldProps) if (!(key in newProps)) onDeleted(key, oldProps[key]);
|
|
1287
1276
|
for (const key in newProps) if (!(key in oldProps)) onAdded(key, newProps[key]);
|
|
@@ -1494,7 +1483,7 @@ var Component = class {
|
|
|
1494
1483
|
this.refEffects = /* @__PURE__ */ new Map();
|
|
1495
1484
|
this.listener = new Dep(() => {
|
|
1496
1485
|
this.markAsDirtied();
|
|
1497
|
-
}, "
|
|
1486
|
+
}, "sync");
|
|
1498
1487
|
}
|
|
1499
1488
|
markAsDirtied() {
|
|
1500
1489
|
this._dirty = true;
|
|
@@ -1530,6 +1519,7 @@ var Component = class {
|
|
|
1530
1519
|
const oldProps = this.rawProps;
|
|
1531
1520
|
this.rawProps = newProps;
|
|
1532
1521
|
const newRefs = newProps.ref;
|
|
1522
|
+
updateRefs(newRefs, this.instance, this.refEffects);
|
|
1533
1523
|
comparePropsWithCallbacks(oldProps, newProps, (key) => {
|
|
1534
1524
|
internalWrite(() => {
|
|
1535
1525
|
Reflect.deleteProperty(oldProps, key);
|
|
@@ -1543,7 +1533,6 @@ var Component = class {
|
|
|
1543
1533
|
this.props[key] = value;
|
|
1544
1534
|
});
|
|
1545
1535
|
});
|
|
1546
|
-
updateRefs(newRefs, this.instance, this.refEffects);
|
|
1547
1536
|
}
|
|
1548
1537
|
rerender() {
|
|
1549
1538
|
this.listener.destroy();
|
|
@@ -1961,8 +1950,9 @@ function createRenderer(component, nativeRenderer, namespace) {
|
|
|
1961
1950
|
namespace
|
|
1962
1951
|
}, {
|
|
1963
1952
|
isParent: true,
|
|
1964
|
-
container,
|
|
1965
|
-
|
|
1953
|
+
anchorNode: container,
|
|
1954
|
+
contextContainer: container,
|
|
1955
|
+
computedContainer: container
|
|
1966
1956
|
});
|
|
1967
1957
|
} else deepUpdateByComponentDirtyTree(nativeRenderer, component, false);
|
|
1968
1958
|
};
|
|
@@ -1984,40 +1974,46 @@ function buildElementChildren(atom, nativeRenderer, parentComponent, context) {
|
|
|
1984
1974
|
}
|
|
1985
1975
|
}
|
|
1986
1976
|
function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, context, needMove) {
|
|
1987
|
-
const oldContainer = component.viewMetadata.container;
|
|
1988
|
-
const expectContainer = component.viewMetadata.expectContainer;
|
|
1989
1977
|
const newTemplate = component.rerender();
|
|
1990
1978
|
const portalContainer = getContainer();
|
|
1979
|
+
const rawContext = context;
|
|
1980
|
+
const { computedContainer } = component.viewMetadata;
|
|
1991
1981
|
popContainer();
|
|
1992
|
-
if (portalContainer
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1982
|
+
if (portalContainer) if (portalContainer === context.contextContainer) {
|
|
1983
|
+
if (portalContainer !== computedContainer) needMove = true;
|
|
1984
|
+
} else {
|
|
1985
|
+
needMove = true;
|
|
1986
|
+
context = {
|
|
1987
|
+
isParent: true,
|
|
1988
|
+
anchorNode: portalContainer,
|
|
1989
|
+
contextContainer: context.contextContainer,
|
|
1990
|
+
computedContainer: portalContainer
|
|
1991
|
+
};
|
|
1992
|
+
}
|
|
1993
|
+
else if (computedContainer !== context.contextContainer) needMove = true;
|
|
1997
1994
|
component.viewMetadata = {
|
|
1998
1995
|
atom: newAtom,
|
|
1999
|
-
expectContainer,
|
|
2000
1996
|
...context
|
|
2001
1997
|
};
|
|
2002
|
-
if (oldContainer !== context.container) needMove = true;
|
|
2003
1998
|
newAtom.child = createChildChain(newTemplate, nativeRenderer, newAtom.namespace);
|
|
2004
1999
|
diff(nativeRenderer, component, newAtom.child, oldChildAtom, context, needMove);
|
|
2005
|
-
return
|
|
2000
|
+
return rawContext;
|
|
2006
2001
|
}
|
|
2007
2002
|
function deepUpdateByComponentDirtyTree(nativeRenderer, component, needMove) {
|
|
2008
2003
|
if (component.dirty) {
|
|
2009
|
-
const { atom,
|
|
2004
|
+
const { atom, anchorNode, isParent, computedContainer, contextContainer } = component.viewMetadata;
|
|
2010
2005
|
const context = {
|
|
2011
|
-
|
|
2006
|
+
anchorNode,
|
|
2012
2007
|
isParent,
|
|
2013
|
-
|
|
2008
|
+
contextContainer,
|
|
2009
|
+
computedContainer
|
|
2014
2010
|
};
|
|
2015
2011
|
const diffAtom = atom.child;
|
|
2016
2012
|
patchComponent(nativeRenderer, component, diffAtom, atom, context, needMove);
|
|
2017
2013
|
const next = atom.sibling;
|
|
2018
2014
|
if (next && next.jsxNode instanceof Component) {
|
|
2019
2015
|
const view = next.jsxNode.viewMetadata;
|
|
2020
|
-
view.
|
|
2016
|
+
view.anchorNode = context.anchorNode;
|
|
2021
2017
|
view.isParent = context.isParent;
|
|
2022
2018
|
}
|
|
2023
2019
|
component.rendered();
|
|
@@ -2095,19 +2091,20 @@ function updateText(nativeRenderer, context, offset, needMove, newAtom, oldAtom)
|
|
|
2095
2091
|
const nativeNode = oldAtom.nativeNode;
|
|
2096
2092
|
newAtom.nativeNode = nativeNode;
|
|
2097
2093
|
if (needMove || newAtom.index - offset !== oldAtom.index) insertNode(nativeRenderer, newAtom, context);
|
|
2098
|
-
context.
|
|
2094
|
+
context.anchorNode = nativeNode;
|
|
2099
2095
|
context.isParent = false;
|
|
2100
2096
|
}
|
|
2101
2097
|
function updateElement(nativeRenderer, context, parentComponent, offset, needMove, newAtom, oldAtom) {
|
|
2102
2098
|
const nativeNode = oldAtom.nativeNode;
|
|
2103
2099
|
newAtom.nativeNode = nativeNode;
|
|
2104
2100
|
if (needMove || newAtom.index - offset !== oldAtom.index) insertNode(nativeRenderer, newAtom, context);
|
|
2105
|
-
context.
|
|
2101
|
+
context.anchorNode = nativeNode;
|
|
2106
2102
|
context.isParent = false;
|
|
2107
2103
|
updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, {
|
|
2108
|
-
|
|
2104
|
+
anchorNode: nativeNode,
|
|
2105
|
+
contextContainer: nativeNode,
|
|
2109
2106
|
isParent: true,
|
|
2110
|
-
|
|
2107
|
+
computedContainer: nativeNode
|
|
2111
2108
|
});
|
|
2112
2109
|
}
|
|
2113
2110
|
function updateComponent(nativeRenderer, context, offset, needMove, newAtom, oldAtom) {
|
|
@@ -2115,20 +2112,18 @@ function updateComponent(nativeRenderer, context, offset, needMove, newAtom, old
|
|
|
2115
2112
|
const newProps = newAtom.jsxNode.props;
|
|
2116
2113
|
newAtom.jsxNode = component;
|
|
2117
2114
|
needMove = needMove || newAtom.index - offset !== oldAtom.index;
|
|
2118
|
-
|
|
2119
|
-
if (
|
|
2120
|
-
if (propsIsChanged || component.dirty) {
|
|
2115
|
+
component.updateProps(newProps);
|
|
2116
|
+
if (component.dirty) {
|
|
2121
2117
|
const updatedContext = patchComponent(nativeRenderer, component, oldAtom.child, newAtom, context, needMove);
|
|
2122
2118
|
const next = oldAtom.sibling;
|
|
2123
2119
|
if (next && next.jsxNode instanceof Component) {
|
|
2124
2120
|
const view = next.jsxNode.viewMetadata;
|
|
2125
|
-
view.
|
|
2121
|
+
view.anchorNode = updatedContext.anchorNode;
|
|
2126
2122
|
view.isParent = updatedContext.isParent;
|
|
2127
2123
|
}
|
|
2128
2124
|
} else {
|
|
2129
2125
|
component.viewMetadata = {
|
|
2130
2126
|
atom: newAtom,
|
|
2131
|
-
expectContainer: component.viewMetadata.expectContainer,
|
|
2132
2127
|
...context
|
|
2133
2128
|
};
|
|
2134
2129
|
newAtom.child = oldAtom.child;
|
|
@@ -2146,7 +2141,7 @@ function reuseComponentView(nativeRenderer, child, context, moveView, skipSubCom
|
|
|
2146
2141
|
if (moveView) insertNode(nativeRenderer, atom, context);
|
|
2147
2142
|
if (!skipSubComponentDiff) reuseElementChildrenView(nativeRenderer, atom, context);
|
|
2148
2143
|
context.isParent = false;
|
|
2149
|
-
context.
|
|
2144
|
+
context.anchorNode = atom.nativeNode;
|
|
2150
2145
|
}
|
|
2151
2146
|
};
|
|
2152
2147
|
while (child) {
|
|
@@ -2173,7 +2168,7 @@ function cleanElementChildren(atom, nativeRenderer) {
|
|
|
2173
2168
|
function cleanView(nativeRenderer, atom, needClean) {
|
|
2174
2169
|
if (atom.type === ComponentAtomType) {
|
|
2175
2170
|
const jsxNode = atom.jsxNode;
|
|
2176
|
-
if (jsxNode.viewMetadata.
|
|
2171
|
+
if (jsxNode.viewMetadata.computedContainer !== jsxNode.viewMetadata.contextContainer) needClean = true;
|
|
2177
2172
|
cleanChildren(atom, nativeRenderer, needClean);
|
|
2178
2173
|
jsxNode.destroy();
|
|
2179
2174
|
return;
|
|
@@ -2205,15 +2200,14 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
2205
2200
|
const portalContainer = getContainer();
|
|
2206
2201
|
popContainer();
|
|
2207
2202
|
from.child = createChildChain(template, nativeRenderer, from.namespace);
|
|
2208
|
-
|
|
2209
|
-
context = portalContainer && portalContainer !== context.container ? {
|
|
2203
|
+
if (portalContainer && portalContainer !== context.contextContainer) context = {
|
|
2210
2204
|
isParent: true,
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2205
|
+
anchorNode: portalContainer,
|
|
2206
|
+
contextContainer: context.contextContainer,
|
|
2207
|
+
computedContainer: portalContainer
|
|
2208
|
+
};
|
|
2214
2209
|
component.viewMetadata = {
|
|
2215
2210
|
atom: from,
|
|
2216
|
-
expectContainer,
|
|
2217
2211
|
...context
|
|
2218
2212
|
};
|
|
2219
2213
|
let child = from.child;
|
|
@@ -2270,9 +2264,9 @@ function createChildChain(template, nativeRenderer, namespace) {
|
|
|
2270
2264
|
return beforeAtom.sibling;
|
|
2271
2265
|
}
|
|
2272
2266
|
function insertNode(nativeRenderer, atom, context) {
|
|
2273
|
-
if (context.isParent) if (context.
|
|
2274
|
-
else nativeRenderer.
|
|
2275
|
-
else nativeRenderer.insertAfter(atom.nativeNode, context.
|
|
2267
|
+
if (context.isParent) if (context.contextContainer === context.computedContainer) nativeRenderer.prependChild(context.anchorNode, atom.nativeNode, atom.namespace);
|
|
2268
|
+
else nativeRenderer.appendChild(context.anchorNode, atom.nativeNode, atom.namespace);
|
|
2269
|
+
else nativeRenderer.insertAfter(atom.nativeNode, context.anchorNode, atom.namespace);
|
|
2276
2270
|
}
|
|
2277
2271
|
function createElementChildren(type, children, nativeRenderer, namespace) {
|
|
2278
2272
|
return createChildChain(children, nativeRenderer, nativeRenderer.getNameSpace(type, namespace));
|
|
@@ -2312,10 +2306,11 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
|
2312
2306
|
insertNode(nativeRenderer, atom, context);
|
|
2313
2307
|
buildElementChildren(atom, nativeRenderer, parentComponent, {
|
|
2314
2308
|
isParent: true,
|
|
2315
|
-
|
|
2316
|
-
|
|
2309
|
+
anchorNode: nativeNode,
|
|
2310
|
+
contextContainer: nativeNode,
|
|
2311
|
+
computedContainer: nativeNode
|
|
2317
2312
|
});
|
|
2318
|
-
context.
|
|
2313
|
+
context.anchorNode = nativeNode;
|
|
2319
2314
|
context.isParent = false;
|
|
2320
2315
|
if (bindingRefs) {
|
|
2321
2316
|
const refEffects = /* @__PURE__ */ new Map();
|
|
@@ -2327,7 +2322,7 @@ function createTextNode(nativeRenderer, atom, context) {
|
|
|
2327
2322
|
const nativeNode = nativeRenderer.createTextNode(atom.jsxNode, atom.namespace);
|
|
2328
2323
|
atom.nativeNode = nativeNode;
|
|
2329
2324
|
insertNode(nativeRenderer, atom, context);
|
|
2330
|
-
context.
|
|
2325
|
+
context.anchorNode = nativeNode;
|
|
2331
2326
|
context.isParent = false;
|
|
2332
2327
|
}
|
|
2333
2328
|
function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, context) {
|
|
@@ -2336,6 +2331,11 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
2336
2331
|
const nativeNode = newAtom.nativeNode;
|
|
2337
2332
|
const oldVNode = oldAtom.jsxNode;
|
|
2338
2333
|
if (newVNode === oldVNode) {
|
|
2334
|
+
const refEffects = nativeNodeRefRecord.get(oldAtom);
|
|
2335
|
+
if (refEffects) {
|
|
2336
|
+
nativeNodeRefRecord.delete(oldAtom);
|
|
2337
|
+
nativeNodeRefRecord.set(newAtom, refEffects);
|
|
2338
|
+
}
|
|
2339
2339
|
newAtom.child = oldAtom.child;
|
|
2340
2340
|
reuseElementChildrenView(nativeRenderer, newAtom, context);
|
|
2341
2341
|
return;
|
package/dist/index.js
CHANGED
|
@@ -1272,17 +1272,6 @@ function reactive(raw) {
|
|
|
1272
1272
|
}
|
|
1273
1273
|
//#endregion
|
|
1274
1274
|
//#region src/base/_utils.ts
|
|
1275
|
-
function hasChange(newProps, oldProps) {
|
|
1276
|
-
const newKeys = Object.keys(oldProps);
|
|
1277
|
-
const oldKeys = Object.keys(newProps);
|
|
1278
|
-
if (oldKeys.length !== newKeys.length) return true;
|
|
1279
|
-
const len = oldKeys.length;
|
|
1280
|
-
for (let i = 0; i < len; i++) {
|
|
1281
|
-
const key = newKeys[i];
|
|
1282
|
-
if (newProps[key] !== oldProps[key]) return true;
|
|
1283
|
-
}
|
|
1284
|
-
return false;
|
|
1285
|
-
}
|
|
1286
1275
|
function comparePropsWithCallbacks(oldProps, newProps, onDeleted, onAdded, onUpdated) {
|
|
1287
1276
|
for (const key in oldProps) if (!(key in newProps)) onDeleted(key, oldProps[key]);
|
|
1288
1277
|
for (const key in newProps) if (!(key in oldProps)) onAdded(key, newProps[key]);
|
|
@@ -1495,7 +1484,7 @@ var Component = class {
|
|
|
1495
1484
|
this.refEffects = /* @__PURE__ */ new Map();
|
|
1496
1485
|
this.listener = new Dep(() => {
|
|
1497
1486
|
this.markAsDirtied();
|
|
1498
|
-
}, "
|
|
1487
|
+
}, "sync");
|
|
1499
1488
|
}
|
|
1500
1489
|
markAsDirtied() {
|
|
1501
1490
|
this._dirty = true;
|
|
@@ -1531,6 +1520,7 @@ var Component = class {
|
|
|
1531
1520
|
const oldProps = this.rawProps;
|
|
1532
1521
|
this.rawProps = newProps;
|
|
1533
1522
|
const newRefs = newProps.ref;
|
|
1523
|
+
updateRefs(newRefs, this.instance, this.refEffects);
|
|
1534
1524
|
comparePropsWithCallbacks(oldProps, newProps, (key) => {
|
|
1535
1525
|
internalWrite(() => {
|
|
1536
1526
|
Reflect.deleteProperty(oldProps, key);
|
|
@@ -1544,7 +1534,6 @@ var Component = class {
|
|
|
1544
1534
|
this.props[key] = value;
|
|
1545
1535
|
});
|
|
1546
1536
|
});
|
|
1547
|
-
updateRefs(newRefs, this.instance, this.refEffects);
|
|
1548
1537
|
}
|
|
1549
1538
|
rerender() {
|
|
1550
1539
|
this.listener.destroy();
|
|
@@ -1962,8 +1951,9 @@ function createRenderer(component, nativeRenderer, namespace) {
|
|
|
1962
1951
|
namespace
|
|
1963
1952
|
}, {
|
|
1964
1953
|
isParent: true,
|
|
1965
|
-
container,
|
|
1966
|
-
|
|
1954
|
+
anchorNode: container,
|
|
1955
|
+
contextContainer: container,
|
|
1956
|
+
computedContainer: container
|
|
1967
1957
|
});
|
|
1968
1958
|
} else deepUpdateByComponentDirtyTree(nativeRenderer, component, false);
|
|
1969
1959
|
};
|
|
@@ -1985,40 +1975,46 @@ function buildElementChildren(atom, nativeRenderer, parentComponent, context) {
|
|
|
1985
1975
|
}
|
|
1986
1976
|
}
|
|
1987
1977
|
function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, context, needMove) {
|
|
1988
|
-
const oldContainer = component.viewMetadata.container;
|
|
1989
|
-
const expectContainer = component.viewMetadata.expectContainer;
|
|
1990
1978
|
const newTemplate = component.rerender();
|
|
1991
1979
|
const portalContainer = getContainer();
|
|
1980
|
+
const rawContext = context;
|
|
1981
|
+
const { computedContainer } = component.viewMetadata;
|
|
1992
1982
|
popContainer();
|
|
1993
|
-
if (portalContainer
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1983
|
+
if (portalContainer) if (portalContainer === context.contextContainer) {
|
|
1984
|
+
if (portalContainer !== computedContainer) needMove = true;
|
|
1985
|
+
} else {
|
|
1986
|
+
needMove = true;
|
|
1987
|
+
context = {
|
|
1988
|
+
isParent: true,
|
|
1989
|
+
anchorNode: portalContainer,
|
|
1990
|
+
contextContainer: context.contextContainer,
|
|
1991
|
+
computedContainer: portalContainer
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1994
|
+
else if (computedContainer !== context.contextContainer) needMove = true;
|
|
1998
1995
|
component.viewMetadata = {
|
|
1999
1996
|
atom: newAtom,
|
|
2000
|
-
expectContainer,
|
|
2001
1997
|
...context
|
|
2002
1998
|
};
|
|
2003
|
-
if (oldContainer !== context.container) needMove = true;
|
|
2004
1999
|
newAtom.child = createChildChain(newTemplate, nativeRenderer, newAtom.namespace);
|
|
2005
2000
|
diff(nativeRenderer, component, newAtom.child, oldChildAtom, context, needMove);
|
|
2006
|
-
return
|
|
2001
|
+
return rawContext;
|
|
2007
2002
|
}
|
|
2008
2003
|
function deepUpdateByComponentDirtyTree(nativeRenderer, component, needMove) {
|
|
2009
2004
|
if (component.dirty) {
|
|
2010
|
-
const { atom,
|
|
2005
|
+
const { atom, anchorNode, isParent, computedContainer, contextContainer } = component.viewMetadata;
|
|
2011
2006
|
const context = {
|
|
2012
|
-
|
|
2007
|
+
anchorNode,
|
|
2013
2008
|
isParent,
|
|
2014
|
-
|
|
2009
|
+
contextContainer,
|
|
2010
|
+
computedContainer
|
|
2015
2011
|
};
|
|
2016
2012
|
const diffAtom = atom.child;
|
|
2017
2013
|
patchComponent(nativeRenderer, component, diffAtom, atom, context, needMove);
|
|
2018
2014
|
const next = atom.sibling;
|
|
2019
2015
|
if (next && next.jsxNode instanceof Component) {
|
|
2020
2016
|
const view = next.jsxNode.viewMetadata;
|
|
2021
|
-
view.
|
|
2017
|
+
view.anchorNode = context.anchorNode;
|
|
2022
2018
|
view.isParent = context.isParent;
|
|
2023
2019
|
}
|
|
2024
2020
|
component.rendered();
|
|
@@ -2096,19 +2092,20 @@ function updateText(nativeRenderer, context, offset, needMove, newAtom, oldAtom)
|
|
|
2096
2092
|
const nativeNode = oldAtom.nativeNode;
|
|
2097
2093
|
newAtom.nativeNode = nativeNode;
|
|
2098
2094
|
if (needMove || newAtom.index - offset !== oldAtom.index) insertNode(nativeRenderer, newAtom, context);
|
|
2099
|
-
context.
|
|
2095
|
+
context.anchorNode = nativeNode;
|
|
2100
2096
|
context.isParent = false;
|
|
2101
2097
|
}
|
|
2102
2098
|
function updateElement(nativeRenderer, context, parentComponent, offset, needMove, newAtom, oldAtom) {
|
|
2103
2099
|
const nativeNode = oldAtom.nativeNode;
|
|
2104
2100
|
newAtom.nativeNode = nativeNode;
|
|
2105
2101
|
if (needMove || newAtom.index - offset !== oldAtom.index) insertNode(nativeRenderer, newAtom, context);
|
|
2106
|
-
context.
|
|
2102
|
+
context.anchorNode = nativeNode;
|
|
2107
2103
|
context.isParent = false;
|
|
2108
2104
|
updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, {
|
|
2109
|
-
|
|
2105
|
+
anchorNode: nativeNode,
|
|
2106
|
+
contextContainer: nativeNode,
|
|
2110
2107
|
isParent: true,
|
|
2111
|
-
|
|
2108
|
+
computedContainer: nativeNode
|
|
2112
2109
|
});
|
|
2113
2110
|
}
|
|
2114
2111
|
function updateComponent(nativeRenderer, context, offset, needMove, newAtom, oldAtom) {
|
|
@@ -2116,20 +2113,18 @@ function updateComponent(nativeRenderer, context, offset, needMove, newAtom, old
|
|
|
2116
2113
|
const newProps = newAtom.jsxNode.props;
|
|
2117
2114
|
newAtom.jsxNode = component;
|
|
2118
2115
|
needMove = needMove || newAtom.index - offset !== oldAtom.index;
|
|
2119
|
-
|
|
2120
|
-
if (
|
|
2121
|
-
if (propsIsChanged || component.dirty) {
|
|
2116
|
+
component.updateProps(newProps);
|
|
2117
|
+
if (component.dirty) {
|
|
2122
2118
|
const updatedContext = patchComponent(nativeRenderer, component, oldAtom.child, newAtom, context, needMove);
|
|
2123
2119
|
const next = oldAtom.sibling;
|
|
2124
2120
|
if (next && next.jsxNode instanceof Component) {
|
|
2125
2121
|
const view = next.jsxNode.viewMetadata;
|
|
2126
|
-
view.
|
|
2122
|
+
view.anchorNode = updatedContext.anchorNode;
|
|
2127
2123
|
view.isParent = updatedContext.isParent;
|
|
2128
2124
|
}
|
|
2129
2125
|
} else {
|
|
2130
2126
|
component.viewMetadata = {
|
|
2131
2127
|
atom: newAtom,
|
|
2132
|
-
expectContainer: component.viewMetadata.expectContainer,
|
|
2133
2128
|
...context
|
|
2134
2129
|
};
|
|
2135
2130
|
newAtom.child = oldAtom.child;
|
|
@@ -2147,7 +2142,7 @@ function reuseComponentView(nativeRenderer, child, context, moveView, skipSubCom
|
|
|
2147
2142
|
if (moveView) insertNode(nativeRenderer, atom, context);
|
|
2148
2143
|
if (!skipSubComponentDiff) reuseElementChildrenView(nativeRenderer, atom, context);
|
|
2149
2144
|
context.isParent = false;
|
|
2150
|
-
context.
|
|
2145
|
+
context.anchorNode = atom.nativeNode;
|
|
2151
2146
|
}
|
|
2152
2147
|
};
|
|
2153
2148
|
while (child) {
|
|
@@ -2174,7 +2169,7 @@ function cleanElementChildren(atom, nativeRenderer) {
|
|
|
2174
2169
|
function cleanView(nativeRenderer, atom, needClean) {
|
|
2175
2170
|
if (atom.type === ComponentAtomType) {
|
|
2176
2171
|
const jsxNode = atom.jsxNode;
|
|
2177
|
-
if (jsxNode.viewMetadata.
|
|
2172
|
+
if (jsxNode.viewMetadata.computedContainer !== jsxNode.viewMetadata.contextContainer) needClean = true;
|
|
2178
2173
|
cleanChildren(atom, nativeRenderer, needClean);
|
|
2179
2174
|
jsxNode.destroy();
|
|
2180
2175
|
return;
|
|
@@ -2206,15 +2201,14 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
2206
2201
|
const portalContainer = getContainer();
|
|
2207
2202
|
popContainer();
|
|
2208
2203
|
from.child = createChildChain(template, nativeRenderer, from.namespace);
|
|
2209
|
-
|
|
2210
|
-
context = portalContainer && portalContainer !== context.container ? {
|
|
2204
|
+
if (portalContainer && portalContainer !== context.contextContainer) context = {
|
|
2211
2205
|
isParent: true,
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2206
|
+
anchorNode: portalContainer,
|
|
2207
|
+
contextContainer: context.contextContainer,
|
|
2208
|
+
computedContainer: portalContainer
|
|
2209
|
+
};
|
|
2215
2210
|
component.viewMetadata = {
|
|
2216
2211
|
atom: from,
|
|
2217
|
-
expectContainer,
|
|
2218
2212
|
...context
|
|
2219
2213
|
};
|
|
2220
2214
|
let child = from.child;
|
|
@@ -2271,9 +2265,9 @@ function createChildChain(template, nativeRenderer, namespace) {
|
|
|
2271
2265
|
return beforeAtom.sibling;
|
|
2272
2266
|
}
|
|
2273
2267
|
function insertNode(nativeRenderer, atom, context) {
|
|
2274
|
-
if (context.isParent) if (context.
|
|
2275
|
-
else nativeRenderer.
|
|
2276
|
-
else nativeRenderer.insertAfter(atom.nativeNode, context.
|
|
2268
|
+
if (context.isParent) if (context.contextContainer === context.computedContainer) nativeRenderer.prependChild(context.anchorNode, atom.nativeNode, atom.namespace);
|
|
2269
|
+
else nativeRenderer.appendChild(context.anchorNode, atom.nativeNode, atom.namespace);
|
|
2270
|
+
else nativeRenderer.insertAfter(atom.nativeNode, context.anchorNode, atom.namespace);
|
|
2277
2271
|
}
|
|
2278
2272
|
function createElementChildren(type, children, nativeRenderer, namespace) {
|
|
2279
2273
|
return createChildChain(children, nativeRenderer, nativeRenderer.getNameSpace(type, namespace));
|
|
@@ -2313,10 +2307,11 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
|
2313
2307
|
insertNode(nativeRenderer, atom, context);
|
|
2314
2308
|
buildElementChildren(atom, nativeRenderer, parentComponent, {
|
|
2315
2309
|
isParent: true,
|
|
2316
|
-
|
|
2317
|
-
|
|
2310
|
+
anchorNode: nativeNode,
|
|
2311
|
+
contextContainer: nativeNode,
|
|
2312
|
+
computedContainer: nativeNode
|
|
2318
2313
|
});
|
|
2319
|
-
context.
|
|
2314
|
+
context.anchorNode = nativeNode;
|
|
2320
2315
|
context.isParent = false;
|
|
2321
2316
|
if (bindingRefs) {
|
|
2322
2317
|
const refEffects = /* @__PURE__ */ new Map();
|
|
@@ -2328,7 +2323,7 @@ function createTextNode(nativeRenderer, atom, context) {
|
|
|
2328
2323
|
const nativeNode = nativeRenderer.createTextNode(atom.jsxNode, atom.namespace);
|
|
2329
2324
|
atom.nativeNode = nativeNode;
|
|
2330
2325
|
insertNode(nativeRenderer, atom, context);
|
|
2331
|
-
context.
|
|
2326
|
+
context.anchorNode = nativeNode;
|
|
2332
2327
|
context.isParent = false;
|
|
2333
2328
|
}
|
|
2334
2329
|
function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, context) {
|
|
@@ -2337,6 +2332,11 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
2337
2332
|
const nativeNode = newAtom.nativeNode;
|
|
2338
2333
|
const oldVNode = oldAtom.jsxNode;
|
|
2339
2334
|
if (newVNode === oldVNode) {
|
|
2335
|
+
const refEffects = nativeNodeRefRecord.get(oldAtom);
|
|
2336
|
+
if (refEffects) {
|
|
2337
|
+
nativeNodeRefRecord.delete(oldAtom);
|
|
2338
|
+
nativeNodeRefRecord.set(newAtom, refEffects);
|
|
2339
|
+
}
|
|
2340
2340
|
newAtom.child = oldAtom.child;
|
|
2341
2341
|
reuseElementChildrenView(nativeRenderer, newAtom, context);
|
|
2342
2342
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/core",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.5",
|
|
4
4
|
"description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|