@reactunity/renderer 0.9.1 → 0.10.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 (34) hide show
  1. package/dist/src/helpers/dictionary-watcher.d.ts +14 -2
  2. package/dist/src/helpers/dictionary-watcher.js +28 -21
  3. package/dist/src/helpers/watcher.js +10 -11
  4. package/dist/src/models/environment/index.d.ts +1 -0
  5. package/dist/src/models/generated/react.d.ts +398 -83
  6. package/dist/src/models/generated/react.js +1 -1
  7. package/dist/src/models/properties/styles.d.ts +10 -9
  8. package/dist/src/renderer/async/callbacks.d.ts +6 -0
  9. package/dist/src/renderer/async/callbacks.js +38 -0
  10. package/dist/src/renderer/async/commands.d.ts +45 -0
  11. package/dist/src/renderer/async/commands.js +1 -0
  12. package/dist/src/renderer/async/objects.d.ts +8 -0
  13. package/dist/src/renderer/async/objects.js +31 -0
  14. package/dist/src/renderer/async/reconciler.d.ts +8 -0
  15. package/dist/src/renderer/async/reconciler.js +105 -0
  16. package/dist/src/renderer/async/serializer.d.ts +9 -0
  17. package/dist/src/renderer/async/serializer.js +31 -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 +15 -1
  24. package/dist/src/renderer/renderer.js +77 -114
  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,122 +1,85 @@
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 LegacyRoot = 1;
17
- var ConcurrentRoot = 1;
18
- var hostContext = {};
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]) {
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
- render: function (element, hostContainer, renderWithoutHelpers) {
109
- if (!hostContainer)
110
- hostContainer = HostContainer;
111
- var hostRoot = containerMap.get(hostContainer);
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; };
112
19
  if (!hostRoot) {
113
- hostRoot = reconciler.createContainer(hostContainer, LegacyRoot, false, null);
114
- containerMap.set(hostContainer, 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
+ scheduled_1 = true;
35
+ Promise.resolve().then(function () {
36
+ asyncJobCallback();
37
+ scheduled_1 = false;
38
+ });
39
+ }
40
+ return Array.prototype.push.apply(commands_1, args);
41
+ };
42
+ var hostContainerInstance = {
43
+ commands: commands_1,
44
+ component: hostContainer,
45
+ context: hostContainer.Context,
46
+ refId: hostContainer.RefId,
47
+ fiberCache: fiberCache_1,
48
+ };
49
+ asyncJobCallback = function () {
50
+ if (!commands_1.length)
51
+ return;
52
+ var serialized = JSON.stringify(commands_1);
53
+ commands_1.length = 0;
54
+ hostContainer.Context.FlushCommands(serialized);
55
+ };
56
+ hostRoot = asyncReconciler.createContainer(hostContainerInstance, mode, false, null);
57
+ }
58
+ else {
59
+ hostRoot = syncReconciler.createContainer(hostContainer, mode, false, null);
60
+ }
61
+ containerMap.set(hostContainer, { hostRoot: hostRoot, asyncJobCallback: asyncJobCallback });
62
+ }
63
+ var shouldWrapWithHelpers = !(options === null || options === void 0 ? void 0 : options.disableHelpers);
64
+ if (shouldWrapWithHelpers) {
65
+ var viewWrapperProps = {
66
+ withHelpers: !(options === null || options === void 0 ? void 0 : options.disableHelpers),
67
+ };
68
+ element = createElement(DefaultView, viewWrapperProps, element);
115
69
  }
116
- if (!renderWithoutHelpers)
117
- element = createElement(DefaultView, null, element);
118
- reconciler.updateContainer(element, hostRoot, null);
70
+ var rc = isAsync ? asyncReconciler : syncReconciler;
71
+ rc.updateContainer(element, hostRoot, null);
72
+ rc.injectIntoDevTools({
73
+ bundleType: isDevelopment ? 1 : 0,
74
+ version: version,
75
+ rendererPackageName: '@reactunity/renderer',
76
+ rendererConfig: { isAsync: isAsync },
77
+ findFiberByHostInstance: findFiberByHostInstance,
78
+ });
79
+ return rc;
119
80
  },
120
81
  };
121
- export var batchedUpdates = reconciler.batchedUpdates;
122
- export var flushSync = reconciler.flushSync;
82
+ var isSyncByDefault = HostContainer.Context.Script.Engine.Key === 'jint';
83
+ var defaultReconciler = isSyncByDefault ? syncReconciler : asyncReconciler;
84
+ export var batchedUpdates = defaultReconciler.batchedUpdates;
85
+ 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.1";
@@ -0,0 +1 @@
1
+ export var version = '0.10.1';
@@ -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.1",
3
+ "version": "0.10.1",
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.9.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.5.5"
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`);