@reactunity/renderer 0.9.0 → 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.
Files changed (34) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/src/helpers/dictionary-watcher.d.ts +14 -2
  4. package/dist/src/helpers/dictionary-watcher.js +29 -22
  5. package/dist/src/helpers/watcher.js +10 -11
  6. package/dist/src/models/environment/index.d.ts +1 -0
  7. package/dist/src/models/generated/react.d.ts +398 -83
  8. package/dist/src/models/generated/react.js +1 -1
  9. package/dist/src/models/properties/styles.d.ts +6 -6
  10. package/dist/src/renderer/async/callbacks.d.ts +6 -0
  11. package/dist/src/renderer/async/callbacks.js +38 -0
  12. package/dist/src/renderer/async/commands.d.ts +45 -0
  13. package/dist/src/renderer/async/commands.js +1 -0
  14. package/dist/src/renderer/async/objects.d.ts +8 -0
  15. package/dist/src/renderer/async/objects.js +31 -0
  16. package/dist/src/renderer/async/reconciler.d.ts +9 -0
  17. package/dist/src/renderer/async/reconciler.js +135 -0
  18. package/dist/src/renderer/async/types.d.ts +19 -0
  19. package/dist/src/renderer/async/types.js +1 -0
  20. package/dist/src/renderer/constants.d.ts +23 -0
  21. package/dist/src/renderer/constants.js +49 -0
  22. package/dist/src/renderer/diffing.js +39 -13
  23. package/dist/src/renderer/renderer.d.ts +18 -2
  24. package/dist/src/renderer/renderer.js +78 -106
  25. package/dist/src/renderer/sync/reconciler.d.ts +2 -0
  26. package/dist/src/renderer/sync/reconciler.js +35 -0
  27. package/dist/src/version.d.ts +1 -0
  28. package/dist/src/version.js +1 -0
  29. package/dist/src/views/default-view.d.ts +2 -1
  30. package/dist/src/views/default-view.js +4 -3
  31. package/dist/src/views/error-boundary.d.ts +1 -1
  32. package/dist/src/views/error-boundary.js +1 -1
  33. package/package.json +9 -9
  34. package/version.js +3 -0
@@ -1,112 +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 * as Reconciler from 'react-reconciler';
2
+ import { ConcurrentRoot, LegacyRoot } from 'react-reconciler/constants';
3
+ import { version } from '../version';
14
4
  import { DefaultView } from '../views/default-view';
15
- import { diffProperties, styleStringSymbol } from './diffing';
16
- var hostContext = {};
17
- var childContext = {};
18
- var textTypes = {
19
- text: true,
20
- icon: true,
21
- style: true,
22
- script: true,
23
- };
24
- function getAllowedProps(props, type) {
25
- var children = props.children, tag = props.tag, rest = __rest(props, ["children", "tag"]);
26
- if (textTypes[type]) {
27
- rest.children = (!children || typeof children === 'boolean') ? null : Array.isArray(children) ? children.join('') : children + '';
28
- }
29
- if (typeof props.style === 'string')
30
- rest[styleStringSymbol] = props.style;
31
- return rest;
32
- }
33
- var hostConfig = {
34
- getRootHostContext: function (rootContainerInstance) { return hostContext; },
35
- getChildHostContext: function (parentHostContext, type, rootContainerInstance) { return childContext; },
36
- getPublicInstance: function (instance) { return instance; },
37
- prepareForCommit: function (containerInfo) { return null; },
38
- resetAfterCommit: function (containerInfo) { return null; },
39
- clearContainer: function () { return null; },
40
- now: Date.now,
41
- supportsHydration: false,
42
- supportsPersistence: false,
43
- isPrimaryRenderer: true,
44
- createInstance: function (type, props, rootContainerInstance, hostContext, internalInstanceHandle) {
45
- var aProps = getAllowedProps(props, type);
46
- var children = aProps.children || null;
47
- delete aProps.children;
48
- return UnityBridge.createElement(props.tag || type, children, rootContainerInstance, aProps);
49
- },
50
- createTextInstance: function (text, rootContainerInstance, hostContext, internalInstanceHandle) {
51
- return UnityBridge.createText(text, rootContainerInstance);
52
- },
53
- appendInitialChild: function (parent, child) { UnityBridge.appendChild(parent, child); },
54
- finalizeInitialChildren: function (instance, type, props, rootContainerInstance, hostContext) {
55
- return false;
56
- },
57
- commitMount: function (instance, type, newProps, internalInstanceHandle) { },
58
- shouldSetTextContent: function (type, props) { return textTypes[type]; },
59
- shouldDeprioritizeSubtree: function (type, props) { return false; },
60
- // -------------------
61
- // Mutation
62
- // -------------------
63
- supportsMutation: true,
64
- prepareUpdate: function (instance, type, oldProps, newProps, rootContainerInstance, hostContext) {
65
- return diffProperties(oldProps, newProps);
66
- },
67
- commitUpdate: function (instance, updatePayload, type, oldProps, newProps, internalInstanceHandle) {
68
- UnityBridge.applyUpdate(instance, getAllowedProps(updatePayload, type), type);
69
- },
70
- resetTextContent: function (instance) { console.log('resetTextContent'); },
71
- commitTextUpdate: function (textInstance, oldText, newText) { UnityBridge.setText(textInstance, newText); },
72
- appendChild: function (parent, child) { return UnityBridge.appendChild(parent, child); },
73
- appendChildToContainer: function (parent, child) { return UnityBridge.appendChildToContainer(parent, child); },
74
- insertBefore: function (parent, child, beforeChild) { return UnityBridge.insertBefore(parent, child, beforeChild); },
75
- insertInContainerBefore: function (parent, child, beforeChild) { return UnityBridge.insertBefore(parent, child, beforeChild); },
76
- removeChild: function (parent, child) { return UnityBridge.removeChild(parent, child); },
77
- removeChildFromContainer: function (parent, child) { return UnityBridge.removeChild(parent, child); },
78
- // Required for Suspense
79
- // TODO: implement
80
- preparePortalMount: function () { },
81
- hideInstance: function (instance) {
82
- },
83
- hideTextInstance: function (textInstance) {
84
- },
85
- unhideInstance: function (instance, props) {
86
- },
87
- unhideTextInstance: function (textInstance, text) {
88
- },
89
- // -------------------
90
- // Scheduling
91
- // -------------------
92
- scheduleDeferredCallback: function (callback, options) { return setTimeout(callback, (options === null || options === void 0 ? void 0 : options.timeout) || 0); },
93
- cancelDeferredCallback: function (callBackID) { clearTimeout(callBackID); },
94
- noTimeout: -1,
95
- scheduleTimeout: function (callback, timeout) { return setTimeout(callback, timeout); },
96
- cancelTimeout: function (handle) { clearTimeout(handle); },
97
- queueMicrotask: function (callback) { return setTimeout(callback, 0); },
98
- };
99
- var ReactUnityReconciler = 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';
100
9
  var containerMap = new Map();
