@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.
Files changed (140) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/cjs/AppContainer.d.ts +22 -0
  3. package/cjs/AppContainer.js +40 -0
  4. package/cjs/Container.d.ts +39 -0
  5. package/cjs/Container.js +120 -0
  6. package/cjs/ReactPortal.d.ts +2 -0
  7. package/cjs/ReactPortal.js +15 -0
  8. package/cjs/SyntheticEvent/constants.d.ts +2 -0
  9. package/cjs/SyntheticEvent/constants.js +13 -0
  10. package/cjs/SyntheticEvent/createCallbackProxy.d.ts +2 -0
  11. package/cjs/SyntheticEvent/createCallbackProxy.js +59 -0
  12. package/cjs/SyntheticEvent/stopPropagation.d.ts +13 -0
  13. package/cjs/SyntheticEvent/stopPropagation.js +33 -0
  14. package/cjs/VNode.d.ts +45 -0
  15. package/cjs/VNode.js +276 -0
  16. package/cjs/constants.d.ts +3 -0
  17. package/cjs/constants.js +6 -0
  18. package/cjs/createAppConfig.d.ts +2 -0
  19. package/cjs/createAppConfig.js +124 -0
  20. package/cjs/createComponentConfig.d.ts +2 -0
  21. package/cjs/createComponentConfig.js +74 -0
  22. package/cjs/createComponentConfig.wechat.d.ts +2 -0
  23. package/cjs/createComponentConfig.wechat.js +89 -0
  24. package/cjs/createHostComponent.d.ts +2 -0
  25. package/cjs/createHostComponent.js +20 -0
  26. package/cjs/createNativeComponent.d.ts +2 -0
  27. package/cjs/createNativeComponent.js +23 -0
  28. package/cjs/createPageConfig.d.ts +3 -0
  29. package/cjs/createPageConfig.js +191 -0
  30. package/cjs/hooks/index.d.ts +3 -0
  31. package/cjs/hooks/index.js +15 -0
  32. package/cjs/hooks/useNativeEffect.d.ts +3 -0
  33. package/cjs/hooks/useNativeEffect.js +13 -0
  34. package/cjs/hooks/useQuery.d.ts +3 -0
  35. package/cjs/hooks/useQuery.js +9 -0
  36. package/cjs/hostConfig/diffProperties.d.ts +1 -0
  37. package/cjs/hostConfig/diffProperties.js +100 -0
  38. package/cjs/hostConfig/index.d.ts +42 -0
  39. package/cjs/hostConfig/index.js +159 -0
  40. package/cjs/index.d.ts +14 -0
  41. package/cjs/index.js +43 -0
  42. package/cjs/instanceId.d.ts +2 -0
  43. package/cjs/instanceId.js +14 -0
  44. package/cjs/nativeEffect.d.ts +10 -0
  45. package/cjs/nativeEffect.js +25 -0
  46. package/cjs/polyfills/Function.d.ts +0 -0
  47. package/cjs/polyfills/Function.js +29 -0
  48. package/cjs/propsAlias.d.ts +6 -0
  49. package/cjs/propsAlias.js +51 -0
  50. package/cjs/render.d.ts +6 -0
  51. package/cjs/render.js +35 -0
  52. package/cjs/stopPullDownRefresh/index.ali.d.ts +2 -0
  53. package/cjs/stopPullDownRefresh/index.ali.js +3 -0
  54. package/cjs/stopPullDownRefresh/index.d.ts +1 -0
  55. package/cjs/stopPullDownRefresh/index.js +6 -0
  56. package/cjs/stopPullDownRefresh/index.toutiao.d.ts +2 -0
  57. package/cjs/stopPullDownRefresh/index.toutiao.js +3 -0
  58. package/cjs/stopPullDownRefresh/index.wechat.d.ts +2 -0
  59. package/cjs/stopPullDownRefresh/index.wechat.js +3 -0
  60. package/cjs/utils/capitalize.d.ts +1 -0
  61. package/cjs/utils/capitalize.js +6 -0
  62. package/cjs/utils/isClassComponent.d.ts +2 -0
  63. package/cjs/utils/isClassComponent.js +6 -0
  64. package/cjs/utils/lowercase.d.ts +1 -0
  65. package/cjs/utils/lowercase.js +6 -0
  66. package/cjs/utils/plainStyle/CSSProperty.d.ts +6 -0
  67. package/cjs/utils/plainStyle/CSSProperty.js +71 -0
  68. package/cjs/utils/plainStyle/index.d.ts +2 -0
  69. package/cjs/utils/plainStyle/index.js +45 -0
  70. package/esm/AppContainer.d.ts +22 -0
  71. package/esm/AppContainer.js +34 -0
  72. package/esm/Container.d.ts +39 -0
  73. package/esm/Container.js +114 -0
  74. package/esm/ReactPortal.d.ts +2 -0
  75. package/esm/ReactPortal.js +11 -0
  76. package/esm/SyntheticEvent/constants.d.ts +2 -0
  77. package/esm/SyntheticEvent/constants.js +10 -0
  78. package/esm/SyntheticEvent/createCallbackProxy.d.ts +2 -0
  79. package/esm/SyntheticEvent/createCallbackProxy.js +32 -0
  80. package/esm/SyntheticEvent/stopPropagation.d.ts +13 -0
  81. package/esm/SyntheticEvent/stopPropagation.js +28 -0
  82. package/esm/VNode.d.ts +45 -0
  83. package/esm/VNode.js +250 -0
  84. package/esm/constants.d.ts +3 -0
  85. package/esm/constants.js +3 -0
  86. package/esm/createAppConfig.d.ts +2 -0
  87. package/esm/createAppConfig.js +95 -0
  88. package/esm/createComponentConfig.d.ts +2 -0
  89. package/esm/createComponentConfig.js +45 -0
  90. package/esm/createComponentConfig.wechat.d.ts +2 -0
  91. package/esm/createComponentConfig.wechat.js +60 -0
  92. package/esm/createHostComponent.d.ts +2 -0
  93. package/esm/createHostComponent.js +14 -0
  94. package/esm/createNativeComponent.d.ts +2 -0
  95. package/esm/createNativeComponent.js +17 -0
  96. package/esm/createPageConfig.d.ts +3 -0
  97. package/esm/createPageConfig.js +183 -0
  98. package/esm/hooks/index.d.ts +3 -0
  99. package/esm/hooks/index.js +3 -0
  100. package/esm/hooks/useNativeEffect.d.ts +3 -0
  101. package/esm/hooks/useNativeEffect.js +7 -0
  102. package/esm/hooks/useQuery.d.ts +3 -0
  103. package/esm/hooks/useQuery.js +6 -0
  104. package/esm/hostConfig/diffProperties.d.ts +1 -0
  105. package/esm/hostConfig/diffProperties.js +97 -0
  106. package/esm/hostConfig/index.d.ts +42 -0
  107. package/esm/hostConfig/index.js +154 -0
  108. package/esm/index.d.ts +14 -0
  109. package/esm/index.js +14 -0
  110. package/esm/instanceId.d.ts +2 -0
  111. package/esm/instanceId.js +9 -0
  112. package/esm/nativeEffect.d.ts +10 -0
  113. package/esm/nativeEffect.js +23 -0
  114. package/esm/polyfills/Function.d.ts +0 -0
  115. package/esm/polyfills/Function.js +29 -0
  116. package/esm/propsAlias.d.ts +6 -0
  117. package/esm/propsAlias.js +42 -0
  118. package/esm/render.d.ts +6 -0
  119. package/esm/render.js +28 -0
  120. package/esm/stopPullDownRefresh/index.ali.d.ts +2 -0
  121. package/esm/stopPullDownRefresh/index.ali.js +1 -0
  122. package/esm/stopPullDownRefresh/index.d.ts +1 -0
  123. package/esm/stopPullDownRefresh/index.js +3 -0
  124. package/esm/stopPullDownRefresh/index.toutiao.d.ts +2 -0
  125. package/esm/stopPullDownRefresh/index.toutiao.js +1 -0
  126. package/esm/stopPullDownRefresh/index.wechat.d.ts +2 -0
  127. package/esm/stopPullDownRefresh/index.wechat.js +1 -0
  128. package/esm/utils/capitalize.d.ts +1 -0
  129. package/esm/utils/capitalize.js +3 -0
  130. package/esm/utils/isClassComponent.d.ts +2 -0
  131. package/esm/utils/isClassComponent.js +3 -0
  132. package/esm/utils/lowercase.d.ts +1 -0
  133. package/esm/utils/lowercase.js +3 -0
  134. package/esm/utils/plainStyle/CSSProperty.d.ts +6 -0
  135. package/esm/utils/plainStyle/CSSProperty.js +68 -0
  136. package/esm/utils/plainStyle/index.d.ts +2 -0
  137. package/esm/utils/plainStyle/index.js +43 -0
  138. package/package.json +56 -0
  139. package/typings/index.d.ts +6 -0
  140. package/vitest.config.js +9 -0
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /* eslint-disable prefer-rest-params */
3
+ /* istanbul ignore next */
4
+ if (typeof Function.prototype.call === 'undefined') {
5
+ Function.prototype.call = function (context) {
6
+ context = context || window;
7
+ context.fn = this;
8
+ const args = [...arguments].slice(1);
9
+ const result = context.fn(...args);
10
+ delete context.fn;
11
+ return result;
12
+ };
13
+ }
14
+ /* istanbul ignore next */
15
+ if (typeof Function.prototype.apply === 'undefined') {
16
+ Function.prototype.apply = function (context) {
17
+ context = context || window;
18
+ context.fn = this;
19
+ let result;
20
+ if (arguments[1]) {
21
+ result = context.fn(...arguments[1]);
22
+ }
23
+ else {
24
+ result = context.fn();
25
+ }
26
+ delete context.fn;
27
+ return result;
28
+ };
29
+ }
@@ -0,0 +1,6 @@
1
+ export declare function getAlias(prop: string, type: string): string;
2
+ export interface GenericProps {
3
+ [key: string]: any;
4
+ }
5
+ export declare function propAlias(prop: string, value: any, type: string): any[];
6
+ export default function propsAlias(props: GenericProps, type: string): GenericProps;
@@ -0,0 +1,51 @@
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
+ exports.propAlias = exports.getAlias = void 0;
7
+ const plainStyle_1 = __importDefault(require("./utils/plainStyle"));
8
+ const framework_shared_1 = require("@rsmax/framework-shared");
9
+ function getAlias(prop, type) {
10
+ var _a, _b;
11
+ const hostComponent = framework_shared_1.RuntimeOptions.get('hostComponents')[type];
12
+ const prefix = `${framework_shared_1.RuntimeOptions.get('platform')}-`;
13
+ // 判断是否是平台独有属性
14
+ if (prop.startsWith(prefix)) {
15
+ return prop.replace(new RegExp(`^${prefix}`), '');
16
+ }
17
+ return (_b = (_a = hostComponent === null || hostComponent === void 0 ? void 0 : hostComponent.alias) === null || _a === void 0 ? void 0 : _a[prop]) !== null && _b !== void 0 ? _b : prop;
18
+ }
19
+ exports.getAlias = getAlias;
20
+ function getValue(prop, value) {
21
+ if (prop.toLowerCase().endsWith('style') && Object.prototype.toString.call(value) === '[object Object]') {
22
+ return (0, plainStyle_1.default)(value);
23
+ }
24
+ return value;
25
+ }
26
+ function propAlias(prop, value, type) {
27
+ return [getAlias(prop, type), getValue(prop, value)];
28
+ }
29
+ exports.propAlias = propAlias;
30
+ function propsAlias(props, type) {
31
+ if (!props) {
32
+ return props;
33
+ }
34
+ const prefix = `${framework_shared_1.RuntimeOptions.get('platform')}-`;
35
+ const aliasProps = {};
36
+ for (const prop in props) {
37
+ // 平台前缀属性优先级提升
38
+ // @see https://github.com/remaxjs/remax/issues/1409
39
+ const hasPrefix = prop.startsWith(prefix);
40
+ const key = getAlias(prop, type);
41
+ const value = getValue(prop, props[prop]);
42
+ if (hasPrefix) {
43
+ aliasProps[key] = value;
44
+ }
45
+ else {
46
+ aliasProps[key] = aliasProps[key] || value;
47
+ }
48
+ }
49
+ return aliasProps;
50
+ }
51
+ exports.default = propsAlias;
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ import ReactReconciler from 'react-reconciler';
3
+ import Container from './Container';
4
+ import AppContainer from './AppContainer';
5
+ export declare const ReactReconcilerInst: ReactReconciler.Reconciler<unknown, unknown, unknown, unknown, unknown>;
6
+ export default function render(rootElement: React.ReactElement | null, container: Container | AppContainer): any;
package/cjs/render.js ADDED
@@ -0,0 +1,35 @@
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
+ exports.ReactReconcilerInst = void 0;
7
+ const react_reconciler_1 = __importDefault(require("react-reconciler"));
8
+ const hostConfig_1 = __importDefault(require("./hostConfig"));
9
+ exports.ReactReconcilerInst = (0, react_reconciler_1.default)(hostConfig_1.default);
10
+ if (process.env.NODE_ENV === 'development') {
11
+ exports.ReactReconcilerInst.injectIntoDevTools({
12
+ bundleType: 1,
13
+ version: '18.3.0',
14
+ rendererPackageName: 'remax',
15
+ });
16
+ }
17
+ function getPublicRootInstance(container) {
18
+ const containerFiber = container.current;
19
+ if (!containerFiber.child) {
20
+ return null;
21
+ }
22
+ return containerFiber.child.stateNode;
23
+ }
24
+ function render(rootElement, container) {
25
+ // Create a root Container if it doesnt exist
26
+ if (!container._rootContainer) {
27
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
28
+ container._rootContainer = exports.ReactReconcilerInst.createContainer(container, 0, null, false, null, '', () => { }, null);
29
+ }
30
+ exports.ReactReconcilerInst.updateContainer(rootElement, container._rootContainer, null, () => {
31
+ // ignore
32
+ });
33
+ return getPublicRootInstance(container._rootContainer);
34
+ }
35
+ exports.default = render;
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = my.stopPullDownRefresh;
@@ -0,0 +1 @@
1
+ export default function stopPullDownRefresh(): void;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function stopPullDownRefresh() {
4
+ // do nothing
5
+ }
6
+ exports.default = stopPullDownRefresh;
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = tt.stopPullDownRefresh;
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = wx.stopPullDownRefresh;
@@ -0,0 +1 @@
1
+ export default function capitalize(str: string): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function capitalize(str) {
4
+ return str.charAt(0).toUpperCase() + str.slice(1);
5
+ }
6
+ exports.default = capitalize;
@@ -0,0 +1,2 @@
1
+ import { ComponentClass } from 'react';
2
+ export default function isClassComponent(Component: any): Component is ComponentClass;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function isClassComponent(Component) {
4
+ return Component.prototype && typeof Component.prototype.render === 'function';
5
+ }
6
+ exports.default = isClassComponent;
@@ -0,0 +1 @@
1
+ export default function lowercase(str: string): string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function lowercase(str) {
4
+ return str.charAt(0).toLowerCase() + str.slice(1);
5
+ }
6
+ exports.default = lowercase;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * CSS properties which accept numbers but are not in units of "px".
3
+ */
4
+ export declare const isUnitlessNumber: {
5
+ [key: string]: boolean;
6
+ };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ // https://github.com/facebook/react/blob/master/packages/react-dom/src/shared/CSSProperty.js
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.isUnitlessNumber = void 0;
5
+ /**
6
+ * CSS properties which accept numbers but are not in units of "px".
7
+ */
8
+ exports.isUnitlessNumber = {
9
+ animationIterationCount: true,
10
+ borderImageOutset: true,
11
+ borderImageSlice: true,
12
+ borderImageWidth: true,
13
+ boxFlex: true,
14
+ boxFlexGroup: true,
15
+ boxOrdinalGroup: true,
16
+ columnCount: true,
17
+ columns: true,
18
+ flex: true,
19
+ flexGrow: true,
20
+ flexPositive: true,
21
+ flexShrink: true,
22
+ flexNegative: true,
23
+ flexOrder: true,
24
+ gridArea: true,
25
+ gridRow: true,
26
+ gridRowEnd: true,
27
+ gridRowSpan: true,
28
+ gridRowStart: true,
29
+ gridColumn: true,
30
+ gridColumnEnd: true,
31
+ gridColumnSpan: true,
32
+ gridColumnStart: true,
33
+ fontWeight: true,
34
+ lineClamp: true,
35
+ lineHeight: true,
36
+ opacity: true,
37
+ order: true,
38
+ orphans: true,
39
+ tabSize: true,
40
+ widows: true,
41
+ zIndex: true,
42
+ zoom: true,
43
+ // SVG-related properties
44
+ fillOpacity: true,
45
+ floodOpacity: true,
46
+ stopOpacity: true,
47
+ strokeDasharray: true,
48
+ strokeDashoffset: true,
49
+ strokeMiterlimit: true,
50
+ strokeOpacity: true,
51
+ strokeWidth: true,
52
+ };
53
+ /**
54
+ * @param {string} prefix vendor-specific prefix, eg: Webkit
55
+ * @param {string} key style name, eg: transitionDuration
56
+ * @return {string} style name prefixed with `prefix`, properly camelCased, eg:
57
+ * WebkitTransitionDuration
58
+ */
59
+ function prefixKey(prefix, key) {
60
+ return prefix + key.charAt(0).toUpperCase() + key.substring(1);
61
+ }
62
+ /**
63
+ * Support style names that may come passed in prefixed by adding permutations
64
+ * of vendor prefixes.
65
+ */
66
+ const prefixes = ['Webkit', 'ms', 'Moz', 'O'];
67
+ for (const prop in exports.isUnitlessNumber) {
68
+ prefixes.forEach(function (prefix) {
69
+ exports.isUnitlessNumber[prefixKey(prefix, prop)] = exports.isUnitlessNumber[prop];
70
+ });
71
+ }
@@ -0,0 +1,2 @@
1
+ declare const plainStyle: (style: Record<string, string | number>) => string;
2
+ export default plainStyle;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const CSSProperty_1 = require("./CSSProperty");
4
+ const framework_shared_1 = require("@rsmax/framework-shared");
5
+ const vendorPrefixes = ['webkit', 'moz', 'ms', 'o'];
6
+ const transformReactStyleKey = (key) => {
7
+ // css3 var
8
+ if (key === null || key === void 0 ? void 0 : key.startsWith('--')) {
9
+ return key;
10
+ }
11
+ let styleValue = key.replace(/\.?([A-Z]+)/g, function (_x, y) {
12
+ return '-' + y.toLowerCase();
13
+ });
14
+ // vendor prefix
15
+ if (styleValue === null || styleValue === void 0 ? void 0 : styleValue.startsWith('-')) {
16
+ const firstWord = styleValue.split('-').filter(s => s)[0];
17
+ styleValue = styleValue.replace(/^-/, '');
18
+ if ((0, framework_shared_1.find)(vendorPrefixes, prefix => prefix === firstWord)) {
19
+ styleValue = '-' + styleValue;
20
+ }
21
+ }
22
+ return styleValue;
23
+ };
24
+ const transformPx = (value) => {
25
+ if (typeof value !== 'string') {
26
+ return value;
27
+ }
28
+ return value.replace(/\b(\d+(\.\d+)?)px\b/g, function (match, x) {
29
+ const targetUnit = 'rpx';
30
+ const size = Number(x);
31
+ return size % 1 === 0 ? size + targetUnit : size.toFixed(2) + targetUnit;
32
+ });
33
+ };
34
+ const plainStyle = (style) => {
35
+ return Object.keys(style)
36
+ .reduce((acc, key) => {
37
+ let value = style[key];
38
+ if (!Number.isNaN(Number(value)) && !CSSProperty_1.isUnitlessNumber[key] && !(key === null || key === void 0 ? void 0 : key.startsWith('--'))) {
39
+ value = value + 'rpx';
40
+ }
41
+ return [...acc, `${transformReactStyleKey(key)}:${framework_shared_1.RuntimeOptions.get('pxToRpx') ? transformPx(value) : value};`];
42
+ }, [])
43
+ .join('');
44
+ };
45
+ exports.default = plainStyle;
@@ -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,34 @@
1
+ import VNode from './VNode';
2
+ import { generate } from './instanceId';
3
+ export default class AppContainer {
4
+ constructor() {
5
+ this.updateQueue = [];
6
+ this.root = new VNode({
7
+ id: generate(),
8
+ type: 'root',
9
+ container: this,
10
+ });
11
+ this.root.mounted = true;
12
+ }
13
+ requestUpdate(path, start, deleteCount, ...items) {
14
+ // ignore
15
+ }
16
+ applyUpdate() {
17
+ this.context._pages.forEach((page) => {
18
+ page.container.applyUpdate();
19
+ page.modalContainer.applyUpdate();
20
+ });
21
+ }
22
+ createCallback(name, fn) {
23
+ this.context[name] = fn;
24
+ }
25
+ appendChild(child) {
26
+ this.root.appendChild(child);
27
+ }
28
+ removeChild(child) {
29
+ this.root.removeChild(child);
30
+ }
31
+ insertBefore(child, beforeChild) {
32
+ this.root.insertBefore(child, beforeChild);
33
+ }
34
+ }
@@ -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 {};
@@ -0,0 +1,114 @@
1
+ import VNode from './VNode';
2
+ import { generate } from './instanceId';
3
+ import nativeEffector from './nativeEffect';
4
+ import { RuntimeOptions } from '@rsmax/framework-shared';
5
+ import { unstable_batchedUpdates } from './index';
6
+ export default class Container {
7
+ constructor(context, rootKey = 'root') {
8
+ this.updateQueue = [];
9
+ this.rendered = false;
10
+ this.context = context;
11
+ this.root = new VNode({
12
+ id: generate(),
13
+ type: 'root',
14
+ container: this,
15
+ });
16
+ this.root.mounted = true;
17
+ this.rootKey = rootKey;
18
+ }
19
+ requestUpdate(update) {
20
+ this.updateQueue.push(update);
21
+ }
22
+ normalizeUpdatePath(paths) {
23
+ return [this.rootKey, ...paths].join('.');
24
+ }
25
+ applyUpdate() {
26
+ if (this.stopUpdate || this.updateQueue.length === 0) {
27
+ return;
28
+ }
29
+ const startTime = new Date().getTime();
30
+ if (typeof this.context.$spliceData === 'function') {
31
+ let $batchedUpdates = (callback) => {
32
+ callback();
33
+ };
34
+ if (typeof this.context.$batchedUpdates === 'function') {
35
+ $batchedUpdates = this.context.$batchedUpdates;
36
+ }
37
+ $batchedUpdates(() => {
38
+ this.updateQueue.map((update, index) => {
39
+ let callback = undefined;
40
+ if (index + 1 === this.updateQueue.length) {
41
+ callback = () => {
42
+ nativeEffector.run();
43
+ /* istanbul ignore next */
44
+ if (RuntimeOptions.get('debug')) {
45
+ console.log(`setData => 回调时间:${new Date().getTime() - startTime}ms`);
46
+ }
47
+ };
48
+ }
49
+ if (update.type === 'splice') {
50
+ this.context.$spliceData({
51
+ [this.normalizeUpdatePath([...update.path, 'children'])]: [
52
+ update.start,
53
+ update.deleteCount,
54
+ ...update.items,
55
+ ],
56
+ }, callback);
57
+ }
58
+ if (update.type === 'set') {
59
+ this.context.setData({
60
+ [this.normalizeUpdatePath([...update.path, update.name])]: update.value,
61
+ }, callback);
62
+ }
63
+ });
64
+ });
65
+ this.updateQueue = [];
66
+ return;
67
+ }
68
+ const updatePayload = this.updateQueue.reduce((acc, update) => {
69
+ if (update.node.isDeleted()) {
70
+ return acc;
71
+ }
72
+ if (update.type === 'splice') {
73
+ acc[this.normalizeUpdatePath([...update.path, 'nodes', update.id.toString()])] = update.items[0] || null;
74
+ if (update.children) {
75
+ acc[this.normalizeUpdatePath([...update.path, 'children'])] = (update.children || []).map(c => c.id);
76
+ }
77
+ }
78
+ else {
79
+ acc[this.normalizeUpdatePath([...update.path, update.name])] = update.value;
80
+ }
81
+ return acc;
82
+ }, {});
83
+ this.context.setData(updatePayload, () => {
84
+ nativeEffector.run();
85
+ /* istanbul ignore next */
86
+ if (RuntimeOptions.get('debug')) {
87
+ console.log(`setData => 回调时间:${new Date().getTime() - startTime}ms`, updatePayload);
88
+ }
89
+ });
90
+ this.updateQueue = [];
91
+ }
92
+ clearUpdate() {
93
+ this.stopUpdate = true;
94
+ }
95
+ createCallback(name, fn) {
96
+ this.context[name] = (...args) => {
97
+ return unstable_batchedUpdates(args => {
98
+ return fn(...args);
99
+ }, args);
100
+ };
101
+ }
102
+ removeCallback(name) {
103
+ delete this.context[name];
104
+ }
105
+ appendChild(child) {
106
+ this.root.appendChild(child);
107
+ }
108
+ removeChild(child) {
109
+ this.root.removeChild(child);
110
+ }
111
+ insertBefore(child, beforeChild) {
112
+ this.root.insertBefore(child, beforeChild);
113
+ }
114
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare function createPortal(children: React.ReactNode, containerInfo: any, key?: string): any;
@@ -0,0 +1,11 @@
1
+ import { Portal } from 'react-is';
2
+ export function createPortal(children, containerInfo, key) {
3
+ return {
4
+ // This tag allow us to uniquely identify this as a React Portal
5
+ $$typeof: Portal,
6
+ key: key || '',
7
+ children,
8
+ containerInfo,
9
+ implementation: null,
10
+ };
11
+ }
@@ -0,0 +1,2 @@
1
+ export declare const DEPRECATED_CATCH_TYPE = "catchClick";
2
+ export declare const SYNTHETIC_TYPES: string[];
@@ -0,0 +1,10 @@
1
+ export const DEPRECATED_CATCH_TYPE = 'catchClick';
2
+ export const SYNTHETIC_TYPES = [
3
+ 'onClick',
4
+ 'onTap',
5
+ 'onLongClick',
6
+ 'onLongTap',
7
+ 'onTouchMove',
8
+ 'onTouchStart',
9
+ 'onTouchEnd',
10
+ ];
@@ -0,0 +1,2 @@
1
+ import VNode from '../VNode';
2
+ export declare function createCallbackProxy(eventType: string, node: VNode, callback: (...params: any) => any): (...params: any) => any;
@@ -0,0 +1,32 @@
1
+ import { find } from '@rsmax/framework-shared';
2
+ import stopPropagation, { validate as validatePropagation, isPropagationStopped } from './stopPropagation';
3
+ import { SYNTHETIC_TYPES, DEPRECATED_CATCH_TYPE } from './constants';
4
+ function isSyntheticType(inputType) {
5
+ if (DEPRECATED_CATCH_TYPE === inputType) {
6
+ console.warn('DEPRECATION: remax 已支持在 onClick 事件中使用 stopPropagation 阻止事件冒泡,请尽量不要使用 catchClick');
7
+ }
8
+ return !!find(SYNTHETIC_TYPES, type => type === inputType);
9
+ }
10
+ function createBaseSyntheticEvent(node, eventType, nativeEvent) {
11
+ if (!nativeEvent) {
12
+ return;
13
+ }
14
+ // 添加阻止冒泡方法
15
+ nativeEvent.stopPropagation = () => {
16
+ stopPropagation(node, eventType);
17
+ };
18
+ return nativeEvent;
19
+ }
20
+ export function createCallbackProxy(eventType, node, callback) {
21
+ if (!isSyntheticType(eventType)) {
22
+ return callback;
23
+ }
24
+ return function (nativeEvent, ...restParams) {
25
+ const syntheticEvent = createBaseSyntheticEvent(node, eventType, nativeEvent);
26
+ if (isPropagationStopped[eventType]) {
27
+ validatePropagation(node, eventType);
28
+ return;
29
+ }
30
+ return callback(syntheticEvent, ...restParams);
31
+ };
32
+ }
@@ -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,28 @@
1
+ import { SYNTHETIC_TYPES } from './constants';
2
+ export const isPropagationStopped = {};
3
+ SYNTHETIC_TYPES.forEach(type => {
4
+ isPropagationStopped[type] = false;
5
+ });
6
+ /**
7
+ * 检查父元素里还有没有点击事件
8
+ *
9
+ * @export
10
+ * @param {VNode} node
11
+ * @returns
12
+ */
13
+ export function validate(node, eventType) {
14
+ var _a;
15
+ const parent = node.parent;
16
+ if (!parent) {
17
+ isPropagationStopped[eventType] = false;
18
+ return;
19
+ }
20
+ if ((_a = parent.props) === null || _a === void 0 ? void 0 : _a[eventType]) {
21
+ return;
22
+ }
23
+ validate(parent, eventType);
24
+ }
25
+ export default function stopPropagation(node, eventType) {
26
+ isPropagationStopped[eventType] = true;
27
+ validate(node, eventType);
28
+ }