@rsmax/runtime 1.0.1
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/CHANGELOG.md +6 -0
- package/cjs/AppContainer.d.ts +22 -0
- package/cjs/AppContainer.js +40 -0
- package/cjs/Container.d.ts +39 -0
- package/cjs/Container.js +120 -0
- package/cjs/ReactPortal.d.ts +2 -0
- package/cjs/ReactPortal.js +15 -0
- package/cjs/SyntheticEvent/constants.d.ts +2 -0
- package/cjs/SyntheticEvent/constants.js +13 -0
- package/cjs/SyntheticEvent/createCallbackProxy.d.ts +2 -0
- package/cjs/SyntheticEvent/createCallbackProxy.js +59 -0
- package/cjs/SyntheticEvent/stopPropagation.d.ts +13 -0
- package/cjs/SyntheticEvent/stopPropagation.js +33 -0
- package/cjs/VNode.d.ts +45 -0
- package/cjs/VNode.js +276 -0
- package/cjs/constants.d.ts +3 -0
- package/cjs/constants.js +6 -0
- package/cjs/createAppConfig.d.ts +2 -0
- package/cjs/createAppConfig.js +124 -0
- package/cjs/createComponentConfig.d.ts +2 -0
- package/cjs/createComponentConfig.js +74 -0
- package/cjs/createComponentConfig.wechat.d.ts +2 -0
- package/cjs/createComponentConfig.wechat.js +89 -0
- package/cjs/createHostComponent.d.ts +2 -0
- package/cjs/createHostComponent.js +20 -0
- package/cjs/createNativeComponent.d.ts +2 -0
- package/cjs/createNativeComponent.js +23 -0
- package/cjs/createPageConfig.d.ts +3 -0
- package/cjs/createPageConfig.js +191 -0
- package/cjs/hooks/index.d.ts +3 -0
- package/cjs/hooks/index.js +15 -0
- package/cjs/hooks/useNativeEffect.d.ts +3 -0
- package/cjs/hooks/useNativeEffect.js +13 -0
- package/cjs/hooks/useQuery.d.ts +3 -0
- package/cjs/hooks/useQuery.js +9 -0
- package/cjs/hostConfig/diffProperties.d.ts +1 -0
- package/cjs/hostConfig/diffProperties.js +100 -0
- package/cjs/hostConfig/index.d.ts +42 -0
- package/cjs/hostConfig/index.js +159 -0
- package/cjs/index.d.ts +14 -0
- package/cjs/index.js +43 -0
- package/cjs/instanceId.d.ts +2 -0
- package/cjs/instanceId.js +14 -0
- package/cjs/nativeEffect.d.ts +10 -0
- package/cjs/nativeEffect.js +25 -0
- package/cjs/polyfills/Function.d.ts +0 -0
- package/cjs/polyfills/Function.js +29 -0
- package/cjs/propsAlias.d.ts +6 -0
- package/cjs/propsAlias.js +51 -0
- package/cjs/render.d.ts +6 -0
- package/cjs/render.js +35 -0
- package/cjs/stopPullDownRefresh/index.ali.d.ts +2 -0
- package/cjs/stopPullDownRefresh/index.ali.js +3 -0
- package/cjs/stopPullDownRefresh/index.d.ts +1 -0
- package/cjs/stopPullDownRefresh/index.js +6 -0
- package/cjs/stopPullDownRefresh/index.toutiao.d.ts +2 -0
- package/cjs/stopPullDownRefresh/index.toutiao.js +3 -0
- package/cjs/stopPullDownRefresh/index.wechat.d.ts +2 -0
- package/cjs/stopPullDownRefresh/index.wechat.js +3 -0
- package/cjs/utils/capitalize.d.ts +1 -0
- package/cjs/utils/capitalize.js +6 -0
- package/cjs/utils/isClassComponent.d.ts +2 -0
- package/cjs/utils/isClassComponent.js +6 -0
- package/cjs/utils/lowercase.d.ts +1 -0
- package/cjs/utils/lowercase.js +6 -0
- package/cjs/utils/plainStyle/CSSProperty.d.ts +6 -0
- package/cjs/utils/plainStyle/CSSProperty.js +71 -0
- package/cjs/utils/plainStyle/index.d.ts +2 -0
- package/cjs/utils/plainStyle/index.js +45 -0
- package/esm/AppContainer.d.ts +22 -0
- package/esm/AppContainer.js +34 -0
- package/esm/Container.d.ts +39 -0
- package/esm/Container.js +114 -0
- package/esm/ReactPortal.d.ts +2 -0
- package/esm/ReactPortal.js +11 -0
- package/esm/SyntheticEvent/constants.d.ts +2 -0
- package/esm/SyntheticEvent/constants.js +10 -0
- package/esm/SyntheticEvent/createCallbackProxy.d.ts +2 -0
- package/esm/SyntheticEvent/createCallbackProxy.js +32 -0
- package/esm/SyntheticEvent/stopPropagation.d.ts +13 -0
- package/esm/SyntheticEvent/stopPropagation.js +28 -0
- package/esm/VNode.d.ts +45 -0
- package/esm/VNode.js +250 -0
- package/esm/constants.d.ts +3 -0
- package/esm/constants.js +3 -0
- package/esm/createAppConfig.d.ts +2 -0
- package/esm/createAppConfig.js +95 -0
- package/esm/createComponentConfig.d.ts +2 -0
- package/esm/createComponentConfig.js +45 -0
- package/esm/createComponentConfig.wechat.d.ts +2 -0
- package/esm/createComponentConfig.wechat.js +60 -0
- package/esm/createHostComponent.d.ts +2 -0
- package/esm/createHostComponent.js +14 -0
- package/esm/createNativeComponent.d.ts +2 -0
- package/esm/createNativeComponent.js +17 -0
- package/esm/createPageConfig.d.ts +3 -0
- package/esm/createPageConfig.js +183 -0
- package/esm/hooks/index.d.ts +3 -0
- package/esm/hooks/index.js +3 -0
- package/esm/hooks/useNativeEffect.d.ts +3 -0
- package/esm/hooks/useNativeEffect.js +7 -0
- package/esm/hooks/useQuery.d.ts +3 -0
- package/esm/hooks/useQuery.js +6 -0
- package/esm/hostConfig/diffProperties.d.ts +1 -0
- package/esm/hostConfig/diffProperties.js +97 -0
- package/esm/hostConfig/index.d.ts +42 -0
- package/esm/hostConfig/index.js +154 -0
- package/esm/index.d.ts +14 -0
- package/esm/index.js +14 -0
- package/esm/instanceId.d.ts +2 -0
- package/esm/instanceId.js +9 -0
- package/esm/nativeEffect.d.ts +10 -0
- package/esm/nativeEffect.js +23 -0
- package/esm/polyfills/Function.d.ts +0 -0
- package/esm/polyfills/Function.js +29 -0
- package/esm/propsAlias.d.ts +6 -0
- package/esm/propsAlias.js +42 -0
- package/esm/render.d.ts +6 -0
- package/esm/render.js +28 -0
- package/esm/stopPullDownRefresh/index.ali.d.ts +2 -0
- package/esm/stopPullDownRefresh/index.ali.js +1 -0
- package/esm/stopPullDownRefresh/index.d.ts +1 -0
- package/esm/stopPullDownRefresh/index.js +3 -0
- package/esm/stopPullDownRefresh/index.toutiao.d.ts +2 -0
- package/esm/stopPullDownRefresh/index.toutiao.js +1 -0
- package/esm/stopPullDownRefresh/index.wechat.d.ts +2 -0
- package/esm/stopPullDownRefresh/index.wechat.js +1 -0
- package/esm/utils/capitalize.d.ts +1 -0
- package/esm/utils/capitalize.js +3 -0
- package/esm/utils/isClassComponent.d.ts +2 -0
- package/esm/utils/isClassComponent.js +3 -0
- package/esm/utils/lowercase.d.ts +1 -0
- package/esm/utils/lowercase.js +3 -0
- package/esm/utils/plainStyle/CSSProperty.d.ts +6 -0
- package/esm/utils/plainStyle/CSSProperty.js +68 -0
- package/esm/utils/plainStyle/index.d.ts +2 -0
- package/esm/utils/plainStyle/index.js +43 -0
- package/package.json +56 -0
- package/typings/index.d.ts +6 -0
- package/vitest.config.js +9 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import VNode, { RawNode } from './VNode';
|
|
2
|
+
import { FiberRoot } from 'react-reconciler';
|
|
3
|
+
interface SpliceUpdate {
|
|
4
|
+
path: string;
|
|
5
|
+
start: number;
|
|
6
|
+
deleteCount: number;
|
|
7
|
+
items: RawNode[];
|
|
8
|
+
}
|
|
9
|
+
export default class AppContainer {
|
|
10
|
+
context: any;
|
|
11
|
+
root: VNode;
|
|
12
|
+
updateQueue: SpliceUpdate[];
|
|
13
|
+
_rootContainer?: FiberRoot;
|
|
14
|
+
constructor();
|
|
15
|
+
requestUpdate(path: string, start: number, deleteCount: number, ...items: RawNode[]): void;
|
|
16
|
+
applyUpdate(): void;
|
|
17
|
+
createCallback(name: string, fn: (...params: any) => any): void;
|
|
18
|
+
appendChild(child: VNode): void;
|
|
19
|
+
removeChild(child: VNode): void;
|
|
20
|
+
insertBefore(child: VNode, beforeChild: VNode): void;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const VNode_1 = __importDefault(require("./VNode"));
|
|
7
|
+
const instanceId_1 = require("./instanceId");
|
|
8
|
+
class AppContainer {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.updateQueue = [];
|
|
11
|
+
this.root = new VNode_1.default({
|
|
12
|
+
id: (0, instanceId_1.generate)(),
|
|
13
|
+
type: 'root',
|
|
14
|
+
container: this,
|
|
15
|
+
});
|
|
16
|
+
this.root.mounted = true;
|
|
17
|
+
}
|
|
18
|
+
requestUpdate(path, start, deleteCount, ...items) {
|
|
19
|
+
// ignore
|
|
20
|
+
}
|
|
21
|
+
applyUpdate() {
|
|
22
|
+
this.context._pages.forEach((page) => {
|
|
23
|
+
page.container.applyUpdate();
|
|
24
|
+
page.modalContainer.applyUpdate();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
createCallback(name, fn) {
|
|
28
|
+
this.context[name] = fn;
|
|
29
|
+
}
|
|
30
|
+
appendChild(child) {
|
|
31
|
+
this.root.appendChild(child);
|
|
32
|
+
}
|
|
33
|
+
removeChild(child) {
|
|
34
|
+
this.root.removeChild(child);
|
|
35
|
+
}
|
|
36
|
+
insertBefore(child, beforeChild) {
|
|
37
|
+
this.root.insertBefore(child, beforeChild);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = AppContainer;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import VNode, { RawNode } from './VNode';
|
|
2
|
+
import { FiberRoot } from 'react-reconciler';
|
|
3
|
+
interface SpliceUpdate {
|
|
4
|
+
path: string[];
|
|
5
|
+
start: number;
|
|
6
|
+
id: number;
|
|
7
|
+
deleteCount: number;
|
|
8
|
+
items: RawNode[];
|
|
9
|
+
children?: RawNode[];
|
|
10
|
+
type: 'splice';
|
|
11
|
+
node: VNode;
|
|
12
|
+
}
|
|
13
|
+
interface SetUpdate {
|
|
14
|
+
path: string[];
|
|
15
|
+
name: string;
|
|
16
|
+
value: any;
|
|
17
|
+
type: 'set';
|
|
18
|
+
node: VNode;
|
|
19
|
+
}
|
|
20
|
+
export default class Container {
|
|
21
|
+
context: any;
|
|
22
|
+
root: VNode;
|
|
23
|
+
rootKey: string;
|
|
24
|
+
updateQueue: Array<SpliceUpdate | SetUpdate>;
|
|
25
|
+
_rootContainer?: FiberRoot;
|
|
26
|
+
stopUpdate?: boolean;
|
|
27
|
+
rendered: boolean;
|
|
28
|
+
constructor(context: any, rootKey?: string);
|
|
29
|
+
requestUpdate(update: SpliceUpdate | SetUpdate): void;
|
|
30
|
+
normalizeUpdatePath(paths: string[]): string;
|
|
31
|
+
applyUpdate(): void;
|
|
32
|
+
clearUpdate(): void;
|
|
33
|
+
createCallback(name: string, fn: (...params: any) => any): void;
|
|
34
|
+
removeCallback(name: string): void;
|
|
35
|
+
appendChild(child: VNode): void;
|
|
36
|
+
removeChild(child: VNode): void;
|
|
37
|
+
insertBefore(child: VNode, beforeChild: VNode): void;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
package/cjs/Container.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const VNode_1 = __importDefault(require("./VNode"));
|
|
7
|
+
const instanceId_1 = require("./instanceId");
|
|
8
|
+
const nativeEffect_1 = __importDefault(require("./nativeEffect"));
|
|
9
|
+
const framework_shared_1 = require("@rsmax/framework-shared");
|
|
10
|
+
const index_1 = require("./index");
|
|
11
|
+
class Container {
|
|
12
|
+
constructor(context, rootKey = 'root') {
|
|
13
|
+
this.updateQueue = [];
|
|
14
|
+
this.rendered = false;
|
|
15
|
+
this.context = context;
|
|
16
|
+
this.root = new VNode_1.default({
|
|
17
|
+
id: (0, instanceId_1.generate)(),
|
|
18
|
+
type: 'root',
|
|
19
|
+
container: this,
|
|
20
|
+
});
|
|
21
|
+
this.root.mounted = true;
|
|
22
|
+
this.rootKey = rootKey;
|
|
23
|
+
}
|
|
24
|
+
requestUpdate(update) {
|
|
25
|
+
this.updateQueue.push(update);
|
|
26
|
+
}
|
|
27
|
+
normalizeUpdatePath(paths) {
|
|
28
|
+
return [this.rootKey, ...paths].join('.');
|
|
29
|
+
}
|
|
30
|
+
applyUpdate() {
|
|
31
|
+
if (this.stopUpdate || this.updateQueue.length === 0) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const startTime = new Date().getTime();
|
|
35
|
+
if (typeof this.context.$spliceData === 'function') {
|
|
36
|
+
let $batchedUpdates = (callback) => {
|
|
37
|
+
callback();
|
|
38
|
+
};
|
|
39
|
+
if (typeof this.context.$batchedUpdates === 'function') {
|
|
40
|
+
$batchedUpdates = this.context.$batchedUpdates;
|
|
41
|
+
}
|
|
42
|
+
$batchedUpdates(() => {
|
|
43
|
+
this.updateQueue.map((update, index) => {
|
|
44
|
+
let callback = undefined;
|
|
45
|
+
if (index + 1 === this.updateQueue.length) {
|
|
46
|
+
callback = () => {
|
|
47
|
+
nativeEffect_1.default.run();
|
|
48
|
+
/* istanbul ignore next */
|
|
49
|
+
if (framework_shared_1.RuntimeOptions.get('debug')) {
|
|
50
|
+
console.log(`setData => 回调时间:${new Date().getTime() - startTime}ms`);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (update.type === 'splice') {
|
|
55
|
+
this.context.$spliceData({
|
|
56
|
+
[this.normalizeUpdatePath([...update.path, 'children'])]: [
|
|
57
|
+
update.start,
|
|
58
|
+
update.deleteCount,
|
|
59
|
+
...update.items,
|
|
60
|
+
],
|
|
61
|
+
}, callback);
|
|
62
|
+
}
|
|
63
|
+
if (update.type === 'set') {
|
|
64
|
+
this.context.setData({
|
|
65
|
+
[this.normalizeUpdatePath([...update.path, update.name])]: update.value,
|
|
66
|
+
}, callback);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
this.updateQueue = [];
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const updatePayload = this.updateQueue.reduce((acc, update) => {
|
|
74
|
+
if (update.node.isDeleted()) {
|
|
75
|
+
return acc;
|
|
76
|
+
}
|
|
77
|
+
if (update.type === 'splice') {
|
|
78
|
+
acc[this.normalizeUpdatePath([...update.path, 'nodes', update.id.toString()])] = update.items[0] || null;
|
|
79
|
+
if (update.children) {
|
|
80
|
+
acc[this.normalizeUpdatePath([...update.path, 'children'])] = (update.children || []).map(c => c.id);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
acc[this.normalizeUpdatePath([...update.path, update.name])] = update.value;
|
|
85
|
+
}
|
|
86
|
+
return acc;
|
|
87
|
+
}, {});
|
|
88
|
+
this.context.setData(updatePayload, () => {
|
|
89
|
+
nativeEffect_1.default.run();
|
|
90
|
+
/* istanbul ignore next */
|
|
91
|
+
if (framework_shared_1.RuntimeOptions.get('debug')) {
|
|
92
|
+
console.log(`setData => 回调时间:${new Date().getTime() - startTime}ms`, updatePayload);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
this.updateQueue = [];
|
|
96
|
+
}
|
|
97
|
+
clearUpdate() {
|
|
98
|
+
this.stopUpdate = true;
|
|
99
|
+
}
|
|
100
|
+
createCallback(name, fn) {
|
|
101
|
+
this.context[name] = (...args) => {
|
|
102
|
+
return (0, index_1.unstable_batchedUpdates)(args => {
|
|
103
|
+
return fn(...args);
|
|
104
|
+
}, args);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
removeCallback(name) {
|
|
108
|
+
delete this.context[name];
|
|
109
|
+
}
|
|
110
|
+
appendChild(child) {
|
|
111
|
+
this.root.appendChild(child);
|
|
112
|
+
}
|
|
113
|
+
removeChild(child) {
|
|
114
|
+
this.root.removeChild(child);
|
|
115
|
+
}
|
|
116
|
+
insertBefore(child, beforeChild) {
|
|
117
|
+
this.root.insertBefore(child, beforeChild);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.default = Container;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPortal = void 0;
|
|
4
|
+
const react_is_1 = require("react-is");
|
|
5
|
+
function createPortal(children, containerInfo, key) {
|
|
6
|
+
return {
|
|
7
|
+
// This tag allow us to uniquely identify this as a React Portal
|
|
8
|
+
$$typeof: react_is_1.Portal,
|
|
9
|
+
key: key || '',
|
|
10
|
+
children,
|
|
11
|
+
containerInfo,
|
|
12
|
+
implementation: null,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.createPortal = createPortal;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SYNTHETIC_TYPES = exports.DEPRECATED_CATCH_TYPE = void 0;
|
|
4
|
+
exports.DEPRECATED_CATCH_TYPE = 'catchClick';
|
|
5
|
+
exports.SYNTHETIC_TYPES = [
|
|
6
|
+
'onClick',
|
|
7
|
+
'onTap',
|
|
8
|
+
'onLongClick',
|
|
9
|
+
'onLongTap',
|
|
10
|
+
'onTouchMove',
|
|
11
|
+
'onTouchStart',
|
|
12
|
+
'onTouchEnd',
|
|
13
|
+
];
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createCallbackProxy = void 0;
|
|
27
|
+
const framework_shared_1 = require("@rsmax/framework-shared");
|
|
28
|
+
const stopPropagation_1 = __importStar(require("./stopPropagation"));
|
|
29
|
+
const constants_1 = require("./constants");
|
|
30
|
+
function isSyntheticType(inputType) {
|
|
31
|
+
if (constants_1.DEPRECATED_CATCH_TYPE === inputType) {
|
|
32
|
+
console.warn('DEPRECATION: remax 已支持在 onClick 事件中使用 stopPropagation 阻止事件冒泡,请尽量不要使用 catchClick');
|
|
33
|
+
}
|
|
34
|
+
return !!(0, framework_shared_1.find)(constants_1.SYNTHETIC_TYPES, type => type === inputType);
|
|
35
|
+
}
|
|
36
|
+
function createBaseSyntheticEvent(node, eventType, nativeEvent) {
|
|
37
|
+
if (!nativeEvent) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// 添加阻止冒泡方法
|
|
41
|
+
nativeEvent.stopPropagation = () => {
|
|
42
|
+
(0, stopPropagation_1.default)(node, eventType);
|
|
43
|
+
};
|
|
44
|
+
return nativeEvent;
|
|
45
|
+
}
|
|
46
|
+
function createCallbackProxy(eventType, node, callback) {
|
|
47
|
+
if (!isSyntheticType(eventType)) {
|
|
48
|
+
return callback;
|
|
49
|
+
}
|
|
50
|
+
return function (nativeEvent, ...restParams) {
|
|
51
|
+
const syntheticEvent = createBaseSyntheticEvent(node, eventType, nativeEvent);
|
|
52
|
+
if (stopPropagation_1.isPropagationStopped[eventType]) {
|
|
53
|
+
(0, stopPropagation_1.validate)(node, eventType);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
return callback(syntheticEvent, ...restParams);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
exports.createCallbackProxy = createCallbackProxy;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import VNode from '../VNode';
|
|
2
|
+
export declare const isPropagationStopped: {
|
|
3
|
+
[key: string]: boolean;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* 检查父元素里还有没有点击事件
|
|
7
|
+
*
|
|
8
|
+
* @export
|
|
9
|
+
* @param {VNode} node
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function validate(node: VNode, eventType: string): void;
|
|
13
|
+
export default function stopPropagation(node: VNode, eventType: string): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validate = exports.isPropagationStopped = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
exports.isPropagationStopped = {};
|
|
6
|
+
constants_1.SYNTHETIC_TYPES.forEach(type => {
|
|
7
|
+
exports.isPropagationStopped[type] = false;
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* 检查父元素里还有没有点击事件
|
|
11
|
+
*
|
|
12
|
+
* @export
|
|
13
|
+
* @param {VNode} node
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
function validate(node, eventType) {
|
|
17
|
+
var _a;
|
|
18
|
+
const parent = node.parent;
|
|
19
|
+
if (!parent) {
|
|
20
|
+
exports.isPropagationStopped[eventType] = false;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if ((_a = parent.props) === null || _a === void 0 ? void 0 : _a[eventType]) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
validate(parent, eventType);
|
|
27
|
+
}
|
|
28
|
+
exports.validate = validate;
|
|
29
|
+
function stopPropagation(node, eventType) {
|
|
30
|
+
exports.isPropagationStopped[eventType] = true;
|
|
31
|
+
validate(node, eventType);
|
|
32
|
+
}
|
|
33
|
+
exports.default = stopPropagation;
|
package/cjs/VNode.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Container from './Container';
|
|
2
|
+
export interface RawNode {
|
|
3
|
+
id: number;
|
|
4
|
+
type: string;
|
|
5
|
+
props?: any;
|
|
6
|
+
nodes?: {
|
|
7
|
+
[key: number]: RawNode;
|
|
8
|
+
};
|
|
9
|
+
children?: Array<RawNode | number>;
|
|
10
|
+
text?: string;
|
|
11
|
+
}
|
|
12
|
+
export default class VNode {
|
|
13
|
+
id: number;
|
|
14
|
+
container: Container;
|
|
15
|
+
mounted: boolean;
|
|
16
|
+
deleted: boolean;
|
|
17
|
+
type: string;
|
|
18
|
+
props?: any;
|
|
19
|
+
parent: VNode | null;
|
|
20
|
+
firstChild: VNode | null;
|
|
21
|
+
lastChild: VNode | null;
|
|
22
|
+
size: number;
|
|
23
|
+
previousSibling: VNode | null;
|
|
24
|
+
nextSibling: VNode | null;
|
|
25
|
+
text?: string;
|
|
26
|
+
callbackIds: Set<string>;
|
|
27
|
+
constructor({ id, type, props, container }: {
|
|
28
|
+
id: number;
|
|
29
|
+
type: string;
|
|
30
|
+
props?: any;
|
|
31
|
+
container: any;
|
|
32
|
+
});
|
|
33
|
+
appendChild(node: VNode): void;
|
|
34
|
+
removeChild(node: VNode): void;
|
|
35
|
+
insertBefore(node: VNode, referenceNode: VNode): void;
|
|
36
|
+
update(payload?: any[]): void;
|
|
37
|
+
get index(): number;
|
|
38
|
+
get children(): VNode[];
|
|
39
|
+
get path(): string[];
|
|
40
|
+
isMounted(): boolean;
|
|
41
|
+
isDeleted(): boolean;
|
|
42
|
+
registerCallback(propKey: string, propValue: any): string;
|
|
43
|
+
unregisteredCallbacks(): void;
|
|
44
|
+
toJSON(): RawNode;
|
|
45
|
+
}
|