101
10
  export var Renderer = {
102
- render: function (element, hostContainer, renderWithoutHelpers) {
103
- if (!hostContainer)
104
- hostContainer = HostContainer;
105
- var hostRoot = containerMap.get(hostContainer);
106
- if (!hostRoot)
107
- containerMap.set(hostContainer, hostRoot = ReactUnityReconciler.createContainer(hostContainer, 0, false, {}));
108
- if (!renderWithoutHelpers)
109
- element = createElement(DefaultView, null, element);
110
- return ReactUnityReconciler.updateContainer(element, hostRoot, null);
11
+ render: function (element, options) {
12
+ if (options === void 0) { options = {}; }
13
+ var hostContainer = (options === null || options === void 0 ? void 0 : options.hostContainer) || HostContainer;
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; };
19
+ if (!hostRoot) {
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);
68
+ }
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;
111
79
  },
112
80
  };
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(ErrorBoundary, { children: _jsx(GlobalsProvider, { children: children }, void 0) }, void 0);
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
  }
@@ -6,5 +6,5 @@ export declare class ErrorBoundary extends React.Component<any, any> {
6
6
  error: any;
7
7
  };
8
8
  componentDidCatch(error: any, errorInfo: any): void;
9
- render(): React.ReactNode;
9
+ render(): any;
10
10
  }
@@ -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) || '' }), void 0), _jsx("view", { children: ((_b = this.state.error) === null || _b === void 0 ? void 0 : _b.stack) || '' }, void 0)] }), void 0);
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.9.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
- "local": "yalc publish --push",
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.26.2"
57
+ "react-reconciler": "^0.28.0",
58
+ "use-sync-external-store": "^1.1.0"
59
59
  },
60
60
  "peerDependencies": {
61
- "react": "^17.0.2"
61
+ "react": "^18.0.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@reactunity/scripts": "^0.8.0",
65
- "@types/react-reconciler": "^0.26.4",
64
+ "@reactunity/scripts": "^0.10.0",
65
+ "@types/react-reconciler": "^0.26.6",
66
66
  "rimraf": "^3.0.2",
67
- "typescript": "^4.4.4"
67
+ "typescript": "^4.6.4"
68
68
  }
69
69
  }
package/version.js ADDED
@@ -0,0 +1,3 @@
1
+ const fs = require('fs');
2
+
3
+ fs.writeFileSync('./src/version.ts', `export const version = '${process.env.npm_package_version}';\n`);