@reactunity/renderer 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/src/helpers/icons.d.ts +7 -0
- package/dist/src/helpers/icons.js +29 -0
- package/dist/src/models/base.d.ts +10 -7
- package/dist/src/models/editor/jsx.d.ts +10 -1
- package/dist/src/models/environment/index.d.ts +3 -0
- package/dist/src/models/generated/editor.d.ts +456 -26
- package/dist/src/models/generated/editor.js +1 -1
- package/dist/src/models/generated/react.d.ts +1897 -731
- package/dist/src/models/generated/react.js +1 -1
- package/dist/src/models/generated/system.d.ts +148 -148
- package/dist/src/models/generated/system.js +1 -1
- package/dist/src/models/generated/tests.js +1 -1
- package/dist/src/models/generated/unity.d.ts +5392 -1283
- package/dist/src/models/generated/unity.js +2 -2
- package/dist/src/models/generated/yoga.js +1 -1
- package/dist/src/models/properties/styles.d.ts +8 -7
- package/dist/src/models/properties/values.d.ts +7 -0
- package/dist/src/models/richtext.d.ts +65 -0
- package/dist/src/models/richtext.js +2 -0
- package/dist/src/models/svg.d.ts +68 -0
- package/dist/src/models/svg.js +1 -0
- package/dist/src/models/ugui/components.d.ts +12 -7
- package/dist/src/models/ugui/events.d.ts +1 -0
- package/dist/src/models/ugui/jsx.d.ts +10 -1
- package/dist/src/models/uitoolkit/components.d.ts +3 -1
- package/dist/src/models/uitoolkit/jsx.d.ts +9 -0
- package/dist/src/renderer/async/callbacks.js +22 -8
- package/dist/src/renderer/async/reconciler.d.ts +1 -8
- package/dist/src/renderer/async/reconciler.js +208 -60
- package/dist/src/renderer/async/serializer.d.ts +9 -0
- package/dist/src/renderer/async/serializer.js +31 -0
- package/dist/src/renderer/async/types.d.ts +31 -5
- package/dist/src/renderer/constants.d.ts +5 -0
- package/dist/src/renderer/constants.js +12 -0
- package/dist/src/renderer/diffing.js +1 -1
- package/dist/src/renderer/renderer.d.ts +11 -10
- package/dist/src/renderer/renderer.js +7 -9
- package/dist/src/renderer/subcontexts/index.d.ts +6 -0
- package/dist/src/renderer/subcontexts/index.js +6 -0
- package/dist/src/renderer/subcontexts/richtext.d.ts +3 -0
- package/dist/src/renderer/subcontexts/richtext.js +52 -0
- package/dist/src/renderer/subcontexts/svg.d.ts +3 -0
- package/dist/src/renderer/subcontexts/svg.js +70 -0
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +6 -6
|
@@ -12,39 +12,28 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
import * as Reconciler from 'react-reconciler';
|
|
13
13
|
import { commonReconciler, getAllowedProps, textTypes } from '../constants';
|
|
14
14
|
import { diffProperties } from '../diffing';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
15
|
+
import { subContextRenderers } from '../subcontexts';
|
|
16
|
+
import { callbacksRepo, convertPropsToSerializable, objectsRepo } from './serializer';
|
|
17
17
|
var refId = 0;
|
|
18
|
-
var callbacks = new CallbacksRepo();
|
|
19
|
-
var objects = new ObjectsRepo();
|
|
20
|
-
// Separates properties in 3 categories: regular props, callbacks and non-serializable objects
|
|
21
|
-
function partitionProps(props) {
|
|
22
|
-
var res = {};
|
|
23
|
-
for (var key in props) {
|
|
24
|
-
if (Object.prototype.hasOwnProperty.call(props, key)) {
|
|
25
|
-
var value = props[key];
|
|
26
|
-
if (value == null) {
|
|
27
|
-
(res.p || (res.p = {}))[key] = null;
|
|
28
|
-
}
|
|
29
|
-
else if (key === 'style') {
|
|
30
|
-
(res.p || (res.p = {}))[key] = partitionProps(value);
|
|
31
|
-
}
|
|
32
|
-
else if (typeof value === 'function') {
|
|
33
|
-
var ind = callbacks.addObject(value);
|
|
34
|
-
(res.e || (res.e = {}))[key] = ind;
|
|
35
|
-
}
|
|
36
|
-
else if (typeof value === 'object') {
|
|
37
|
-
var ind = objects.addObject(value);
|
|
38
|
-
(res.o || (res.o = {}))[key] = ind;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
(res.p || (res.p = {}))[key] = value;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return res;
|
|
46
|
-
}
|
|
47
18
|
var ctxMap = new Map();
|
|
19
|
+
var updateSubContext = function (instance) {
|
|
20
|
+
var rend = subContextRenderers[instance.type];
|
|
21
|
+
var root = instance === null || instance === void 0 ? void 0 : instance.root;
|
|
22
|
+
var cur = instance;
|
|
23
|
+
while (cur && !root) {
|
|
24
|
+
root = cur.root;
|
|
25
|
+
cur = cur.parent;
|
|
26
|
+
}
|
|
27
|
+
if (!root)
|
|
28
|
+
return;
|
|
29
|
+
var content = rend(root.subContext.node);
|
|
30
|
+
if (instance.type === 'richtext') {
|
|
31
|
+
instance.hostContext.commands.push(['x', { r: root.refId, c: content }]);
|
|
32
|
+
}
|
|
33
|
+
else if (instance.type === 'svg') {
|
|
34
|
+
instance.hostContext.commands.push(['u', __assign({ r: root.refId, t: 'svg' }, convertPropsToSerializable({ innerContent: content }))]);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
48
37
|
var hostConfig = __assign(__assign({}, commonReconciler), { getRootHostContext: function (rootContainer) {
|
|
49
38
|
var context = rootContainer.context;
|
|
50
39
|
if (rootContainer.refId < 0) {
|
|
@@ -62,42 +51,117 @@ var hostConfig = __assign(__assign({}, commonReconciler), { getRootHostContext:
|
|
|
62
51
|
return serialized;
|
|
63
52
|
};
|
|
64
53
|
var fireEventByRef = function (ind, args) {
|
|
65
|
-
return
|
|
54
|
+
return callbacksRepo.call(ind, args);
|
|
66
55
|
};
|
|
67
56
|
var getObjectRef = function (ind) {
|
|
68
|
-
return
|
|
57
|
+
return objectsRepo.getObject(ind);
|
|
69
58
|
};
|
|
70
59
|
var getEventAsObjectRef = function (ind) {
|
|
71
|
-
return
|
|
60
|
+
return callbacksRepo.getObject(ind);
|
|
72
61
|
};
|
|
73
62
|
context.BindCommands(flushCommands, fireEventByRef, getObjectRef, getEventAsObjectRef);
|
|
74
63
|
var ctx = {
|
|
75
64
|
context: context,
|
|
76
65
|
commands: commands,
|
|
66
|
+
refId: rootContainer.refId,
|
|
67
|
+
type: 'native',
|
|
77
68
|
};
|
|
78
69
|
ctxMap.set(context, ctx);
|
|
79
70
|
return ctx;
|
|
80
|
-
}, getChildHostContext: function (parentCtx) {
|
|
71
|
+
}, getChildHostContext: function (parentCtx, type) {
|
|
72
|
+
if (type === 'richtext' && parentCtx.type === 'native')
|
|
73
|
+
return {
|
|
74
|
+
type: 'richtext',
|
|
75
|
+
hostContext: parentCtx,
|
|
76
|
+
node: null,
|
|
77
|
+
parent: null,
|
|
78
|
+
root: null,
|
|
79
|
+
};
|
|
80
|
+
if (type === 'svg' && parentCtx.type === 'native')
|
|
81
|
+
return {
|
|
82
|
+
type: 'svg',
|
|
83
|
+
hostContext: parentCtx,
|
|
84
|
+
node: null,
|
|
85
|
+
parent: null,
|
|
86
|
+
root: null,
|
|
87
|
+
};
|
|
81
88
|
return parentCtx;
|
|
82
89
|
}, getPublicInstance: function (instance) {
|
|
83
|
-
|
|
90
|
+
if (instance.type === 'native')
|
|
91
|
+
return instance.context.GetRef(instance.refId, instance.commands.length > 0);
|
|
92
|
+
return null;
|
|
84
93
|
}, supportsMutation: true, supportsHydration: false, supportsPersistence: false, supportsMicrotasks: true, supportsTestSelectors: false, isPrimaryRenderer: true, warnsIfNotActing: true, prepareForCommit: function () { return null; }, resetAfterCommit: function () { }, shouldDeprioritizeSubtree: function () { return false; }, clearContainer: function (container) {
|
|
85
94
|
UnityBridge.clearContainer(container);
|
|
86
95
|
}, createInstance: function (type, props, rootContainer, ctx, internalHandle) {
|
|
87
|
-
refId++;
|
|
88
96
|
var aProps = getAllowedProps(props, type);
|
|
89
|
-
ctx.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
if (ctx.type === 'native') {
|
|
98
|
+
refId++;
|
|
99
|
+
ctx.commands.push(['c', __assign({ t: type, r: refId }, convertPropsToSerializable(aProps))]);
|
|
100
|
+
if (rootContainer.fiberCache)
|
|
101
|
+
rootContainer.fiberCache.setObject(refId, internalHandle);
|
|
102
|
+
var res = __assign(__assign({}, ctx), { refId: refId });
|
|
103
|
+
if (type === 'richtext') {
|
|
104
|
+
res.subContext = {
|
|
105
|
+
type: 'richtext',
|
|
106
|
+
node: {
|
|
107
|
+
tag: '',
|
|
108
|
+
children: [],
|
|
109
|
+
attributes: aProps,
|
|
110
|
+
},
|
|
111
|
+
root: res,
|
|
112
|
+
hostContext: res,
|
|
113
|
+
parent: null,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (type === 'svg') {
|
|
117
|
+
res.subContext = {
|
|
118
|
+
type: 'svg',
|
|
119
|
+
node: {
|
|
120
|
+
tag: '',
|
|
121
|
+
children: [],
|
|
122
|
+
attributes: aProps,
|
|
123
|
+
},
|
|
124
|
+
root: res,
|
|
125
|
+
hostContext: res,
|
|
126
|
+
parent: null,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return res;
|
|
130
|
+
}
|
|
131
|
+
else if (ctx.type === 'richtext' || ctx.type === 'svg') {
|
|
132
|
+
return __assign(__assign({}, ctx), { node: {
|
|
133
|
+
tag: type,
|
|
134
|
+
children: [],
|
|
135
|
+
attributes: aProps,
|
|
136
|
+
} });
|
|
137
|
+
}
|
|
93
138
|
}, createTextInstance: function (text, rootContainer, ctx, internalHandle) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
rootContainer.fiberCache
|
|
98
|
-
|
|
139
|
+
if (ctx.type === 'native') {
|
|
140
|
+
refId++;
|
|
141
|
+
ctx.commands.push(['t', { r: refId, c: text }]);
|
|
142
|
+
if (rootContainer.fiberCache)
|
|
143
|
+
rootContainer.fiberCache.setObject(refId, internalHandle);
|
|
144
|
+
return __assign(__assign({}, ctx), { refId: refId });
|
|
145
|
+
}
|
|
146
|
+
else if (ctx.type === 'richtext' || ctx.type === 'svg') {
|
|
147
|
+
return __assign(__assign({}, ctx), { node: { text: text } });
|
|
148
|
+
}
|
|
99
149
|
}, appendInitialChild: function (parent, child) {
|
|
100
|
-
|
|
150
|
+
if (!child)
|
|
151
|
+
return;
|
|
152
|
+
if (parent.type === 'native' && parent.subContext)
|
|
153
|
+
parent = parent.subContext;
|
|
154
|
+
if (parent.type === 'native' && child.type === 'native') {
|
|
155
|
+
parent.commands.push(['a', { p: parent.refId, c: child.refId }]);
|
|
156
|
+
}
|
|
157
|
+
else if ((parent.type === 'richtext' && child.type === 'richtext') ||
|
|
158
|
+
(parent.type === 'svg' && child.type === 'svg')) {
|
|
159
|
+
if ('children' in parent.node)
|
|
160
|
+
parent.node.children.push(child.node);
|
|
161
|
+
child.root = parent.root;
|
|
162
|
+
child.parent = parent;
|
|
163
|
+
updateSubContext(child);
|
|
164
|
+
}
|
|
101
165
|
}, finalizeInitialChildren: function () { return false; }, commitMount: function (instance) { }, shouldSetTextContent: function (type) { return textTypes[type]; },
|
|
102
166
|
// -------------------
|
|
103
167
|
// Mutation
|
|
@@ -106,30 +170,114 @@ var hostConfig = __assign(__assign({}, commonReconciler), { getRootHostContext:
|
|
|
106
170
|
return diffProperties(oldProps, newProps);
|
|
107
171
|
}, commitUpdate: function (instance, updatePayload, type) {
|
|
108
172
|
var props = getAllowedProps(updatePayload, type);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
173
|
+
if (instance.type === 'native') {
|
|
174
|
+
instance.commands.push(['u', __assign({ r: instance.refId, t: type }, convertPropsToSerializable(props))]);
|
|
175
|
+
}
|
|
176
|
+
else if (instance.type === 'richtext' || instance.type === 'svg') {
|
|
177
|
+
if ('attributes' in instance.node)
|
|
178
|
+
instance.node.attributes = __assign(__assign({}, instance.node.attributes), props);
|
|
179
|
+
updateSubContext(instance);
|
|
180
|
+
}
|
|
181
|
+
}, commitTextUpdate: function (instance, oldText, newText) {
|
|
182
|
+
if (instance.type === 'native') {
|
|
183
|
+
instance.commands.push(['x', { r: instance.refId, c: newText }]);
|
|
184
|
+
}
|
|
185
|
+
else if (instance.type === 'richtext' || instance.type === 'svg') {
|
|
186
|
+
instance.node = { text: newText };
|
|
187
|
+
updateSubContext(instance);
|
|
188
|
+
}
|
|
112
189
|
}, appendChild: function (parent, child) {
|
|
113
|
-
|
|
190
|
+
if (!child)
|
|
191
|
+
return;
|
|
192
|
+
if (parent.type === 'native' && parent.subContext)
|
|
193
|
+
parent = parent.subContext;
|
|
194
|
+
if (parent.type === 'native' && child.type === 'native') {
|
|
195
|
+
child.commands.push(['a', { p: parent.refId, c: child.refId }]);
|
|
196
|
+
}
|
|
197
|
+
else if ((parent.type === 'richtext' && child.type === 'richtext') ||
|
|
198
|
+
(parent.type === 'svg' && child.type === 'svg')) {
|
|
199
|
+
if ('children' in parent.node)
|
|
200
|
+
parent.node.children.push(child.node);
|
|
201
|
+
child.root = parent.root;
|
|
202
|
+
child.parent = parent;
|
|
203
|
+
updateSubContext(child);
|
|
204
|
+
}
|
|
114
205
|
}, appendChildToContainer: function (parent, child) {
|
|
115
|
-
child.
|
|
206
|
+
if (child.type === 'native')
|
|
207
|
+
child.commands.push(['a', { p: parent.refId, c: child.refId }]);
|
|
116
208
|
}, insertBefore: function (parent, child, beforeChild) {
|
|
117
|
-
|
|
209
|
+
if (!child)
|
|
210
|
+
return;
|
|
211
|
+
if (parent.type === 'native' && parent.subContext)
|
|
212
|
+
parent = parent.subContext;
|
|
213
|
+
if (parent.type === 'native' && child.type === 'native' && beforeChild.type === 'native') {
|
|
214
|
+
child.commands.push(['i', { p: parent.refId, c: child.refId, i: beforeChild.refId }]);
|
|
215
|
+
}
|
|
216
|
+
else if ((parent.type === 'richtext' && child.type === 'richtext' && beforeChild.type === 'richtext') ||
|
|
217
|
+
(parent.type === 'svg' && child.type === 'svg' && beforeChild.type === 'svg')) {
|
|
218
|
+
if ('children' in parent.node) {
|
|
219
|
+
var index = parent.node.children.indexOf(beforeChild.node);
|
|
220
|
+
if (index >= 0)
|
|
221
|
+
parent.node.children.splice(index, 0, child.node);
|
|
222
|
+
else
|
|
223
|
+
parent.node.children.push(child.node);
|
|
224
|
+
}
|
|
225
|
+
child.root = parent.root;
|
|
226
|
+
child.parent = parent;
|
|
227
|
+
updateSubContext(child);
|
|
228
|
+
}
|
|
118
229
|
}, insertInContainerBefore: function (parent, child, beforeChild) {
|
|
119
|
-
child.
|
|
230
|
+
if (child.type === 'native' && beforeChild.type === 'native')
|
|
231
|
+
child.commands.push(['i', { p: parent.refId, c: child.refId, i: beforeChild.refId }]);
|
|
120
232
|
}, removeChild: function (parent, child) {
|
|
121
|
-
|
|
233
|
+
if (!child)
|
|
234
|
+
return;
|
|
235
|
+
if (parent.type === 'native' && parent.subContext)
|
|
236
|
+
parent = parent.subContext;
|
|
237
|
+
if (parent.type === 'native' && child.type === 'native') {
|
|
238
|
+
child.commands.push(['r', { p: parent.refId, c: child.refId }]);
|
|
239
|
+
}
|
|
240
|
+
else if ((parent.type === 'richtext' && child.type === 'richtext') ||
|
|
241
|
+
(parent.type === 'svg' && child.type === 'svg')) {
|
|
242
|
+
if ('children' in parent.node) {
|
|
243
|
+
var index = parent.node.children.indexOf(child.node);
|
|
244
|
+
if (index >= 0)
|
|
245
|
+
parent.node.children.splice(index, 1);
|
|
246
|
+
}
|
|
247
|
+
updateSubContext(parent);
|
|
248
|
+
}
|
|
122
249
|
}, removeChildFromContainer: function (parent, child) {
|
|
123
|
-
child.
|
|
250
|
+
if (child.type === 'native')
|
|
251
|
+
child.commands.push(['r', { p: parent.refId, c: child.refId }]);
|
|
124
252
|
}, resetTextContent: function () { }, preparePortalMount: function () { }, detachDeletedInstance: function () { },
|
|
125
253
|
// Required for Suspense
|
|
126
254
|
hideInstance: function (instance) {
|
|
127
|
-
|
|
255
|
+
if (instance.type === 'native')
|
|
256
|
+
instance.commands.push(['h', { r: instance.refId, h: true }]);
|
|
257
|
+
else if (instance.type === 'richtext' || instance.type === 'svg') {
|
|
258
|
+
instance.node.hidden = true;
|
|
259
|
+
updateSubContext(instance);
|
|
260
|
+
}
|
|
128
261
|
}, hideTextInstance: function (instance) {
|
|
129
|
-
|
|
262
|
+
if (instance.type === 'native')
|
|
263
|
+
instance.commands.push(['h', { r: instance.refId, h: true }]);
|
|
264
|
+
else if (instance.type === 'richtext' || instance.type === 'svg') {
|
|
265
|
+
instance.node.hidden = true;
|
|
266
|
+
updateSubContext(instance);
|
|
267
|
+
}
|
|
130
268
|
}, unhideInstance: function (instance) {
|
|
131
|
-
|
|
269
|
+
if (instance.type === 'native')
|
|
270
|
+
instance.commands.push(['h', { r: instance.refId, h: false }]);
|
|
271
|
+
else if (instance.type === 'richtext' || instance.type === 'svg') {
|
|
272
|
+
instance.node.hidden = false;
|
|
273
|
+
updateSubContext(instance);
|
|
274
|
+
}
|
|
132
275
|
}, unhideTextInstance: function (instance) {
|
|
133
|
-
|
|
276
|
+
if (instance.type === 'native')
|
|
277
|
+
instance.commands.push(['h', { r: instance.refId, h: false }]);
|
|
278
|
+
else if (instance.type === 'richtext' || instance.type === 'svg') {
|
|
279
|
+
instance.node.hidden = false;
|
|
280
|
+
updateSubContext(instance);
|
|
281
|
+
}
|
|
134
282
|
} });
|
|
135
283
|
export var asyncReconciler = Reconciler(hostConfig);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CallbacksRepo } from './callbacks';
|
|
2
|
+
import { ObjectsRepo } from './objects';
|
|
3
|
+
export declare const callbacksRepo: CallbacksRepo;
|
|
4
|
+
export declare const objectsRepo: ObjectsRepo<any>;
|
|
5
|
+
export declare function convertPropsToSerializable(props: any): {
|
|
6
|
+
p: any;
|
|
7
|
+
o: any;
|
|
8
|
+
e: any;
|
|
9
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CallbacksRepo } from './callbacks';
|
|
2
|
+
import { ObjectsRepo } from './objects';
|
|
3
|
+
export var callbacksRepo = new CallbacksRepo();
|
|
4
|
+
export var objectsRepo = new ObjectsRepo();
|
|
5
|
+
// Separates properties in 3 categories: regular props, callbacks and non-serializable objects
|
|
6
|
+
export function convertPropsToSerializable(props) {
|
|
7
|
+
var res = {};
|
|
8
|
+
for (var key in props) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(props, key)) {
|
|
10
|
+
var value = props[key];
|
|
11
|
+
if (value == null) {
|
|
12
|
+
(res.p || (res.p = {}))[key] = null;
|
|
13
|
+
}
|
|
14
|
+
else if (key === 'style') {
|
|
15
|
+
(res.p || (res.p = {}))[key] = convertPropsToSerializable(value);
|
|
16
|
+
}
|
|
17
|
+
else if (key[0] === 'o' && key[1] === 'n' && typeof value === 'function') {
|
|
18
|
+
var ind = callbacksRepo.addObject(value);
|
|
19
|
+
(res.e || (res.e = {}))[key] = ind;
|
|
20
|
+
}
|
|
21
|
+
else if (typeof value === 'object' || typeof value === 'function') {
|
|
22
|
+
var ind = objectsRepo.addObject(value);
|
|
23
|
+
(res.o || (res.o = {}))[key] = ind;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
(res.p || (res.p = {}))[key] = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return res;
|
|
31
|
+
}
|
|
@@ -3,17 +3,43 @@ import { ReactUnity } from '../../models/generated';
|
|
|
3
3
|
import { ChildSet, HydratableInstance, InstanceTag, NoTimeout, Props, TimeoutHandle, UpdatePayload } from '../../models/renderer';
|
|
4
4
|
import { BatchCommand } from './commands';
|
|
5
5
|
import { ObjectsRepo } from './objects';
|
|
6
|
-
export declare type AsyncHostContext =
|
|
6
|
+
export declare type AsyncHostContext = AsyncNativeInstance | AsyncSubContext;
|
|
7
|
+
export declare type AsyncInstance = AsyncNativeInstance | AsyncSubContext;
|
|
8
|
+
export declare type AsyncNativeInstance = {
|
|
7
9
|
context: ReactUnity.ReactContext;
|
|
8
10
|
commands: BatchCommand[];
|
|
9
|
-
};
|
|
10
|
-
export declare type AsyncNativeInstance = AsyncHostContext & {
|
|
11
11
|
refId: number;
|
|
12
|
+
type: 'native';
|
|
13
|
+
subContext?: AsyncSubContext;
|
|
14
|
+
};
|
|
15
|
+
export declare type AsyncSubContext = RichTextContext | SvgContext;
|
|
16
|
+
export declare type RichTextContext = {
|
|
17
|
+
hostContext: AsyncNativeInstance;
|
|
18
|
+
type: 'richtext';
|
|
19
|
+
node: RichTextNode;
|
|
20
|
+
root: AsyncNativeInstance;
|
|
21
|
+
parent: RichTextContext;
|
|
22
|
+
};
|
|
23
|
+
export declare type SvgContext = {
|
|
24
|
+
hostContext: AsyncNativeInstance;
|
|
25
|
+
type: 'svg';
|
|
26
|
+
node: RichTextNode;
|
|
27
|
+
root: AsyncNativeInstance;
|
|
28
|
+
parent: SvgContext;
|
|
12
29
|
};
|
|
13
|
-
declare type
|
|
30
|
+
export declare type RichTextNode = ({
|
|
31
|
+
tag: string;
|
|
32
|
+
attributes: Record<string, any>;
|
|
33
|
+
children: RichTextNode[];
|
|
34
|
+
hidden?: boolean;
|
|
35
|
+
} | {
|
|
36
|
+
text: string;
|
|
37
|
+
hidden?: boolean;
|
|
38
|
+
});
|
|
39
|
+
export declare type AsyncContainerInstance = AsyncNativeInstance & {
|
|
14
40
|
component: ReactUnity.IReactComponent;
|
|
15
41
|
fiberCache: ObjectsRepo | null;
|
|
16
42
|
};
|
|
17
43
|
declare type AsyncPublicInstance = ReactUnity.IReactComponent;
|
|
18
|
-
export declare type AsyncReconcilerConfig = Reconciler.HostConfig<InstanceTag, Props, AsyncContainerInstance,
|
|
44
|
+
export declare type AsyncReconcilerConfig = Reconciler.HostConfig<InstanceTag, Props, AsyncContainerInstance, AsyncInstance, AsyncInstance, AsyncNativeInstance, HydratableInstance, AsyncPublicInstance, AsyncHostContext, UpdatePayload, ChildSet, TimeoutHandle, NoTimeout>;
|
|
19
45
|
export {};
|
|
@@ -19,5 +19,10 @@ export declare const commonReconciler: {
|
|
|
19
19
|
scheduleTimeout: (callback: any, delay: any) => number;
|
|
20
20
|
scheduleMicrotask: (callback: (...args: any[]) => any) => void;
|
|
21
21
|
cancelTimeout: (handle: any) => void;
|
|
22
|
+
beforeActiveInstanceBlur(): void;
|
|
23
|
+
afterActiveInstanceBlur(): void;
|
|
24
|
+
getInstanceFromNode(node: any): any;
|
|
25
|
+
getInstanceFromScope(scopeInstance: any): any;
|
|
26
|
+
prepareScopeUpdate(scopeInstance: any, instance: any): void;
|
|
22
27
|
};
|
|
23
28
|
export declare const isDevelopment: boolean;
|
|
@@ -45,5 +45,17 @@ export var commonReconciler = {
|
|
|
45
45
|
function (callback) { return Promise.resolve(null).then(callback)
|
|
46
46
|
.catch(function (error) { return setTimeout(function () { throw error; }, 0); }); },
|
|
47
47
|
cancelTimeout: function (handle) { return clearTimeout(handle); },
|
|
48
|
+
beforeActiveInstanceBlur: function () {
|
|
49
|
+
},
|
|
50
|
+
afterActiveInstanceBlur: function () {
|
|
51
|
+
},
|
|
52
|
+
getInstanceFromNode: function (node) {
|
|
53
|
+
return undefined;
|
|
54
|
+
},
|
|
55
|
+
getInstanceFromScope: function (scopeInstance) {
|
|
56
|
+
return undefined;
|
|
57
|
+
},
|
|
58
|
+
prepareScopeUpdate: function (scopeInstance, instance) {
|
|
59
|
+
},
|
|
48
60
|
};
|
|
49
61
|
export var isDevelopment = process.env.NODE_ENV === 'development';
|
|
@@ -20,7 +20,7 @@ export function diffProperties(lastProps, nextProps, deepDiffing) {
|
|
|
20
20
|
else {
|
|
21
21
|
var depth = deepDiffing > 0 ? deepDiffing : propKey === 'style' ? 1 : 0;
|
|
22
22
|
if (depth > 0) {
|
|
23
|
-
prop = diffProperties(lastProps[propKey],
|
|
23
|
+
prop = diffProperties(lastProps[propKey], {}, depth - 1);
|
|
24
24
|
if (!prop)
|
|
25
25
|
continue;
|
|
26
26
|
}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { NativeContainerInstance } from '../models/renderer';
|
|
3
|
-
import {
|
|
4
|
-
import { AsyncNativeInstance } from './async/types';
|
|
3
|
+
import { AsyncContainerInstance, AsyncNativeInstance } from './async/types';
|
|
5
4
|
interface RenderOptions {
|
|
6
5
|
hostContainer?: NativeContainerInstance;
|
|
7
6
|
disableHelpers?: boolean;
|
|
8
7
|
mode?: 'legacy' | 'concurrent';
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
Render using the sync reconciler instead of the batch rendering. It is not recommended to change this value.
|
|
10
|
+
Changing this will disable some features like inline rich-text and svg rendering, although it may improve performance for Jint.
|
|
11
|
+
*/
|
|
12
|
+
disableBatchRendering?: boolean;
|
|
10
13
|
}
|
|
11
14
|
export declare const Renderer: {
|
|
12
|
-
render(element: React.ReactNode, options?: RenderOptions): import("react-reconciler").Reconciler<import("./async/types").
|
|
13
|
-
refId: number;
|
|
14
|
-
} & {
|
|
15
|
-
component: import("../..").ReactUnity.IReactComponent;
|
|
16
|
-
fiberCache: ObjectsRepo<any>;
|
|
17
|
-
}, AsyncNativeInstance, AsyncNativeInstance, AsyncNativeInstance, import("../..").ReactUnity.IReactComponent> | import("react-reconciler").Reconciler<import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.ITextComponent, import("../..").ReactUnity.IReactComponent, any>;
|
|
15
|
+
render(element: React.ReactNode, options?: RenderOptions): import("react-reconciler").Reconciler<AsyncContainerInstance, import("./async/types").AsyncInstance, import("./async/types").AsyncInstance, AsyncNativeInstance, import("../..").ReactUnity.IReactComponent> | import("react-reconciler").Reconciler<import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.IReactComponent, import("../..").ReactUnity.ITextComponent, import("../..").ReactUnity.IReactComponent, any>;
|
|
18
16
|
};
|
|
19
17
|
export declare const batchedUpdates: <A, R>(fn: (a: A) => R, a: A) => R;
|
|
20
|
-
export declare const flushSync:
|
|
18
|
+
export declare const flushSync: {
|
|
19
|
+
(): void;
|
|
20
|
+
<R>(fn: () => R): R;
|
|
21
|
+
};
|
|
21
22
|
export {};
|
|
@@ -11,9 +11,7 @@ export var Renderer = {
|
|
|
11
11
|
render: function (element, options) {
|
|
12
12
|
if (options === void 0) { options = {}; }
|
|
13
13
|
var hostContainer = (options === null || options === void 0 ? void 0 : options.hostContainer) || HostContainer;
|
|
14
|
-
|
|
15
|
-
// For other engines (ClearScript), async is default
|
|
16
|
-
var isAsync = hostContainer.Context.Script.Engine.Key === 'jint' ? (options === null || options === void 0 ? void 0 : options.sync) === false : !(options === null || options === void 0 ? void 0 : options.sync);
|
|
14
|
+
var isAsync = !(options === null || options === void 0 ? void 0 : options.disableBatchRendering);
|
|
17
15
|
var _a = containerMap.get(hostContainer) || {}, hostRoot = _a.hostRoot, asyncJobCallback = _a.asyncJobCallback;
|
|
18
16
|
var findFiberByHostInstance = function () { return null; };
|
|
19
17
|
if (!hostRoot) {
|
|
@@ -31,6 +29,7 @@ export var Renderer = {
|
|
|
31
29
|
args[_i] = arguments[_i];
|
|
32
30
|
}
|
|
33
31
|
if (!scheduled_1) {
|
|
32
|
+
scheduled_1 = true;
|
|
34
33
|
Promise.resolve().then(function () {
|
|
35
34
|
asyncJobCallback();
|
|
36
35
|
scheduled_1 = false;
|
|
@@ -39,6 +38,7 @@ export var Renderer = {
|
|
|
39
38
|
return Array.prototype.push.apply(commands_1, args);
|
|
40
39
|
};
|
|
41
40
|
var hostContainerInstance = {
|
|
41
|
+
type: 'native',
|
|
42
42
|
commands: commands_1,
|
|
43
43
|
component: hostContainer,
|
|
44
44
|
context: hostContainer.Context,
|
|
@@ -52,10 +52,10 @@ export var Renderer = {
|
|
|
52
52
|
commands_1.length = 0;
|
|
53
53
|
hostContainer.Context.FlushCommands(serialized);
|
|
54
54
|
};
|
|
55
|
-
hostRoot = asyncReconciler.createContainer(hostContainerInstance, mode, false, null);
|
|
55
|
+
hostRoot = asyncReconciler.createContainer(hostContainerInstance, mode, null, false, undefined, '', function (error) { return console.error(error); }, null);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
|
-
hostRoot = syncReconciler.createContainer(hostContainer, mode, false, null);
|
|
58
|
+
hostRoot = syncReconciler.createContainer(hostContainer, mode, null, false, undefined, '', function (error) { return console.error(error); }, null);
|
|
59
59
|
}
|
|
60
60
|
containerMap.set(hostContainer, { hostRoot: hostRoot, asyncJobCallback: asyncJobCallback });
|
|
61
61
|
}
|
|
@@ -78,7 +78,5 @@ export var Renderer = {
|
|
|
78
78
|
return rc;
|
|
79
79
|
},
|
|
80
80
|
};
|
|
81
|
-
var
|
|
82
|
-
var
|
|
83
|
-
export var batchedUpdates = defaultReconciler.batchedUpdates;
|
|
84
|
-
export var flushSync = defaultReconciler.flushSync;
|
|
81
|
+
export var batchedUpdates = asyncReconciler.batchedUpdates;
|
|
82
|
+
export var flushSync = asyncReconciler.flushSync;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export function parametrizeValue(value) {
|
|
2
|
+
if (typeof value === 'number')
|
|
3
|
+
return value + '';
|
|
4
|
+
value = value + '';
|
|
5
|
+
if (value.includes(' ') || value.includes('-'))
|
|
6
|
+
return '"' + value + '"';
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
export function stringifyRichText(node) {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
if (node.hidden)
|
|
12
|
+
return '';
|
|
13
|
+
if ('text' in node)
|
|
14
|
+
return node.text;
|
|
15
|
+
var acc = [];
|
|
16
|
+
var tag = node.tag;
|
|
17
|
+
if (tag) {
|
|
18
|
+
acc.push('<');
|
|
19
|
+
acc.push(tag);
|
|
20
|
+
if (((_a = node.attributes) === null || _a === void 0 ? void 0 : _a.value) != null) {
|
|
21
|
+
var value = (_b = node.attributes) === null || _b === void 0 ? void 0 : _b.value;
|
|
22
|
+
acc.push('=');
|
|
23
|
+
acc.push(parametrizeValue(value));
|
|
24
|
+
}
|
|
25
|
+
for (var key in node.attributes) {
|
|
26
|
+
if (key === 'value')
|
|
27
|
+
continue;
|
|
28
|
+
if (Object.prototype.hasOwnProperty.call(node.attributes, key)) {
|
|
29
|
+
var value = node.attributes[key];
|
|
30
|
+
if (value != null) {
|
|
31
|
+
acc.push(' ');
|
|
32
|
+
acc.push(key);
|
|
33
|
+
acc.push('=');
|
|
34
|
+
acc.push(parametrizeValue(value));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
acc.push('>');
|
|
39
|
+
}
|
|
40
|
+
if (((_c = node.children) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
41
|
+
for (var _i = 0, _d = node.children; _i < _d.length; _i++) {
|
|
42
|
+
var child = _d[_i];
|
|
43
|
+
acc.push(stringifyRichText(child));
|
|
44
|
+
}
|
|
45
|
+
if (tag) {
|
|
46
|
+
acc.push('</');
|
|
47
|
+
acc.push(tag);
|
|
48
|
+
acc.push('>');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return acc.join('');
|
|
52
|
+
}
|