@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,183 @@
1
+ import React from 'react';
2
+ import { callbackName, createPageWrapper, Lifecycle, RuntimeOptions } from '@rsmax/framework-shared';
3
+ import stopPullDownRefresh from './stopPullDownRefresh';
4
+ import Container from './Container';
5
+ import { createPortal } from './ReactPortal';
6
+ import render from './render';
7
+ import { unstable_batchedUpdates } from './index';
8
+ let idCounter = 0;
9
+ function generatePageId() {
10
+ const id = idCounter;
11
+ const pageId = 'page_' + id;
12
+ idCounter += 1;
13
+ return pageId;
14
+ }
15
+ // for testing
16
+ export function resetPageId() {
17
+ idCounter = 0;
18
+ }
19
+ export default function createPageConfig(Page, name) {
20
+ var _a;
21
+ let app;
22
+ try {
23
+ app = getApp();
24
+ }
25
+ catch (e) {
26
+ app = null;
27
+ }
28
+ const config = {
29
+ data: {
30
+ root: {
31
+ children: [],
32
+ },
33
+ modalRoot: {
34
+ children: [],
35
+ },
36
+ },
37
+ wrapperRef: React.createRef(),
38
+ lifecycleCallback: {},
39
+ onLoad(query) {
40
+ const PageWrapper = createPageWrapper(Page, name);
41
+ this.pageId = generatePageId();
42
+ this.lifecycleCallback = {};
43
+ this.data = {
44
+ root: {
45
+ children: [],
46
+ },
47
+ modalRoot: {
48
+ children: [],
49
+ },
50
+ };
51
+ this.query = query;
52
+ this.container = new Container(this, 'root');
53
+ this.modalContainer = new Container(this, 'modalRoot');
54
+ const pageElement = React.createElement(PageWrapper, {
55
+ page: this,
56
+ query,
57
+ modalContainer: this.modalContainer,
58
+ ref: this.wrapperRef,
59
+ });
60
+ if (app && app._mount) {
61
+ this.element = createPortal(pageElement, this.container, this.pageId);
62
+ app._mount(this);
63
+ }
64
+ else {
65
+ this.element = render(pageElement, this.container);
66
+ }
67
+ return this.callLifecycle(Lifecycle.load, query);
68
+ },
69
+ onUnload() {
70
+ this.callLifecycle(Lifecycle.unload);
71
+ this.unloaded = true;
72
+ this.container.clearUpdate();
73
+ if (app) {
74
+ app._unmount(this);
75
+ }
76
+ },
77
+ onTabItemTap(e) {
78
+ return this.callLifecycle(Lifecycle.tabItemTap, e);
79
+ },
80
+ onResize(e) {
81
+ return this.callLifecycle(Lifecycle.resize, e);
82
+ },
83
+ /**
84
+ * Lifecycle start
85
+ */
86
+ registerLifecycle(lifecycle, callback) {
87
+ this.lifecycleCallback[lifecycle] = this.lifecycleCallback[lifecycle] || [];
88
+ this.lifecycleCallback[lifecycle].push(callback);
89
+ return () => {
90
+ this.lifecycleCallback[lifecycle].splice(this.lifecycleCallback[lifecycle].indexOf(callback), 1);
91
+ };
92
+ },
93
+ callLifecycle(lifecycle, ...args) {
94
+ const callbacks = this.lifecycleCallback[lifecycle] || [];
95
+ let result;
96
+ // 生命周期中可能改变 state 导致 callbacks 发生变化
97
+ [...callbacks].map((callback) => {
98
+ result = unstable_batchedUpdates(args => {
99
+ return callback(...args);
100
+ }, args);
101
+ });
102
+ if (result) {
103
+ return result;
104
+ }
105
+ const callback = callbackName(lifecycle);
106
+ if (this.wrapperRef.current && this.wrapperRef.current[callback]) {
107
+ return this.wrapperRef.current[callback](...args);
108
+ }
109
+ },
110
+ events: {
111
+ // 页面返回时触发
112
+ onBack(e) {
113
+ return this.callLifecycle(Lifecycle.back, e);
114
+ },
115
+ // 键盘高度变化时触发
116
+ onKeyboardHeight(e) {
117
+ return this.callLifecycle(Lifecycle.keyboardHeight, e);
118
+ },
119
+ onTabItemTap(e) {
120
+ return this.callLifecycle(Lifecycle.tabItemTap, e);
121
+ },
122
+ // 点击但切换tabItem前触发
123
+ beforeTabItemTap() {
124
+ return this.callLifecycle(Lifecycle.beforeTabItemTap);
125
+ },
126
+ onResize(e) {
127
+ return this.callLifecycle(Lifecycle.resize, e);
128
+ },
129
+ },
130
+ onShow() {
131
+ return this.callLifecycle(Lifecycle.show);
132
+ },
133
+ onHide() {
134
+ return this.callLifecycle(Lifecycle.hide);
135
+ },
136
+ onReady() {
137
+ return this.callLifecycle(Lifecycle.ready);
138
+ },
139
+ onPullDownRefresh(e) {
140
+ const result = this.callLifecycle(Lifecycle.pullDownRefresh, e);
141
+ if (result && typeof result.then === 'function') {
142
+ Promise.resolve(result).then(() => {
143
+ stopPullDownRefresh();
144
+ });
145
+ }
146
+ },
147
+ onReachBottom() {
148
+ return this.callLifecycle(Lifecycle.reachBottom);
149
+ },
150
+ onTitleClick() {
151
+ return this.callLifecycle(Lifecycle.titleClick);
152
+ },
153
+ onOptionMenuClick(e) {
154
+ return this.callLifecycle(Lifecycle.optionMenuClick, e);
155
+ },
156
+ onPopMenuClick(e) {
157
+ return this.callLifecycle(Lifecycle.popMenuClick, e);
158
+ },
159
+ onPullIntercept() {
160
+ return this.callLifecycle(Lifecycle.pullIntercept);
161
+ },
162
+ /**
163
+ * lifecycle end
164
+ */
165
+ };
166
+ const lifecycleEvents = {
167
+ onPageScroll(e) {
168
+ return this.callLifecycle(Lifecycle.pageScroll, e);
169
+ },
170
+ onShareAppMessage(options) {
171
+ return this.callLifecycle(Lifecycle.shareAppMessage, options) || {};
172
+ },
173
+ onShareTimeline(options) {
174
+ return this.callLifecycle(Lifecycle.shareTimeline, options) || {};
175
+ },
176
+ };
177
+ ((_a = RuntimeOptions.get('pageEvents')[name]) !== null && _a !== void 0 ? _a : []).forEach(eventName => {
178
+ if (lifecycleEvents[eventName]) {
179
+ config[eventName] = lifecycleEvents[eventName];
180
+ }
181
+ });
182
+ return RuntimeOptions.get('pluginDriver').onPageConfig({ config, page: name });
183
+ }
@@ -0,0 +1,3 @@
1
+ export { usePageEvent, useAppEvent, usePageInstance, useComponentInstance } from '@rsmax/framework-shared';
2
+ export { default as useNativeEffect } from './useNativeEffect';
3
+ export { default as useQuery } from './useQuery';
@@ -0,0 +1,3 @@
1
+ export { usePageEvent, useAppEvent, usePageInstance, useComponentInstance } from '@rsmax/framework-shared';
2
+ export { default as useNativeEffect } from './useNativeEffect';
3
+ export { default as useQuery } from './useQuery';
@@ -0,0 +1,3 @@
1
+ import { DependencyList } from 'react';
2
+ import { Listener } from '../nativeEffect';
3
+ export default function useNativeEffect(listener: Listener, deps?: DependencyList): void;
@@ -0,0 +1,7 @@
1
+ import { useLayoutEffect } from 'react';
2
+ import nativeEffect from '../nativeEffect';
3
+ export default function useNativeEffect(listener, deps) {
4
+ useLayoutEffect(() => {
5
+ return nativeEffect.connect(listener, !!deps);
6
+ }, deps);
7
+ }
@@ -0,0 +1,3 @@
1
+ export default function useQuery<Q extends Record<string, string | undefined> = {
2
+ [name: string]: string | undefined;
3
+ }>(): Q;
@@ -0,0 +1,6 @@
1
+ import { useContext } from 'react';
2
+ import { PageInstanceContext } from '@rsmax/framework-shared';
3
+ export default function useQuery() {
4
+ const pageInstance = useContext(PageInstanceContext);
5
+ return pageInstance.query;
6
+ }
@@ -0,0 +1 @@
1
+ export default function diffProperties(lastRawProps: Record<string, any> | null | undefined, nextRawProps: Record<string, any> | null | undefined): null | any[];
@@ -0,0 +1,97 @@
1
+ import { includes } from '@rsmax/framework-shared';
2
+ const STYLE = ['style', 'placeholderStyle'];
3
+ const CHILDREN = 'children';
4
+ const CLASS_NAME = 'className';
5
+ export default function diffProperties(lastRawProps, nextRawProps) {
6
+ const updatePayload = [];
7
+ const lastProps = lastRawProps;
8
+ const nextProps = nextRawProps;
9
+ let propKey;
10
+ let styleName;
11
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
12
+ const styleUpdates = {};
13
+ for (propKey in lastProps) {
14
+ if (hasOwnProperty.call(nextProps, propKey) ||
15
+ !hasOwnProperty.call(lastProps, propKey) ||
16
+ lastProps[propKey] == null) {
17
+ continue;
18
+ }
19
+ if (includes(STYLE, propKey)) {
20
+ const lastStyle = lastProps[propKey];
21
+ for (styleName in lastStyle) {
22
+ if (hasOwnProperty.call(lastStyle, styleName)) {
23
+ if (!styleUpdates[propKey]) {
24
+ styleUpdates[propKey] = {};
25
+ }
26
+ styleUpdates[propKey][styleName] = '';
27
+ }
28
+ }
29
+ }
30
+ else {
31
+ // For all other deleted properties we add it to the queue. We use
32
+ // the whitelist in the commit phase instead.
33
+ updatePayload.push(propKey, propKey === CLASS_NAME ? '' : null);
34
+ }
35
+ }
36
+ for (propKey in nextProps) {
37
+ const nextProp = nextProps[propKey];
38
+ const lastProp = lastProps != null ? lastProps[propKey] : undefined;
39
+ if (!hasOwnProperty.call(nextProps, propKey) || nextProp === lastProp || (nextProp == null && lastProp == null)) {
40
+ continue;
41
+ }
42
+ if (includes(STYLE, propKey)) {
43
+ if (process.env.NODE_ENV === 'development') {
44
+ if (nextProp) {
45
+ // Freeze the next style object so that we can assume it won't be
46
+ // mutated. We have already warned for this in the past.
47
+ Object.freeze(nextProp);
48
+ }
49
+ }
50
+ if (lastProp) {
51
+ // Unset styles on `lastProp` but not on `nextProp`.
52
+ for (styleName in lastProp) {
53
+ if (hasOwnProperty.call(lastProp, styleName) && (!nextProp || !hasOwnProperty.call(nextProp, styleName))) {
54
+ if (!styleUpdates[propKey]) {
55
+ styleUpdates[propKey] = {};
56
+ }
57
+ styleUpdates[propKey][styleName] = '';
58
+ }
59
+ }
60
+ // Update styles that changed since `lastProp`.
61
+ for (styleName in nextProp) {
62
+ if (hasOwnProperty.call(nextProp, styleName) && lastProp[styleName] !== nextProp[styleName]) {
63
+ if (!styleUpdates[propKey]) {
64
+ styleUpdates[propKey] = {};
65
+ }
66
+ styleUpdates[propKey][styleName] = nextProp[styleName];
67
+ }
68
+ }
69
+ }
70
+ else {
71
+ // Relies on `updateStylesByID` not mutating `styleUpdates`.
72
+ if (!styleUpdates[propKey]) {
73
+ updatePayload.push(propKey, null);
74
+ }
75
+ styleUpdates[propKey] = nextProp;
76
+ }
77
+ }
78
+ else if (propKey === CHILDREN) {
79
+ if (lastProp !== nextProp && (typeof nextProp === 'string' || typeof nextProp === 'number')) {
80
+ updatePayload.push(propKey, '' + nextProp);
81
+ }
82
+ }
83
+ else {
84
+ // For any other property we always add it to the queue and then we
85
+ // filter it out using the whitelist during the commit.
86
+ updatePayload.push(propKey, nextProp);
87
+ }
88
+ }
89
+ // 由于 style 要转换成 string, 所以必须整个 style 对象都更新
90
+ for (const styleKey in styleUpdates) {
91
+ const styleValue = styleUpdates[styleKey];
92
+ if (styleValue) {
93
+ updatePayload.push(styleKey, Object.assign({}, lastProps[styleKey], styleValue));
94
+ }
95
+ }
96
+ return updatePayload.length ? updatePayload : null;
97
+ }
@@ -0,0 +1,42 @@
1
+ import VNode from '../VNode';
2
+ import Container from '../Container';
3
+ declare const _default: {
4
+ now: any;
5
+ getPublicInstance: <T>(inst: T) => T;
6
+ getRootHostContext: () => {};
7
+ shouldSetTextContent(type: string): boolean;
8
+ prepareForCommit: () => null;
9
+ preparePortalMount: () => void;
10
+ clearContainer: () => void;
11
+ resetAfterCommit: (container: Container) => void;
12
+ getChildHostContext: () => {};
13
+ createInstance(type: string, newProps: any, container: Container): VNode;
14
+ createTextInstance(text: string, container: Container): VNode;
15
+ commitTextUpdate(node: VNode, oldText: string, newText: string): void;
16
+ prepareUpdate(node: VNode, type: string, lastProps: any, nextProps: any): any[] | null;
17
+ commitUpdate(node: VNode, updatePayload: any, type: string, oldProps: any, newProps: any): void;
18
+ appendInitialChild: (parent: VNode, child: VNode) => void;
19
+ appendChild(parent: VNode, child: VNode): void;
20
+ insertBefore(parent: VNode, child: VNode, beforeChild: VNode): void;
21
+ removeChild(parent: VNode, child: VNode): void;
22
+ finalizeInitialChildren: () => boolean;
23
+ appendChildToContainer(container: any, child: VNode): void;
24
+ insertInContainerBefore(container: any, child: VNode, beforeChild: VNode): void;
25
+ removeChildFromContainer(container: any, child: VNode): void;
26
+ hideInstance(instance: VNode): void;
27
+ hideTextInstance(instance: VNode): void;
28
+ unhideInstance(instance: VNode, props: any): void;
29
+ unhideTextInstance(instance: VNode, text: string): void;
30
+ /**
31
+ * 当 fiber 被标记为 Deletion 时,dom被卸载后,从dom节点上删除 react 初始化的内容,如 __reactProps$xxxx 等. 详见React源码
32
+ * https://github.com/facebook/react/blob/8b31835fc0a4de479a816471764f0e1d103ae205/packages/react-reconciler/src/forks/ReactFiberConfig.custom.js#L78
33
+ */
34
+ detachDeletedInstance(): {};
35
+ schedulePassiveEffects: any;
36
+ cancelPassiveEffects: any;
37
+ shouldYield: any;
38
+ scheduleDeferredCallback: any;
39
+ cancelDeferredCallback: any;
40
+ supportsMutation: boolean;
41
+ };
42
+ export default _default;
@@ -0,0 +1,154 @@
1
+ import scheduler from 'scheduler';
2
+ import { TYPE_TEXT } from '../constants';
3
+ import { generate } from '../instanceId';
4
+ import VNode from '../VNode';
5
+ import diffProperties from './diffProperties';
6
+ const { unstable_scheduleCallback: scheduleDeferredCallback, unstable_cancelCallback: cancelDeferredCallback, unstable_shouldYield: shouldYield, unstable_now: now, } = scheduler;
7
+ const DOM_TAG_MAP = {
8
+ span: 'text',
9
+ div: 'view',
10
+ img: 'image',
11
+ };
12
+ function processProps(newProps, node) {
13
+ const props = {};
14
+ node.unregisteredCallbacks();
15
+ for (const propKey of Object.keys(newProps)) {
16
+ if (typeof newProps[propKey] === 'function') {
17
+ props[propKey] = node.registerCallback(propKey, newProps[propKey]);
18
+ }
19
+ else if (propKey === 'style') {
20
+ props[propKey] = newProps[propKey] || '';
21
+ }
22
+ else if (propKey === 'children') {
23
+ // pass
24
+ }
25
+ else {
26
+ props[propKey] = newProps[propKey];
27
+ }
28
+ }
29
+ return props;
30
+ }
31
+ const rootHostContext = {};
32
+ const childHostContext = {};
33
+ export default {
34
+ now,
35
+ getPublicInstance: (inst) => {
36
+ return inst;
37
+ },
38
+ getRootHostContext: () => {
39
+ return rootHostContext;
40
+ },
41
+ shouldSetTextContent(type) {
42
+ return type === 'stub-block';
43
+ },
44
+ prepareForCommit: () => {
45
+ return null;
46
+ },
47
+ preparePortalMount: () => {
48
+ // nothing to do
49
+ },
50
+ clearContainer: () => {
51
+ // nothing to do
52
+ },
53
+ resetAfterCommit: (container) => {
54
+ container.applyUpdate();
55
+ },
56
+ getChildHostContext: () => {
57
+ return childHostContext;
58
+ },
59
+ createInstance(type, newProps, container) {
60
+ var _a;
61
+ const id = generate();
62
+ const node = new VNode({
63
+ id,
64
+ type: (_a = DOM_TAG_MAP[type]) !== null && _a !== void 0 ? _a : type,
65
+ props: {},
66
+ container,
67
+ });
68
+ node.props = processProps(newProps, node);
69
+ return node;
70
+ },
71
+ createTextInstance(text, container) {
72
+ const id = generate();
73
+ const node = new VNode({
74
+ id,
75
+ type: TYPE_TEXT,
76
+ props: null,
77
+ container,
78
+ });
79
+ node.text = text;
80
+ return node;
81
+ },
82
+ commitTextUpdate(node, oldText, newText) {
83
+ if (oldText !== newText) {
84
+ node.text = newText;
85
+ node.update();
86
+ }
87
+ },
88
+ prepareUpdate(node, type, lastProps, nextProps) {
89
+ lastProps = processProps(lastProps, node);
90
+ nextProps = processProps(nextProps, node);
91
+ return diffProperties(lastProps, nextProps);
92
+ },
93
+ commitUpdate(node, updatePayload, type, oldProps, newProps) {
94
+ node.props = processProps(newProps, node);
95
+ node.update(updatePayload);
96
+ },
97
+ appendInitialChild: (parent, child) => {
98
+ parent.appendChild(child);
99
+ },
100
+ appendChild(parent, child) {
101
+ parent.appendChild(child);
102
+ },
103
+ insertBefore(parent, child, beforeChild) {
104
+ parent.insertBefore(child, beforeChild);
105
+ },
106
+ removeChild(parent, child) {
107
+ parent.removeChild(child);
108
+ },
109
+ finalizeInitialChildren: () => {
110
+ return false;
111
+ },
112
+ appendChildToContainer(container, child) {
113
+ container.appendChild(child);
114
+ child.mounted = true;
115
+ },
116
+ insertInContainerBefore(container, child, beforeChild) {
117
+ container.insertBefore(child, beforeChild);
118
+ },
119
+ removeChildFromContainer(container, child) {
120
+ container.removeChild(child);
121
+ },
122
+ hideInstance(instance) {
123
+ var _a;
124
+ const originStyle = (_a = instance.props) === null || _a === void 0 ? void 0 : _a.style;
125
+ const newStyle = Object.assign({}, originStyle || {}, { display: 'none' }); // 微信和阿里的小程序都不支持在内联样式中加`important!`
126
+ instance.props = Object.assign({}, instance.props || {}, { style: newStyle });
127
+ instance.update();
128
+ },
129
+ hideTextInstance(instance) {
130
+ instance.text = '';
131
+ instance.update();
132
+ },
133
+ unhideInstance(instance, props) {
134
+ instance.props = props;
135
+ instance.update();
136
+ },
137
+ unhideTextInstance(instance, text) {
138
+ instance.text = text;
139
+ instance.update();
140
+ },
141
+ /**
142
+ * 当 fiber 被标记为 Deletion 时,dom被卸载后,从dom节点上删除 react 初始化的内容,如 __reactProps$xxxx 等. 详见React源码
143
+ * https://github.com/facebook/react/blob/8b31835fc0a4de479a816471764f0e1d103ae205/packages/react-reconciler/src/forks/ReactFiberConfig.custom.js#L78
144
+ */
145
+ detachDeletedInstance() {
146
+ return {};
147
+ },
148
+ schedulePassiveEffects: scheduleDeferredCallback,
149
+ cancelPassiveEffects: cancelDeferredCallback,
150
+ shouldYield,
151
+ scheduleDeferredCallback,
152
+ cancelDeferredCallback,
153
+ supportsMutation: true,
154
+ };
package/esm/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export { default as render } from './render';
2
+ export { default as createAppConfig } from './createAppConfig';
3
+ export { default as createPageConfig } from './createPageConfig';
4
+ export { default as createComponentConfig } from './createComponentConfig';
5
+ export { default as createNativeComponent } from './createNativeComponent';
6
+ export { default as createHostComponent } from './createHostComponent';
7
+ export { createPortal } from './ReactPortal';
8
+ export { RuntimeOptions, PluginDriver } from '@rsmax/framework-shared';
9
+ export * from './hooks';
10
+ export declare const unstable_batchedUpdates: <A, R>(fn: (a: A) => R, a: A) => R;
11
+ declare const _default: {
12
+ unstable_batchedUpdates: <A, R>(fn: (a: A) => R, a: A) => R;
13
+ };
14
+ export default _default;
package/esm/index.js ADDED
@@ -0,0 +1,14 @@
1
+ export { default as render } from './render';
2
+ export { default as createAppConfig } from './createAppConfig';
3
+ export { default as createPageConfig } from './createPageConfig';
4
+ export { default as createComponentConfig } from './createComponentConfig';
5
+ export { default as createNativeComponent } from './createNativeComponent';
6
+ export { default as createHostComponent } from './createHostComponent';
7
+ export { createPortal } from './ReactPortal';
8
+ export { RuntimeOptions, PluginDriver } from '@rsmax/framework-shared';
9
+ export * from './hooks';
10
+ import { ReactReconcilerInst } from './render';
11
+ export const unstable_batchedUpdates = ReactReconcilerInst.batchedUpdates;
12
+ export default {
13
+ unstable_batchedUpdates,
14
+ };
@@ -0,0 +1,2 @@
1
+ export declare function reset(): void;
2
+ export declare function generate(): number;
@@ -0,0 +1,9 @@
1
+ let instanceId = 0;
2
+ export function reset() {
3
+ instanceId = 0;
4
+ }
5
+ export function generate() {
6
+ const id = instanceId;
7
+ instanceId += 1;
8
+ return id;
9
+ }
@@ -0,0 +1,10 @@
1
+ export type Listener = () => void;
2
+ declare function dispose(listener: Listener): void;
3
+ declare function connect(listener: Listener, once: boolean): () => void;
4
+ declare function run(): void;
5
+ declare const _default: {
6
+ connect: typeof connect;
7
+ run: typeof run;
8
+ dispose: typeof dispose;
9
+ };
10
+ export default _default;
@@ -0,0 +1,23 @@
1
+ const effector = {
2
+ listenerConfigs: [],
3
+ };
4
+ function dispose(listener) {
5
+ effector.listenerConfigs = effector.listenerConfigs.filter(config => config.listener !== listener);
6
+ }
7
+ function connect(listener, once) {
8
+ effector.listenerConfigs.push({ listener, once });
9
+ return () => dispose(listener);
10
+ }
11
+ function run() {
12
+ effector.listenerConfigs.forEach(config => {
13
+ config.listener();
14
+ if (config.once) {
15
+ dispose(config.listener);
16
+ }
17
+ });
18
+ }
19
+ export default {
20
+ connect,
21
+ run,
22
+ dispose,
23
+ };
File without changes
@@ -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,42 @@
1
+ import plainStyle from './utils/plainStyle';
2
+ import { RuntimeOptions } from '@rsmax/framework-shared';
3
+ export function getAlias(prop, type) {
4
+ var _a, _b;
5
+ const hostComponent = RuntimeOptions.get('hostComponents')[type];
6
+ const prefix = `${RuntimeOptions.get('platform')}-`;
7
+ // 判断是否是平台独有属性
8
+ if (prop.startsWith(prefix)) {
9
+ return prop.replace(new RegExp(`^${prefix}`), '');
10
+ }
11
+ 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;
12
+ }
13
+ function getValue(prop, value) {
14
+ if (prop.toLowerCase().endsWith('style') && Object.prototype.toString.call(value) === '[object Object]') {
15
+ return plainStyle(value);
16
+ }
17
+ return value;
18
+ }
19
+ export function propAlias(prop, value, type) {
20
+ return [getAlias(prop, type), getValue(prop, value)];
21
+ }
22
+ export default function propsAlias(props, type) {
23
+ if (!props) {
24
+ return props;
25
+ }
26
+ const prefix = `${RuntimeOptions.get('platform')}-`;
27
+ const aliasProps = {};
28
+ for (const prop in props) {
29
+ // 平台前缀属性优先级提升
30
+ // @see https://github.com/remaxjs/remax/issues/1409
31
+ const hasPrefix = prop.startsWith(prefix);
32
+ const key = getAlias(prop, type);
33
+ const value = getValue(prop, props[prop]);
34
+ if (hasPrefix) {
35
+ aliasProps[key] = value;
36
+ }
37
+ else {
38
+ aliasProps[key] = aliasProps[key] || value;
39
+ }
40
+ }
41
+ return aliasProps;
42
+ }