airx 0.2.0 → 0.2.2
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/README.md +42 -5
- package/output/{index.d.ts → esm/index.d.ts} +1 -0
- package/output/esm/index.js +1212 -0
- package/output/esm/index.js.map +1 -0
- package/output/esm/render/browser.d.ts +7 -0
- package/output/{render → esm/render}/common/index.d.ts +14 -12
- package/output/{render → esm/render}/index.d.ts +2 -1
- package/output/{render/browser.d.ts → esm/render/server.d.ts} +3 -2
- package/output/umd/element.d.ts +46 -0
- package/output/umd/index.d.ts +13 -0
- package/output/umd/index.js +1229 -0
- package/output/umd/index.js.map +1 -0
- package/output/umd/logger.d.ts +3 -0
- package/output/umd/reactive.d.ts +10 -0
- package/output/umd/render/browser.d.ts +7 -0
- package/output/umd/render/common/hooks.d.ts +10 -0
- package/output/umd/render/common/index.d.ts +62 -0
- package/output/umd/render/common/plugins/context.d.ts +5 -0
- package/output/umd/render/common/plugins/index.d.ts +19 -0
- package/output/umd/render/common/plugins/internal/basic.d.ts +10 -0
- package/output/umd/render/common/plugins/internal/inject.d.ts +6 -0
- package/output/umd/render/index.d.ts +4 -0
- package/output/umd/render/server.d.ts +5 -0
- package/output/umd/symbol.d.ts +2 -0
- package/output/umd/types.d.ts +1172 -0
- package/package.json +16 -15
- package/output/element.js +0 -27
- package/output/element.js.map +0 -1
- package/output/index.js +0 -21
- package/output/index.js.map +0 -1
- package/output/logger.js +0 -13
- package/output/logger.js.map +0 -1
- package/output/reactive.js +0 -64
- package/output/reactive.js.map +0 -1
- package/output/render/browser.js +0 -191
- package/output/render/browser.js.map +0 -1
- package/output/render/common/hooks.js +0 -22
- package/output/render/common/hooks.js.map +0 -1
- package/output/render/common/index.js +0 -372
- package/output/render/common/index.js.map +0 -1
- package/output/render/common/plugins/context.js +0 -12
- package/output/render/common/plugins/context.js.map +0 -1
- package/output/render/common/plugins/index.js +0 -2
- package/output/render/common/plugins/index.js.map +0 -1
- package/output/render/common/plugins/internal/basic.js +0 -158
- package/output/render/common/plugins/internal/basic.js.map +0 -1
- package/output/render/common/plugins/internal/inject.js +0 -25
- package/output/render/common/plugins/internal/inject.js.map +0 -1
- package/output/render/index.js +0 -4
- package/output/render/index.js.map +0 -1
- package/output/symbol.js +0 -3
- package/output/symbol.js.map +0 -1
- package/output/types.js +0 -2
- package/output/types.js.map +0 -1
- /package/output/{element.d.ts → esm/element.d.ts} +0 -0
- /package/output/{logger.d.ts → esm/logger.d.ts} +0 -0
- /package/output/{reactive.d.ts → esm/reactive.d.ts} +0 -0
- /package/output/{render → esm/render}/common/hooks.d.ts +0 -0
- /package/output/{render → esm/render}/common/plugins/context.d.ts +0 -0
- /package/output/{render → esm/render}/common/plugins/index.d.ts +0 -0
- /package/output/{render → esm/render}/common/plugins/internal/basic.d.ts +0 -0
- /package/output/{render → esm/render}/common/plugins/internal/inject.d.ts +0 -0
- /package/output/{symbol.d.ts → esm/symbol.d.ts} +0 -0
- /package/output/{types.d.ts → esm/types.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "airx",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "a front framework with jsx",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"./output/index.js"
|
|
9
|
-
]
|
|
10
|
-
},
|
|
5
|
+
"main": "./output/umd/index.js",
|
|
6
|
+
"module": "./output/esm/index.js",
|
|
7
|
+
"types": "./output/esm/index.d.ts",
|
|
11
8
|
"files": [
|
|
12
9
|
"output/*"
|
|
13
10
|
],
|
|
14
11
|
"scripts": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
12
|
+
"dev": "rollup -c -w",
|
|
13
|
+
"build": "rollup -c",
|
|
17
14
|
"lint": "eslint source"
|
|
18
15
|
},
|
|
19
16
|
"dependencies": {
|
|
20
|
-
"csstype": "^3.1.
|
|
17
|
+
"csstype": "^3.1.3"
|
|
21
18
|
},
|
|
22
19
|
"devDependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@
|
|
25
|
-
"
|
|
26
|
-
"typescript": "
|
|
20
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
21
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
22
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
23
|
+
"@typescript-eslint/eslint-plugin": "^7.7.0",
|
|
24
|
+
"@typescript-eslint/parser": "^7.7.0",
|
|
25
|
+
"eslint": "^8.57.0",
|
|
26
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
27
|
+
"typescript": "^5.4.5"
|
|
27
28
|
},
|
|
28
|
-
"author": "",
|
|
29
|
+
"author": "yinxulai",
|
|
29
30
|
"license": "MIT"
|
|
30
31
|
}
|
package/output/element.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as symbol from './symbol';
|
|
2
|
-
/**
|
|
3
|
-
* createElement 是用于创建 AirxElement 的工具函数
|
|
4
|
-
*/
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6
|
-
export function createElement(type, props, ...children) {
|
|
7
|
-
return {
|
|
8
|
-
type,
|
|
9
|
-
props: {
|
|
10
|
-
...props,
|
|
11
|
-
children
|
|
12
|
-
},
|
|
13
|
-
[symbol.airxElementSymbol]: true
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
export function isValidElement(element) {
|
|
17
|
-
return typeof element === 'object'
|
|
18
|
-
&& element !== null
|
|
19
|
-
&& Reflect.get(element, symbol.airxElementSymbol);
|
|
20
|
-
}
|
|
21
|
-
export function Fragment(props) {
|
|
22
|
-
return () => props.children;
|
|
23
|
-
}
|
|
24
|
-
export function component(comp) {
|
|
25
|
-
return comp;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=element.js.map
|
package/output/element.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","sourceRoot":"","sources":["../source/element.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,UAAU,CAAA;AAoClC;;GAEG;AACH,8DAA8D;AAC9D,MAAM,UAAU,aAAa,CAC3B,IAAwB,EACxB,KAAqC,EACrC,GAAG,QAAwB;IAE3B,OAAO;QACL,IAAI;QACJ,KAAK,EAAE;YACL,GAAG,KAAK;YACR,QAAQ;SACT;QACD,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,IAAI;KACjC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAgB;IAC7C,OAAO,OAAO,OAAO,KAAK,QAAQ;WAC7B,OAAO,KAAK,IAAI;WAChB,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAA;AACrD,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAgC;IACvD,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAA;AAC7B,CAAC;AAiBD,MAAM,UAAU,SAAS,CAAc,IAAsB;IAC3D,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/output/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { PluginContext, render } from './render';
|
|
2
|
-
export * from './types';
|
|
3
|
-
export { createSignal, watchSignal } from './reactive';
|
|
4
|
-
export { Fragment, component, createElement } from './element';
|
|
5
|
-
export { inject, provide, onMounted, onUnmounted } from './render';
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
-
export function createApp(element) {
|
|
8
|
-
const appContext = new PluginContext();
|
|
9
|
-
const app = {
|
|
10
|
-
plugin: (...plugins) => {
|
|
11
|
-
appContext.registerPlugin(...plugins);
|
|
12
|
-
return app;
|
|
13
|
-
},
|
|
14
|
-
mount: (container) => {
|
|
15
|
-
render(appContext, element, container);
|
|
16
|
-
return app;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
return app;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
package/output/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAExD,cAAc,SAAS,CAAA;AAEvB,OAAO,EAAE,YAAY,EAAU,WAAW,EAAE,MAAM,YAAY,CAAA;AAE9D,OAAO,EACL,QAAQ,EACR,SAAS,EACT,aAAa,EAKd,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,MAAM,EACN,OAAO,EACP,SAAS,EACT,WAAW,EACZ,MAAM,UAAU,CAAA;AAOjB,8DAA8D;AAC9D,MAAM,UAAU,SAAS,CAAC,OAAyB;IACjD,MAAM,UAAU,GAAG,IAAI,aAAa,EAAE,CAAA;IACtC,MAAM,GAAG,GAAY;QACnB,MAAM,EAAE,CAAC,GAAG,OAAiB,EAAE,EAAE;YAC/B,UAAU,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,CAAA;YACrC,OAAO,GAAG,CAAA;QACZ,CAAC;QAED,KAAK,EAAE,CAAC,SAAsB,EAAE,EAAE;YAChC,MAAM,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;YACtC,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAA;IAED,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
package/output/logger.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const isDev = localStorage.getItem('airx-dev');
|
|
2
|
-
export function createLogger(name) {
|
|
3
|
-
function getPrintPrefix() {
|
|
4
|
-
const date = new Date().toLocaleString();
|
|
5
|
-
return `[${date}][${name}]`;
|
|
6
|
-
}
|
|
7
|
-
function debug(...args) {
|
|
8
|
-
if (isDev)
|
|
9
|
-
console.log(getPrintPrefix(), ...args);
|
|
10
|
-
}
|
|
11
|
-
return { debug };
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=logger.js.map
|
package/output/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../source/logger.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;AAC9C,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,SAAS,cAAc;QACrB,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,cAAc,EAAE,CAAA;QACxC,OAAO,IAAI,IAAI,KAAK,IAAI,GAAG,CAAA;IAC7B,CAAC;IAED,SAAS,KAAK,CAAC,GAAG,IAAe;QAC/B,IAAI,KAAK;YAAE,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,EAAE,GAAG,IAAI,CAAC,CAAA;IACnD,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,CAAA;AAClB,CAAC"}
|
package/output/reactive.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import * as symbol from './symbol';
|
|
2
|
-
/** FIXME: 污染全局总是不好的 */
|
|
3
|
-
const globalContext = {
|
|
4
|
-
dependencies: new Set()
|
|
5
|
-
};
|
|
6
|
-
export function createCollector() {
|
|
7
|
-
const newDependencies = new Set();
|
|
8
|
-
return {
|
|
9
|
-
clear: () => newDependencies.clear(),
|
|
10
|
-
complete: () => [...newDependencies.values()],
|
|
11
|
-
collect: (process) => {
|
|
12
|
-
const beforeDeps = globalContext.dependencies;
|
|
13
|
-
globalContext.dependencies = newDependencies;
|
|
14
|
-
const result = process();
|
|
15
|
-
globalContext.dependencies = beforeDeps;
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function triggerRef(ref) {
|
|
21
|
-
requestAnimationFrame(() => {
|
|
22
|
-
const deps = Reflect.get(ref, symbol.airxReactiveDependenciesSymbol);
|
|
23
|
-
for (const dep of deps) {
|
|
24
|
-
dep();
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function createRefObject(value) {
|
|
29
|
-
const object = Object.create({ value });
|
|
30
|
-
Reflect.defineProperty(object, symbol.airxReactiveDependenciesSymbol, {
|
|
31
|
-
configurable: false,
|
|
32
|
-
enumerable: false,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: new Set()
|
|
35
|
-
});
|
|
36
|
-
return object;
|
|
37
|
-
}
|
|
38
|
-
export function watchSignal(ref, listener) {
|
|
39
|
-
const deps = Reflect.get(ref, symbol.airxReactiveDependenciesSymbol);
|
|
40
|
-
deps.add(listener);
|
|
41
|
-
return () => { deps.delete(listener); };
|
|
42
|
-
}
|
|
43
|
-
export function createSignal(obj) {
|
|
44
|
-
const ref = createRefObject(obj);
|
|
45
|
-
if (!globalContext.dependencies.has(ref)) {
|
|
46
|
-
globalContext.dependencies.add(ref);
|
|
47
|
-
}
|
|
48
|
-
let value = ref.value;
|
|
49
|
-
Reflect.defineProperty(ref, 'value', {
|
|
50
|
-
get() {
|
|
51
|
-
if (!globalContext.dependencies.has(ref)) {
|
|
52
|
-
globalContext.dependencies.add(ref);
|
|
53
|
-
}
|
|
54
|
-
return value;
|
|
55
|
-
},
|
|
56
|
-
set(newValue) {
|
|
57
|
-
value = newValue;
|
|
58
|
-
triggerRef(ref);
|
|
59
|
-
return value;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
return ref;
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=reactive.js.map
|
package/output/reactive.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reactive.js","sourceRoot":"","sources":["../source/reactive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,UAAU,CAAA;AAElC,uBAAuB;AACvB,MAAM,aAAa,GAAG;IACpB,YAAY,EAAE,IAAI,GAAG,EAAmB;CACzC,CAAA;AAED,MAAM,UAAU,eAAe;IAC7B,MAAM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AAG,CAAC,QAAQ,CAAC,CAAA;IAClB,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA,CAAC,CAAC,CAAA;AACxC,CAAC;AAED,MAAM,UAAU,YAAY,CAAI,GAAM;IACpC,MAAM,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;IAEhC,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACxC,aAAa,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;KACpC;IAED,IAAI,KAAK,GAAM,GAAG,CAAC,KAAK,CAAA;IAExB,OAAO,CAAC,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE;QACnC,GAAG;YACD,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBACxC,aAAa,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;aACpC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;QACD,GAAG,CAAC,QAAQ;YACV,KAAK,GAAG,QAAQ,CAAA;YAChB,UAAU,CAAC,GAAG,CAAC,CAAA;YACf,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
package/output/render/browser.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '../logger';
|
|
2
|
-
import { InnerAirxComponentContext, performUnitOfWork } from './common';
|
|
3
|
-
export function render(pluginContext, element, domRef) {
|
|
4
|
-
const rootInstance = {
|
|
5
|
-
domRef,
|
|
6
|
-
context: new InnerAirxComponentContext()
|
|
7
|
-
};
|
|
8
|
-
rootInstance.context.instance = rootInstance;
|
|
9
|
-
const context = {
|
|
10
|
-
rootInstance,
|
|
11
|
-
nextUnitOfWork: null,
|
|
12
|
-
needCommitDom: false
|
|
13
|
-
};
|
|
14
|
-
const appInstance = {
|
|
15
|
-
element,
|
|
16
|
-
parent: context.rootInstance,
|
|
17
|
-
memoProps: { ...element.props },
|
|
18
|
-
context: new InnerAirxComponentContext()
|
|
19
|
-
};
|
|
20
|
-
appInstance.context.instance = appInstance;
|
|
21
|
-
context.rootInstance.child = appInstance;
|
|
22
|
-
context.nextUnitOfWork = appInstance;
|
|
23
|
-
/**
|
|
24
|
-
* 提交 Dom 变化
|
|
25
|
-
*/
|
|
26
|
-
function commitDom(rootInstance, rootNode) {
|
|
27
|
-
const logger = createLogger('commitDom');
|
|
28
|
-
logger.debug('commitDom', rootInstance);
|
|
29
|
-
function updateDomProperties(dom, nextProps, prevProps = {}) {
|
|
30
|
-
for (const plugin of pluginContext.plugins) {
|
|
31
|
-
if (plugin.updateDom)
|
|
32
|
-
plugin.updateDom(dom, nextProps, prevProps);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function getParentDom(instance) {
|
|
36
|
-
if (instance.parent?.domRef != null) {
|
|
37
|
-
return instance.parent.domRef;
|
|
38
|
-
}
|
|
39
|
-
if (instance.parent) {
|
|
40
|
-
return getParentDom(instance.parent);
|
|
41
|
-
}
|
|
42
|
-
throw new Error('Cant find dom');
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 查找 instance 下所有的一级 dom
|
|
46
|
-
* @param instance
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
function getChildDoms(instance) {
|
|
50
|
-
const domList = [];
|
|
51
|
-
const todoList = [instance];
|
|
52
|
-
while (todoList.length > 0) {
|
|
53
|
-
const current = todoList.pop();
|
|
54
|
-
// 找到真实 dom 直接提交
|
|
55
|
-
if (current?.domRef != null) {
|
|
56
|
-
domList.push(current.domRef);
|
|
57
|
-
}
|
|
58
|
-
// 有子节点但是无真实 dom,向下继续查找
|
|
59
|
-
if (current?.domRef == null) {
|
|
60
|
-
if (current?.child != null) {
|
|
61
|
-
todoList.push(current.child);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// 可能有兄弟节点,则需要继续查找
|
|
65
|
-
if (current?.sibling != null) {
|
|
66
|
-
todoList.push(current.sibling);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return domList;
|
|
70
|
-
}
|
|
71
|
-
function commitInstanceDom(nextInstance, oldNode) {
|
|
72
|
-
// 移除标删元素
|
|
73
|
-
if (nextInstance.deletions) {
|
|
74
|
-
for (const deletion of nextInstance.deletions) {
|
|
75
|
-
const domList = getChildDoms(deletion);
|
|
76
|
-
for (let index = 0; index < domList.length; index++) {
|
|
77
|
-
const dom = domList[index];
|
|
78
|
-
if (dom && dom.parentNode)
|
|
79
|
-
dom.parentNode.removeChild(dom);
|
|
80
|
-
}
|
|
81
|
-
deletion.context.triggerUnmounted();
|
|
82
|
-
}
|
|
83
|
-
nextInstance.deletions.clear();
|
|
84
|
-
}
|
|
85
|
-
// 创建 dom
|
|
86
|
-
if (nextInstance.domRef == null) {
|
|
87
|
-
if (nextInstance.element == null)
|
|
88
|
-
throw new Error('???');
|
|
89
|
-
if (typeof nextInstance.element.type === 'string') {
|
|
90
|
-
if (nextInstance.element.type === 'text') {
|
|
91
|
-
const textContent = nextInstance.element.props.textContent;
|
|
92
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
-
nextInstance.domRef = document.createTextNode(textContent);
|
|
94
|
-
}
|
|
95
|
-
else if (nextInstance.element.type === 'comment') {
|
|
96
|
-
const textContent = nextInstance.element.props.textContent;
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
-
nextInstance.domRef = document.createComment(textContent);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
nextInstance.domRef = nextInstance.elementNamespace
|
|
102
|
-
? document.createElementNS(nextInstance.elementNamespace, nextInstance.element.type)
|
|
103
|
-
: document.createElement(nextInstance.element.type);
|
|
104
|
-
}
|
|
105
|
-
if (nextInstance.domRef) {
|
|
106
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
-
nextInstance.domRef.airxInstance = nextInstance;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// 更新属性
|
|
112
|
-
if (nextInstance.domRef != null && nextInstance.element != null) {
|
|
113
|
-
updateDomProperties(nextInstance.domRef, nextInstance.element.props, nextInstance.beforeElement?.props);
|
|
114
|
-
}
|
|
115
|
-
// 插入 parent
|
|
116
|
-
// TODO: 针对仅移动时优化
|
|
117
|
-
if (nextInstance.domRef != null) {
|
|
118
|
-
if (oldNode !== nextInstance.domRef) {
|
|
119
|
-
if (nextInstance.domRef.parentNode) {
|
|
120
|
-
nextInstance.domRef.parentNode.removeChild(nextInstance.domRef);
|
|
121
|
-
}
|
|
122
|
-
const parentDom = getParentDom(nextInstance);
|
|
123
|
-
parentDom.appendChild(nextInstance.domRef);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function commitWalkV2(initInstance, initNode) {
|
|
128
|
-
// 创建一个栈,将根节点压入栈中
|
|
129
|
-
const stack = [[initInstance, initNode]];
|
|
130
|
-
while (stack.length > 0) {
|
|
131
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
132
|
-
const stackLayer = stack.pop();
|
|
133
|
-
if (typeof stackLayer === 'function') {
|
|
134
|
-
stackLayer();
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
const [instance, node] = stackLayer;
|
|
138
|
-
commitInstanceDom(instance, node);
|
|
139
|
-
// stack 是先入后出
|
|
140
|
-
// 实际上是先渲染 child
|
|
141
|
-
// 这里然后再渲染 sibling
|
|
142
|
-
// 执行生命周期的 Mount
|
|
143
|
-
stack.push(() => instance.context.triggerMounted());
|
|
144
|
-
// 更新下一个兄弟节点
|
|
145
|
-
if (instance.sibling != null) {
|
|
146
|
-
const siblingNode = instance.domRef
|
|
147
|
-
? instance.domRef.nextSibling
|
|
148
|
-
: node?.nextSibling;
|
|
149
|
-
stack.push([instance.sibling, siblingNode || undefined]);
|
|
150
|
-
}
|
|
151
|
-
// 更新下一个子节点
|
|
152
|
-
if (instance.child != null) {
|
|
153
|
-
const childNode = instance.domRef
|
|
154
|
-
? instance.domRef.firstChild
|
|
155
|
-
: node;
|
|
156
|
-
stack.push([instance.child, childNode || undefined]);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
commitWalkV2(rootInstance, rootNode);
|
|
161
|
-
}
|
|
162
|
-
function onUpdateRequire() {
|
|
163
|
-
if (context.nextUnitOfWork == null && context.rootInstance.child) {
|
|
164
|
-
context.nextUnitOfWork = context.rootInstance.child;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* 调度
|
|
169
|
-
*/
|
|
170
|
-
function workLoop(deadline) {
|
|
171
|
-
let shouldYield = false;
|
|
172
|
-
const logger = createLogger('workLoop');
|
|
173
|
-
while (context.nextUnitOfWork && !shouldYield) {
|
|
174
|
-
logger.debug('nextUnitOfWork', context.nextUnitOfWork);
|
|
175
|
-
context.nextUnitOfWork = performUnitOfWork(pluginContext, context.nextUnitOfWork, onUpdateRequire);
|
|
176
|
-
if (context.nextUnitOfWork == null)
|
|
177
|
-
context.needCommitDom = true;
|
|
178
|
-
if (deadline)
|
|
179
|
-
shouldYield = deadline.timeRemaining() < 1;
|
|
180
|
-
}
|
|
181
|
-
if (context.needCommitDom && context.rootInstance.child) {
|
|
182
|
-
commitDom(context.rootInstance.child, context.rootInstance.domRef?.firstChild || undefined);
|
|
183
|
-
context.needCommitDom = false;
|
|
184
|
-
}
|
|
185
|
-
requestIdleCallback(workLoop);
|
|
186
|
-
}
|
|
187
|
-
// 开始调度
|
|
188
|
-
workLoop();
|
|
189
|
-
return context.rootInstance;
|
|
190
|
-
}
|
|
191
|
-
//# sourceMappingURL=browser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../source/render/browser.ts"],"names":[],"mappings":"AACA,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,IAAI,CAAC,WAAW,EAAE;YAC7C,MAAM,CAAC,KAAK,CAAC,gBAAgB,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;YACtD,OAAO,CAAC,cAAc,GAAG,iBAAiB,CAAC,aAAa,EAAE,OAAO,CAAC,cAAc,EAAE,eAAe,CAAa,CAAA;YAC9G,IAAI,OAAO,CAAC,cAAc,IAAI,IAAI;gBAAE,OAAO,CAAC,aAAa,GAAG,IAAI,CAAA;YAChE,IAAI,QAAQ;gBAAE,WAAW,GAAG,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,CAAA;SACzD;QAED,IAAI,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE;YACvD,SAAS,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,EAClC,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,UAAU,IAAI,SAAS,CACrD,CAAA;YACD,OAAO,CAAC,aAAa,GAAG,KAAK,CAAA;SAC9B;QAED,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IAC/B,CAAC;IAED,OAAO;IACP,QAAQ,EAAE,CAAA;IACV,OAAO,OAAO,CAAC,YAAY,CAAA;AAC7B,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export const globalContext = {
|
|
2
|
-
current: null
|
|
3
|
-
};
|
|
4
|
-
function useContext() {
|
|
5
|
-
if (globalContext.current == null) {
|
|
6
|
-
throw new Error('Unable to find a valid component context');
|
|
7
|
-
}
|
|
8
|
-
return globalContext.current;
|
|
9
|
-
}
|
|
10
|
-
export const onMounted = (listener) => {
|
|
11
|
-
return useContext().onMounted(listener);
|
|
12
|
-
};
|
|
13
|
-
export const onUnmounted = (listener) => {
|
|
14
|
-
return useContext().onUnmounted(listener);
|
|
15
|
-
};
|
|
16
|
-
export const inject = (key) => {
|
|
17
|
-
return useContext().inject(key);
|
|
18
|
-
};
|
|
19
|
-
export const provide = (key, value) => {
|
|
20
|
-
return useContext().provide(key, value);
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../source/render/common/hooks.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,OAAO,EAAE,IAAI;CACd,CAAA;AAED,SAAS,UAAU;IACjB,IAAI,aAAa,CAAC,OAAO,IAAI,IAAI,EAAE;QACjC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAA;KAC5D;IAED,OAAO,aAAa,CAAC,OAAO,CAAA;AAC9B,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAsC,CAAC,QAAQ,EAAE,EAAE;IACvE,OAAO,UAAU,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;AACzC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,WAAW,GAAwC,CAAC,QAAQ,EAAE,EAAE;IAC3E,OAAO,UAAU,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;AAC3C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAmC,CAAC,GAAG,EAAE,EAAE;IAC5D,OAAO,UAAU,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACjC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAoC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;IACrE,OAAO,UAAU,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AACzC,CAAC,CAAA"}
|