@reactunity/renderer 0.9.2 → 0.10.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/src/helpers/dictionary-watcher.d.ts +14 -2
- package/dist/src/helpers/dictionary-watcher.js +28 -21
- package/dist/src/helpers/watcher.js +10 -11
- package/dist/src/models/environment/index.d.ts +1 -0
- package/dist/src/models/generated/react.d.ts +398 -83
- package/dist/src/models/generated/react.js +1 -1
- package/dist/src/models/properties/styles.d.ts +6 -6
- package/dist/src/renderer/async/callbacks.d.ts +6 -0
- package/dist/src/renderer/async/callbacks.js +38 -0
- package/dist/src/renderer/async/commands.d.ts +45 -0
- package/dist/src/renderer/async/commands.js +1 -0
- package/dist/src/renderer/async/objects.d.ts +8 -0
- package/dist/src/renderer/async/objects.js +31 -0
- package/dist/src/renderer/async/reconciler.d.ts +9 -0
- package/dist/src/renderer/async/reconciler.js +135 -0
- package/dist/src/renderer/async/types.d.ts +19 -0
- package/dist/src/renderer/async/types.js +1 -0
- package/dist/src/renderer/constants.d.ts +23 -0
- package/dist/src/renderer/constants.js +49 -0
- package/dist/src/renderer/diffing.js +39 -13
- package/dist/src/renderer/renderer.d.ts +9 -1
- package/dist/src/renderer/renderer.js +73 -111
- package/dist/src/renderer/sync/reconciler.d.ts +2 -0
- package/dist/src/renderer/sync/reconciler.js +35 -0
- package/dist/src/version.d.ts +1 -0
- package/dist/src/version.js +1 -0
- package/dist/src/views/default-view.d.ts +2 -1
- package/dist/src/views/default-view.js +4 -3
- package/dist/src/views/error-boundary.d.ts +1 -1
- package/dist/src/views/error-boundary.js +1 -1
- package/package.json +9 -9
- package/version.js +3 -0
|
@@ -1,122 +1,84 @@
|
|
|
1
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
-
var t = {};
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
1
|
import { createElement } from 'react';
|
|
13
|
-
import
|
|
2
|
+
import { ConcurrentRoot, LegacyRoot } from 'react-reconciler/constants';
|
|
3
|
+
import { version } from '../version';
|
|
14
4
|
import { DefaultView } from '../views/default-view';
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var childContext = {};
|
|
20
|
-
var DiscreteEventPriority = 1;
|
|
21
|
-
var ContinuousEventPriority = 4;
|
|
22
|
-
var DefaultEventPriority = 16;
|
|
23
|
-
var eventPriorities = {
|
|
24
|
-
discrete: DiscreteEventPriority,
|
|
25
|
-
continuous: ContinuousEventPriority,
|
|
26
|
-
default: DefaultEventPriority,
|
|
27
|
-
};
|
|
28
|
-
var textTypes = {
|
|
29
|
-
text: true,
|
|
30
|
-
icon: true,
|
|
31
|
-
style: true,
|
|
32
|
-
script: true,
|
|
33
|
-
};
|
|
34
|
-
function getAllowedProps(props, type) {
|
|
35
|
-
var children = props.children, tag = props.tag, rest = __rest(props, ["children", "tag"]);
|
|
36
|
-
if (textTypes[type] && 'children' in props) {
|
|
37
|
-
rest.children = (!children || typeof children === 'boolean') ? null : Array.isArray(children) ? children.join('') : children + '';
|
|
38
|
-
}
|
|
39
|
-
if (typeof props.style === 'string')
|
|
40
|
-
rest[styleStringSymbol] = props.style;
|
|
41
|
-
return rest;
|
|
42
|
-
}
|
|
43
|
-
var hostConfig = {
|
|
44
|
-
getRootHostContext: function () { return hostContext; },
|
|
45
|
-
getChildHostContext: function () { return childContext; },
|
|
46
|
-
getPublicInstance: function (instance) { return instance; },
|
|
47
|
-
now: Date.now,
|
|
48
|
-
supportsMutation: true,
|
|
49
|
-
supportsHydration: false,
|
|
50
|
-
supportsPersistence: false,
|
|
51
|
-
supportsMicrotasks: false,
|
|
52
|
-
supportsTestSelectors: false,
|
|
53
|
-
isPrimaryRenderer: true,
|
|
54
|
-
warnsIfNotActing: true,
|
|
55
|
-
prepareForCommit: function () { return null; },
|
|
56
|
-
resetAfterCommit: function () { },
|
|
57
|
-
clearContainer: function () { },
|
|
58
|
-
shouldDeprioritizeSubtree: function () { return false; },
|
|
59
|
-
createInstance: function (type, props, rootContainerInstance) {
|
|
60
|
-
var aProps = getAllowedProps(props, type);
|
|
61
|
-
var children = aProps.children || null;
|
|
62
|
-
delete aProps.children;
|
|
63
|
-
return UnityBridge.createElement(props.tag || type, children, rootContainerInstance, aProps);
|
|
64
|
-
},
|
|
65
|
-
createTextInstance: function (text, rootContainerInstance) {
|
|
66
|
-
return UnityBridge.createText(text, rootContainerInstance);
|
|
67
|
-
},
|
|
68
|
-
appendInitialChild: function (parent, child) { UnityBridge.appendChild(parent, child); },
|
|
69
|
-
finalizeInitialChildren: function () { return false; },
|
|
70
|
-
commitMount: function () { },
|
|
71
|
-
shouldSetTextContent: function (type) { return textTypes[type]; },
|
|
72
|
-
// -------------------
|
|
73
|
-
// Mutation
|
|
74
|
-
// -------------------
|
|
75
|
-
prepareUpdate: function (instance, type, oldProps, newProps) {
|
|
76
|
-
return diffProperties(oldProps, newProps);
|
|
77
|
-
},
|
|
78
|
-
commitUpdate: function (instance, updatePayload, type) {
|
|
79
|
-
UnityBridge.applyUpdate(instance, getAllowedProps(updatePayload, type), type);
|
|
80
|
-
},
|
|
81
|
-
resetTextContent: function () { return console.log('resetTextContent'); },
|
|
82
|
-
commitTextUpdate: function (textInstance, oldText, newText) { UnityBridge.setText(textInstance, newText); },
|
|
83
|
-
appendChild: function (parent, child) { return UnityBridge.appendChild(parent, child); },
|
|
84
|
-
appendChildToContainer: function (parent, child) { return UnityBridge.appendChildToContainer(parent, child); },
|
|
85
|
-
insertBefore: function (parent, child, beforeChild) { return UnityBridge.insertBefore(parent, child, beforeChild); },
|
|
86
|
-
insertInContainerBefore: function (parent, child, beforeChild) { return UnityBridge.insertBefore(parent, child, beforeChild); },
|
|
87
|
-
removeChild: function (parent, child) { return UnityBridge.removeChild(parent, child); },
|
|
88
|
-
removeChildFromContainer: function (parent, child) { return UnityBridge.removeChild(parent, child); },
|
|
89
|
-
// Required for Suspense
|
|
90
|
-
// TODO: implement
|
|
91
|
-
preparePortalMount: function () { },
|
|
92
|
-
hideInstance: function () { },
|
|
93
|
-
hideTextInstance: function () { },
|
|
94
|
-
unhideInstance: function () { },
|
|
95
|
-
unhideTextInstance: function () { },
|
|
96
|
-
detachDeletedInstance: function () { },
|
|
97
|
-
// -------------------
|
|
98
|
-
// Scheduling
|
|
99
|
-
// -------------------
|
|
100
|
-
getCurrentEventPriority: function () { return eventPriorities.default; },
|
|
101
|
-
noTimeout: -1,
|
|
102
|
-
scheduleTimeout: function (callback, timeout) { return setTimeout(callback, timeout); },
|
|
103
|
-
cancelTimeout: function (handle) { return clearTimeout(handle); },
|
|
104
|
-
};
|
|
105
|
-
var reconciler = Reconciler(hostConfig);
|
|
5
|
+
import { ObjectsRepo } from './async/objects';
|
|
6
|
+
import { asyncReconciler } from './async/reconciler';
|
|
7
|
+
import { isDevelopment } from './constants';
|
|
8
|
+
import { syncReconciler } from './sync/reconciler';
|
|
106
9
|
var containerMap = new Map();
|
|
107
10
|
export var Renderer = {
|
|
108
11
|
render: function (element, options) {
|
|
109
12
|
if (options === void 0) { options = {}; }
|
|
110
13
|
var hostContainer = (options === null || options === void 0 ? void 0 : options.hostContainer) || HostContainer;
|
|
111
|
-
|
|
14
|
+
// For Jint engine, sync is default
|
|
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);
|
|
17
|
+
var _a = containerMap.get(hostContainer) || {}, hostRoot = _a.hostRoot, asyncJobCallback = _a.asyncJobCallback;
|
|
18
|
+
var findFiberByHostInstance = function () { return null; };
|
|
112
19
|
if (!hostRoot) {
|
|
113
|
-
|
|
114
|
-
|
|
20
|
+
var mode = (options === null || options === void 0 ? void 0 : options.mode) === 'legacy' ? LegacyRoot : ConcurrentRoot;
|
|
21
|
+
if (isAsync) {
|
|
22
|
+
var fiberCache_1 = isDevelopment ? new ObjectsRepo() : null;
|
|
23
|
+
if (isDevelopment) {
|
|
24
|
+
findFiberByHostInstance = function (instance) { return !instance ? null : fiberCache_1.getObject(instance.refId); };
|
|
25
|
+
}
|
|
26
|
+
var scheduled_1 = false;
|
|
27
|
+
var commands_1 = [];
|
|
28
|
+
commands_1.push = function () {
|
|
29
|
+
var args = [];
|
|
30
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
31
|
+
args[_i] = arguments[_i];
|
|
32
|
+
}
|
|
33
|
+
if (!scheduled_1) {
|
|
34
|
+
Promise.resolve().then(function () {
|
|
35
|
+
asyncJobCallback();
|
|
36
|
+
scheduled_1 = false;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return Array.prototype.push.apply(commands_1, args);
|
|
40
|
+
};
|
|
41
|
+
var hostContainerInstance = {
|
|
42
|
+
commands: commands_1,
|
|
43
|
+
component: hostContainer,
|
|
44
|
+
context: hostContainer.Context,
|
|
45
|
+
refId: hostContainer.RefId,
|
|
46
|
+
fiberCache: fiberCache_1,
|
|
47
|
+
};
|
|
48
|
+
asyncJobCallback = function () {
|
|
49
|
+
if (!commands_1.length)
|
|
50
|
+
return;
|
|
51
|
+
var serialized = JSON.stringify(commands_1);
|
|
52
|
+
commands_1.length = 0;
|
|
53
|
+
hostContainer.Context.FlushCommands(serialized);
|
|
54
|
+
};
|
|
55
|
+
hostRoot = asyncReconciler.createContainer(hostContainerInstance, mode, false, null);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
hostRoot = syncReconciler.createContainer(hostContainer, mode, false, null);
|
|
59
|
+
}
|
|
60
|
+
containerMap.set(hostContainer, { hostRoot: hostRoot, asyncJobCallback: asyncJobCallback });
|
|
61
|
+
}
|
|
62
|
+
var shouldWrapWithHelpers = !(options === null || options === void 0 ? void 0 : options.disableHelpers);
|
|
63
|
+
if (shouldWrapWithHelpers) {
|
|
64
|
+
var viewWrapperProps = {
|
|
65
|
+
withHelpers: !(options === null || options === void 0 ? void 0 : options.disableHelpers),
|
|
66
|
+
};
|
|
67
|
+
element = createElement(DefaultView, viewWrapperProps, element);
|
|
115
68
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
69
|
+
var rc = isAsync ? asyncReconciler : syncReconciler;
|
|
70
|
+
rc.updateContainer(element, hostRoot, null);
|
|
71
|
+
rc.injectIntoDevTools({
|
|
72
|
+
bundleType: isDevelopment ? 1 : 0,
|
|
73
|
+
version: version,
|
|
74
|
+
rendererPackageName: '@reactunity/renderer',
|
|
75
|
+
rendererConfig: { isAsync: isAsync },
|
|
76
|
+
findFiberByHostInstance: findFiberByHostInstance,
|
|
77
|
+
});
|
|
78
|
+
return rc;
|
|
119
79
|
},
|
|
120
80
|
};
|
|
121
|
-
|
|
122
|
-
|
|
81
|
+
var isSyncByDefault = HostContainer.Context.Script.Engine.Key === 'jint';
|
|
82
|
+
var defaultReconciler = isSyncByDefault ? syncReconciler : asyncReconciler;
|
|
83
|
+
export var batchedUpdates = defaultReconciler.batchedUpdates;
|
|
84
|
+
export var flushSync = defaultReconciler.flushSync;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import * as Reconciler from 'react-reconciler';
|
|
2
|
+
export declare const syncReconciler: Reconciler.Reconciler<import("../../..").ReactUnity.IReactComponent, import("../../..").ReactUnity.IReactComponent, import("../../..").ReactUnity.ITextComponent, import("../../..").ReactUnity.IReactComponent, any>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import * as Reconciler from 'react-reconciler';
|
|
13
|
+
import { commonReconciler, getAllowedProps, hideClass, textTypes } from '../constants';
|
|
14
|
+
import { diffProperties } from '../diffing';
|
|
15
|
+
var hostContext = {};
|
|
16
|
+
var childContext = {};
|
|
17
|
+
var hostConfig = __assign(__assign({}, commonReconciler), { getRootHostContext: function () { return hostContext; }, getChildHostContext: function () { return childContext; }, getPublicInstance: function (instance) { return instance; }, supportsMutation: true, supportsHydration: false, supportsPersistence: false, supportsMicrotasks: true, supportsTestSelectors: false, isPrimaryRenderer: true, warnsIfNotActing: true, prepareForCommit: function () { return null; }, resetAfterCommit: function () { }, clearContainer: function (container) { return UnityBridge.clearContainer(container); }, shouldDeprioritizeSubtree: function () { return false; }, createInstance: function (type, props, rootContainerInstance) {
|
|
18
|
+
var aProps = getAllowedProps(props, type);
|
|
19
|
+
var children = aProps.children || null;
|
|
20
|
+
delete aProps.children;
|
|
21
|
+
return UnityBridge.createElement(props.tag || type, children, rootContainerInstance, aProps);
|
|
22
|
+
}, createTextInstance: function (text, rootContainerInstance) {
|
|
23
|
+
return UnityBridge.createText(text, rootContainerInstance);
|
|
24
|
+
}, appendInitialChild: function (parent, child) { UnityBridge.appendChild(parent, child); }, finalizeInitialChildren: function () { return false; }, commitMount: function () { }, shouldSetTextContent: function (type) { return textTypes[type]; },
|
|
25
|
+
// -------------------
|
|
26
|
+
// Mutation
|
|
27
|
+
// -------------------
|
|
28
|
+
prepareUpdate: function (instance, type, oldProps, newProps) {
|
|
29
|
+
return diffProperties(oldProps, newProps);
|
|
30
|
+
}, commitUpdate: function (instance, updatePayload, type) {
|
|
31
|
+
UnityBridge.applyUpdate(instance, getAllowedProps(updatePayload, type), type);
|
|
32
|
+
}, commitTextUpdate: function (textInstance, oldText, newText) { UnityBridge.setText(textInstance, newText); }, appendChild: function (parent, child) { return UnityBridge.appendChild(parent, child); }, appendChildToContainer: function (parent, child) { return UnityBridge.appendChildToContainer(parent, child); }, insertBefore: function (parent, child, beforeChild) { return UnityBridge.insertBefore(parent, child, beforeChild); }, insertInContainerBefore: function (parent, child, beforeChild) { return UnityBridge.insertBefore(parent, child, beforeChild); }, removeChild: function (parent, child) { return UnityBridge.removeChild(parent, child); }, removeChildFromContainer: function (parent, child) { return UnityBridge.removeChild(parent, child); }, resetTextContent: function () { }, preparePortalMount: function () { }, detachDeletedInstance: function () { },
|
|
33
|
+
// Required for Suspense
|
|
34
|
+
hideInstance: function (instance) { instance.ClassList.Add(hideClass); }, hideTextInstance: function (instance) { instance.ClassList.Add(hideClass); }, unhideInstance: function (instance) { instance.ClassList.Remove(hideClass); }, unhideTextInstance: function (instance) { instance.ClassList.Remove(hideClass); } });
|
|
35
|
+
export var syncReconciler = Reconciler(hostConfig);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "0.10.0";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var version = '0.10.0';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
interface Props {
|
|
3
3
|
children?: ReactNode;
|
|
4
|
+
withHelpers: boolean;
|
|
4
5
|
}
|
|
5
|
-
export declare function DefaultView({ children }: Props): JSX.Element;
|
|
6
|
+
export declare function DefaultView({ children, withHelpers }: Props): JSX.Element;
|
|
6
7
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { GlobalsProvider } from '../helpers/dictionary-watcher';
|
|
3
3
|
import { ErrorBoundary } from './error-boundary';
|
|
4
4
|
export function DefaultView(_a) {
|
|
5
|
-
var children = _a.children;
|
|
6
|
-
return _jsx(
|
|
5
|
+
var children = _a.children, withHelpers = _a.withHelpers;
|
|
6
|
+
return _jsx(_Fragment, { children: !withHelpers ? children :
|
|
7
|
+
_jsx(ErrorBoundary, { children: _jsx(GlobalsProvider, { children: children }) }) });
|
|
7
8
|
}
|
|
@@ -44,7 +44,7 @@ var ErrorBoundary = /** @class */ (function (_super) {
|
|
|
44
44
|
ErrorBoundary.prototype.render = function () {
|
|
45
45
|
var _a, _b;
|
|
46
46
|
if (this.state.hasError) {
|
|
47
|
-
return _jsxs("view", __assign({ style: { color: 'crimson', padding: 20 } }, { children: [_jsx("view", __assign({ style: { marginBottom: '12px' } }, { children: ((_a = this.state.error) === null || _a === void 0 ? void 0 : _a.message) || '' })
|
|
47
|
+
return _jsxs("view", __assign({ style: { color: 'crimson', padding: 20 } }, { children: [_jsx("view", __assign({ style: { marginBottom: '12px' } }, { children: ((_a = this.state.error) === null || _a === void 0 ? void 0 : _a.message) || '' })), _jsx("view", { children: ((_b = this.state.error) === null || _b === void 0 ? void 0 : _b.stack) || '' })] }));
|
|
48
48
|
}
|
|
49
49
|
return this.props.children;
|
|
50
50
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactunity/renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "React renderer for Unity3D",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -39,10 +39,9 @@
|
|
|
39
39
|
"prepare": "yarn build",
|
|
40
40
|
"watch": "tsc --watch",
|
|
41
41
|
"lint": "react-unity-scripts lint",
|
|
42
|
-
"
|
|
43
|
-
"pack": "npm pack"
|
|
42
|
+
"version": "node version.js && git add src/version.ts"
|
|
44
43
|
},
|
|
45
|
-
"author": "Gokhan Kurt <krtgkn@gmail.com>",
|
|
44
|
+
"author": "Gokhan Kurt <krtgkn@gmail.com> (https://github.com/KurtGokhan)",
|
|
46
45
|
"license": "MIT",
|
|
47
46
|
"repository": {
|
|
48
47
|
"type": "git",
|
|
@@ -55,15 +54,16 @@
|
|
|
55
54
|
"unity3d"
|
|
56
55
|
],
|
|
57
56
|
"dependencies": {
|
|
58
|
-
"react-reconciler": "^0.
|
|
57
|
+
"react-reconciler": "^0.28.0",
|
|
58
|
+
"use-sync-external-store": "^1.1.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"react": "
|
|
61
|
+
"react": "^18.0.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@reactunity/scripts": "^0.
|
|
65
|
-
"@types/react-reconciler": "^0.26.
|
|
64
|
+
"@reactunity/scripts": "^0.10.0",
|
|
65
|
+
"@types/react-reconciler": "^0.26.6",
|
|
66
66
|
"rimraf": "^3.0.2",
|
|
67
|
-
"typescript": "^4.
|
|
67
|
+
"typescript": "^4.6.4"
|
|
68
68
|
}
|
|
69
69
|
}
|
package/version.js
ADDED