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