@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
package/esm/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
+ }
package/esm/VNode.js ADDED
@@ -0,0 +1,250 @@
1
+ import propsAlias, { propAlias } from './propsAlias';
2
+ import { REMAX_METHOD, TYPE_TEXT } from './constants';
3
+ import { RuntimeOptions } from '@rsmax/framework-shared';
4
+ import { createCallbackProxy } from './SyntheticEvent/createCallbackProxy';
5
+ function toRawNode(node) {
6
+ if (node.type === TYPE_TEXT) {
7
+ return {
8
+ id: node.id,
9
+ type: node.type,
10
+ text: node.text,
11
+ };
12
+ }
13
+ return {
14
+ id: node.id,
15
+ type: node.type,
16
+ props: propsAlias(node.props, node.type),
17
+ children: [],
18
+ text: node.text,
19
+ };
20
+ }
21
+ function toRawProps(prop, value, type) {
22
+ return propAlias(prop, value, type);
23
+ }
24
+ export default class VNode {
25
+ constructor({ id, type, props, container }) {
26
+ this.mounted = false;
27
+ this.deleted = false;
28
+ this.parent = null;
29
+ this.firstChild = null;
30
+ this.lastChild = null;
31
+ this.size = 0;
32
+ this.previousSibling = null;
33
+ this.nextSibling = null;
34
+ this.callbackIds = new Set();
35
+ this.id = id;
36
+ this.container = container;
37
+ this.type = type;
38
+ this.props = props;
39
+ }
40
+ appendChild(node) {
41
+ this.removeChild(node);
42
+ this.size += 1;
43
+ node.parent = this;
44
+ node.deleted = false; // 交换节点时删除的节点会被复用
45
+ if (!this.firstChild) {
46
+ this.firstChild = node;
47
+ }
48
+ if (this.lastChild) {
49
+ this.lastChild.nextSibling = node;
50
+ node.previousSibling = this.lastChild;
51
+ }
52
+ this.lastChild = node;
53
+ if (this.isMounted()) {
54
+ this.container.requestUpdate({
55
+ type: 'splice',
56
+ path: this.path,
57
+ start: node.index,
58
+ id: node.id,
59
+ deleteCount: 0,
60
+ children: this.children,
61
+ items: [node.toJSON()],
62
+ node: this,
63
+ });
64
+ }
65
+ }
66
+ removeChild(node) {
67
+ const { previousSibling, nextSibling } = node;
68
+ if (node.parent !== this) {
69
+ return;
70
+ }
71
+ const index = node.index;
72
+ this.size -= 1;
73
+ if (this.firstChild === node) {
74
+ this.firstChild = node.nextSibling;
75
+ }
76
+ if (this.lastChild === node) {
77
+ this.lastChild = node.previousSibling;
78
+ }
79
+ if (previousSibling) {
80
+ previousSibling.nextSibling = nextSibling;
81
+ }
82
+ if (nextSibling) {
83
+ nextSibling.previousSibling = previousSibling;
84
+ }
85
+ node.previousSibling = null;
86
+ node.nextSibling = null;
87
+ node.deleted = true;
88
+ node.unregisteredCallbacks();
89
+ if (this.isMounted()) {
90
+ this.container.requestUpdate({
91
+ type: 'splice',
92
+ path: this.path,
93
+ start: index,
94
+ id: node.id,
95
+ deleteCount: 1,
96
+ children: this.children,
97
+ items: [],
98
+ node: this,
99
+ });
100
+ }
101
+ }
102
+ insertBefore(node, referenceNode) {
103
+ this.removeChild(node);
104
+ this.size += 1;
105
+ node.parent = this;
106
+ node.deleted = false; // 交换节点时删除的节点会被复用
107
+ if (referenceNode === this.firstChild) {
108
+ this.firstChild = node;
109
+ }
110
+ if (referenceNode.previousSibling) {
111
+ referenceNode.previousSibling.nextSibling = node;
112
+ node.previousSibling = referenceNode.previousSibling;
113
+ }
114
+ referenceNode.previousSibling = node;
115
+ node.nextSibling = referenceNode;
116
+ if (this.isMounted()) {
117
+ this.container.requestUpdate({
118
+ type: 'splice',
119
+ path: this.path,
120
+ start: node.index,
121
+ id: node.id,
122
+ deleteCount: 0,
123
+ children: this.children,
124
+ items: [node.toJSON()],
125
+ node: this,
126
+ });
127
+ }
128
+ }
129
+ update(payload) {
130
+ if (this.type === 'text' || !payload) {
131
+ this.container.requestUpdate({
132
+ type: 'splice',
133
+ // root 不会更新,所以肯定有 parent
134
+ path: this.parent.path,
135
+ start: this.index,
136
+ id: this.id,
137
+ deleteCount: 1,
138
+ items: [this.toJSON()],
139
+ node: this,
140
+ });
141
+ return;
142
+ }
143
+ const parentPath = this.parent.path;
144
+ for (let i = 0; i < payload.length; i = i + 2) {
145
+ const [propName, propValue] = toRawProps(payload[i], payload[i + 1], this.type);
146
+ let path = [...parentPath, 'nodes', this.id.toString(), 'props'];
147
+ if (RuntimeOptions.get('platform') === 'ali') {
148
+ path = [...parentPath, `children[${this.index}].props`];
149
+ }
150
+ this.container.requestUpdate({
151
+ type: 'set',
152
+ path,
153
+ name: propName,
154
+ value: propValue,
155
+ node: this,
156
+ });
157
+ }
158
+ }
159
+ get index() {
160
+ let value = 0;
161
+ let previousSibling = this.previousSibling;
162
+ while (previousSibling) {
163
+ value += 1;
164
+ previousSibling = previousSibling.previousSibling;
165
+ }
166
+ return value;
167
+ }
168
+ get children() {
169
+ const arr = [];
170
+ let item = this.firstChild;
171
+ while (item) {
172
+ arr.push(item);
173
+ item = item.nextSibling;
174
+ }
175
+ return arr;
176
+ }
177
+ get path() {
178
+ const dataPath = [];
179
+ const parents = [];
180
+ let parent = this.parent;
181
+ while (parent) {
182
+ parents.unshift(parent);
183
+ parent = parent.parent;
184
+ }
185
+ for (let i = 0; i < parents.length; i++) {
186
+ const child = parents[i + 1] || this;
187
+ if (RuntimeOptions.get('platform') === 'ali') {
188
+ dataPath.push('children');
189
+ dataPath.push(child.index.toString());
190
+ }
191
+ else {
192
+ dataPath.push('nodes');
193
+ dataPath.push(child.id.toString());
194
+ }
195
+ }
196
+ return dataPath;
197
+ }
198
+ isMounted() {
199
+ return this.parent ? this.parent.isMounted() : this.mounted;
200
+ }
201
+ isDeleted() {
202
+ var _a, _b;
203
+ return this.deleted === true ? this.deleted : (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.isDeleted()) !== null && _b !== void 0 ? _b : false;
204
+ }
205
+ registerCallback(propKey, propValue) {
206
+ const id = `${REMAX_METHOD}_${this.id}_${propKey}`;
207
+ this.callbackIds.add(id);
208
+ this.container.createCallback(id, createCallbackProxy(propKey, this, propValue));
209
+ return id;
210
+ }
211
+ unregisteredCallbacks() {
212
+ this.callbackIds.forEach(id => {
213
+ this.container.removeCallback(id);
214
+ });
215
+ }
216
+ toJSON() {
217
+ const stack = [];
218
+ const rawNode = toRawNode(this);
219
+ stack.push({
220
+ currentNode: rawNode,
221
+ children: this.children,
222
+ });
223
+ while (stack.length > 0) {
224
+ // while 循环已经保证了不会有空值
225
+ const stackItem = stack.pop();
226
+ const { children = [], currentNode } = stackItem;
227
+ for (let i = children.length - 1; i >= 0; i--) {
228
+ const currentVNode = children[i];
229
+ const currentRawNode = toRawNode(currentVNode);
230
+ if (RuntimeOptions.get('platform') !== 'ali') {
231
+ currentNode.children.unshift(currentRawNode.id);
232
+ }
233
+ else {
234
+ currentNode.children.unshift(currentRawNode);
235
+ }
236
+ if (RuntimeOptions.get('platform') !== 'ali') {
237
+ if (!currentNode.nodes) {
238
+ currentNode.nodes = {};
239
+ }
240
+ currentNode.nodes[currentRawNode.id] = currentRawNode;
241
+ }
242
+ stack.push({
243
+ currentNode: currentRawNode,
244
+ children: currentVNode.children,
245
+ });
246
+ }
247
+ }
248
+ return rawNode;
249
+ }
250
+ }
@@ -0,0 +1,3 @@
1
+ export declare const REMAX_ROOT_BACKUP = "$$REMAX_ROOT_BACKUP";
2
+ export declare const REMAX_METHOD = "$$REMAX_METHOD";
3
+ export declare const TYPE_TEXT = "plain-text";
@@ -0,0 +1,3 @@
1
+ export const REMAX_ROOT_BACKUP = '$$REMAX_ROOT_BACKUP';
2
+ export const REMAX_METHOD = '$$REMAX_METHOD';
3
+ export const TYPE_TEXT = 'plain-text';
@@ -0,0 +1,2 @@
1
+ import './polyfills/Function';
2
+ export default function createAppConfig(this: any, App: any): any;
@@ -0,0 +1,95 @@
1
+ import './polyfills/Function';
2
+ import * as React from 'react';
3
+ import { ForwardRef } from 'react-is';
4
+ import render from './render';
5
+ import AppContainer from './AppContainer';
6
+ import { AppInstanceContext, AppLifecycle, callbackName, isClassComponent, RuntimeOptions, } from '@rsmax/framework-shared';
7
+ class DefaultAppComponent extends React.Component {
8
+ render() {
9
+ return React.createElement(React.Fragment, this.props);
10
+ }
11
+ }
12
+ export default function createAppConfig(App) {
13
+ const WrappedApp = RuntimeOptions.get('pluginDriver').onAppComponent(App);
14
+ const createConfig = (AppComponent = DefaultAppComponent) => {
15
+ const config = {
16
+ _container: new AppContainer(),
17
+ _pages: [],
18
+ _instance: React.createRef(),
19
+ onLaunch(options) {
20
+ this._container.context = this;
21
+ this._render();
22
+ return this.callLifecycle(AppLifecycle.launch, options);
23
+ },
24
+ callLifecycle(lifecycle, ...args) {
25
+ const callbacks = AppInstanceContext.lifecycleCallback[lifecycle] || [];
26
+ let result;
27
+ callbacks.forEach((callback) => {
28
+ result = callback(...args);
29
+ });
30
+ if (result) {
31
+ return result;
32
+ }
33
+ const callback = callbackName(lifecycle);
34
+ if (this._instance.current && this._instance.current[callback]) {
35
+ return this._instance.current[callback](...args);
36
+ }
37
+ },
38
+ _mount(pageInstance) {
39
+ /**
40
+ * 飞书开发者工具的问题,这里的 this 跟 getApp 拿到的不是同一个实例
41
+ */
42
+ if (!this._container.context) {
43
+ this._container.context = this;
44
+ }
45
+ this._pages.push(pageInstance);
46
+ this._render();
47
+ },
48
+ _unmount(pageInstance) {
49
+ this._pages.splice(this._pages.indexOf(pageInstance), 1);
50
+ this._render();
51
+ },
52
+ _render() {
53
+ const props = {};
54
+ if (isClassComponent(AppComponent) || AppComponent.$$typeof === ForwardRef) {
55
+ props.ref = this._instance;
56
+ }
57
+ return render(React.createElement(AppComponent, props, this._pages.map((p) => p.element)), this._container);
58
+ },
59
+ onShow(options) {
60
+ return this.callLifecycle(AppLifecycle.show, options);
61
+ },
62
+ onHide() {
63
+ return this.callLifecycle(AppLifecycle.hide);
64
+ },
65
+ onError(error) {
66
+ return this.callLifecycle(AppLifecycle.error, error);
67
+ },
68
+ // 微信
69
+ onPageNotFound(options) {
70
+ return this.callLifecycle(AppLifecycle.pageNotFound, options);
71
+ },
72
+ // 微信
73
+ onUnhandledRejection(options) {
74
+ return this.callLifecycle(AppLifecycle.unhandledRejection, options);
75
+ },
76
+ // 微信
77
+ onThemeChange(options) {
78
+ return this.callLifecycle(AppLifecycle.themeChange, options);
79
+ },
80
+ };
81
+ const lifecycleEvent = {
82
+ // 阿里
83
+ onShareAppMessage(options) {
84
+ return this.callLifecycle(AppLifecycle.shareAppMessage, options);
85
+ },
86
+ };
87
+ (RuntimeOptions.get('appEvents') || []).forEach(eventName => {
88
+ if (lifecycleEvent[eventName]) {
89
+ config[eventName] = lifecycleEvent[eventName];
90
+ }
91
+ });
92
+ return RuntimeOptions.get('pluginDriver').onAppConfig(config);
93
+ };
94
+ return createConfig(WrappedApp);
95
+ }
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export default function createComponentConfig(Component: React.ComponentType<any>): any;
@@ -0,0 +1,45 @@
1
+ import * as React from 'react';
2
+ import { RuntimeOptions, ComponentInstanceContext } from '@rsmax/framework-shared';
3
+ import Container from './Container';
4
+ import render from './render';
5
+ export default function createComponentConfig(Component) {
6
+ const config = {
7
+ data: {
8
+ action: {},
9
+ root: {
10
+ children: [],
11
+ },
12
+ },
13
+ didMount() {
14
+ if (!this.container) {
15
+ this.init();
16
+ }
17
+ },
18
+ didUpdate(prevProps, prevData) {
19
+ if (prevData !== this.data) {
20
+ return;
21
+ }
22
+ this.render();
23
+ },
24
+ didUnmount() {
25
+ this.container.clearUpdate();
26
+ render(null, this.container);
27
+ },
28
+ methods: {
29
+ init() {
30
+ this.component = RuntimeOptions.get('pluginDriver').onMiniComponent({
31
+ component: Component,
32
+ context: this,
33
+ });
34
+ this.container = new Container(this);
35
+ this.render();
36
+ },
37
+ render() {
38
+ this.element = render(React.createElement(ComponentInstanceContext.Provider, {
39
+ value: this,
40
+ }, React.createElement(this.component, this.props)), this.container);
41
+ },
42
+ },
43
+ };
44
+ return config;
45
+ }
@@ -0,0 +1,2 @@
1
+ import * as React from 'react';
2
+ export default function createComponentConfig(Component: React.ComponentType<any>): any;
@@ -0,0 +1,60 @@
1
+ import * as React from 'react';
2
+ import { RuntimeOptions, ComponentInstanceContext } from '@rsmax/framework-shared';
3
+ import Container from './Container';
4
+ import render from './render';
5
+ export default function createComponentConfig(Component) {
6
+ const config = {
7
+ options: {
8
+ styleIsolation: 'apply-shared',
9
+ },
10
+ data: {
11
+ action: {},
12
+ root: {
13
+ children: [],
14
+ },
15
+ },
16
+ attached: function () {
17
+ // 在组件实例进入页面节点树时执行
18
+ if (!this.container) {
19
+ this.init();
20
+ }
21
+ },
22
+ detached: function () {
23
+ // 在组件实例被从页面节点树移除时执行
24
+ this.container.clearUpdate();
25
+ render(null, this.container);
26
+ },
27
+ /*
28
+ TODO: 当前微信无对应语法支持监听props
29
+ 且必须显示设定 properties,才能在组件中使用 this.properties.name
30
+ 所以当前的实现不支持在微信端 props
31
+ eg:
32
+ properties: {
33
+ name: String
34
+ },
35
+
36
+ didUpdate(prevProps: any, prevData: any) {
37
+ if (prevData !== this.data) {
38
+ return;
39
+ }
40
+
41
+ this.render();
42
+ },*/
43
+ methods: {
44
+ init() {
45
+ this.component = RuntimeOptions.get('pluginDriver').onMiniComponent({
46
+ component: Component,
47
+ context: this,
48
+ });
49
+ this.container = new Container(this);
50
+ this.render();
51
+ },
52
+ render() {
53
+ this.element = render(React.createElement(ComponentInstanceContext.Provider, {
54
+ value: this,
55
+ }, React.createElement(this.component, this.properties)), this.container);
56
+ },
57
+ },
58
+ };
59
+ return config;
60
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export default function createHostComponent<P = any>(name: string, component?: React.ComponentType<P>): any;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { RuntimeOptions } from '@rsmax/framework-shared';
3
+ export default function createHostComponent(name, component) {
4
+ if (component) {
5
+ return component;
6
+ }
7
+ const Component = React.forwardRef((props, ref) => {
8
+ let element = React.createElement(name, Object.assign(Object.assign({}, props), { ref }));
9
+ element = RuntimeOptions.get('pluginDriver').onCreateHostComponentElement(element);
10
+ return element;
11
+ });
12
+ Component.displayName = name;
13
+ return RuntimeOptions.get('pluginDriver').onCreateHostComponent(Component);
14
+ }
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export default function createNativeComponent(name: string): React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ export default function createNativeComponent(name) {
3
+ const Component = React.forwardRef((props, ref) => {
4
+ const newProps = Object.assign({}, props);
5
+ newProps.__ref =
6
+ typeof ref === 'function'
7
+ ? ref
8
+ : (e) => {
9
+ if (ref) {
10
+ ref.current = e;
11
+ }
12
+ };
13
+ return React.createElement(name, newProps);
14
+ });
15
+ Component.displayName = name;
16
+ return Component;
17
+ }
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ export declare function resetPageId(): void;
3
+ export default function createPageConfig(Page: React.ComponentType<any>, name: string): any;