@reactunity/renderer 0.15.1 → 0.16.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/editor/index.d.ts +1 -0
- package/dist/editor/index.js +1 -0
- package/dist/editor/jsx-dev-runtime.d.ts +2 -0
- package/dist/editor/jsx-dev-runtime.js +1 -0
- package/dist/editor/jsx-runtime.d.ts +2 -0
- package/dist/editor/jsx-runtime.js +1 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.js +9 -9
- package/dist/src/helpers/dictionary-watcher.d.ts +66 -66
- package/dist/src/helpers/dictionary-watcher.js +100 -98
- package/dist/src/helpers/hooks/use-globals.d.ts +6 -6
- package/dist/src/helpers/hooks/use-globals.js +6 -6
- package/dist/src/helpers/hooks/use-reactive-value.d.ts +4 -4
- package/dist/src/helpers/hooks/use-reactive-value.js +27 -27
- package/dist/src/helpers/icons.d.ts +11 -7
- package/dist/src/helpers/icons.js +29 -29
- package/dist/src/models/base.d.ts +56 -56
- package/dist/src/models/base.js +2 -2
- package/dist/src/models/editor/components.d.ts +22 -22
- package/dist/src/models/editor/components.js +1 -1
- package/dist/src/models/editor/environment.d.ts +9 -10
- package/dist/src/models/editor/environment.js +1 -1
- package/dist/src/models/editor/index.d.ts +3 -3
- package/dist/src/models/editor/index.js +3 -3
- package/dist/src/models/editor/jsx.d.ts +111 -104
- package/dist/src/models/editor/jsx.js +1 -1
- package/dist/src/models/environment/dom/common.d.ts +85 -85
- package/dist/src/models/environment/dom/common.js +1 -1
- package/dist/src/models/environment/dom/fetch.d.ts +111 -111
- package/dist/src/models/environment/dom/fetch.js +1 -1
- package/dist/src/models/environment/dom/global.d.ts +11 -11
- package/dist/src/models/environment/dom/global.js +1 -1
- package/dist/src/models/environment/dom/xhr.d.ts +161 -161
- package/dist/src/models/environment/dom/xhr.js +1 -1
- package/dist/src/models/environment/index.d.ts +43 -47
- package/dist/src/models/environment/index.js +2 -3
- package/dist/src/models/environment/interop.d.ts +23 -23
- package/dist/src/models/environment/interop.js +1 -1
- package/dist/src/models/generated/editor.d.ts +18501 -18501
- package/dist/src/models/generated/editor.js +6 -6
- package/dist/src/models/generated/index.d.ts +6 -6
- package/dist/src/models/generated/index.js +6 -6
- package/dist/src/models/generated/react.d.ts +15214 -15214
- package/dist/src/models/generated/react.js +6 -6
- package/dist/src/models/generated/system.d.ts +36731 -36731
- package/dist/src/models/generated/system.js +6 -6
- package/dist/src/models/generated/tests.d.ts +5023 -5023
- package/dist/src/models/generated/tests.js +6 -6
- package/dist/src/models/generated/unity.d.ts +43446 -43446
- package/dist/src/models/generated/unity.js +6 -6
- package/dist/src/models/generated/yoga.d.ts +368 -368
- package/dist/src/models/generated/yoga.js +6 -6
- package/dist/src/models/properties/colors.d.ts +150 -150
- package/dist/src/models/properties/colors.js +1 -1
- package/dist/src/models/properties/common.d.ts +2 -2
- package/dist/src/models/properties/common.js +1 -1
- package/dist/src/models/properties/index.d.ts +7 -7
- package/dist/src/models/properties/index.js +7 -7
- package/dist/src/models/properties/style.d.ts +10 -10
- package/dist/src/models/properties/style.js +1 -1
- package/dist/src/models/properties/styles-enums.d.ts +23 -23
- package/dist/src/models/properties/styles-enums.js +1 -1
- package/dist/src/models/properties/styles.d.ts +127 -127
- package/dist/src/models/properties/styles.js +1 -1
- package/dist/src/models/properties/values.d.ts +24 -24
- package/dist/src/models/properties/values.js +1 -1
- package/dist/src/models/properties/yoga-enums.d.ts +8 -8
- package/dist/src/models/properties/yoga-enums.js +1 -1
- package/dist/src/models/properties/yoga.d.ts +66 -66
- package/dist/src/models/properties/yoga.js +1 -1
- package/dist/src/models/renderer.d.ts +20 -20
- package/dist/src/models/renderer.js +1 -1
- package/dist/src/models/richtext.d.ts +69 -69
- package/dist/src/models/richtext.js +2 -2
- package/dist/src/models/svg.d.ts +68 -68
- package/dist/src/models/svg.js +1 -1
- package/dist/src/models/tests/index.d.ts +12 -12
- package/dist/src/models/tests/index.js +1 -1
- package/dist/src/models/ugui/components.d.ts +86 -86
- package/dist/src/models/ugui/components.js +1 -1
- package/dist/src/models/ugui/events.d.ts +74 -74
- package/dist/src/models/ugui/events.js +2 -2
- package/dist/src/models/ugui/index.d.ts +4 -4
- package/dist/src/models/ugui/index.js +4 -4
- package/dist/src/models/ugui/input.d.ts +26 -26
- package/dist/src/models/ugui/input.js +1 -1
- package/dist/src/models/ugui/jsx.d.ts +67 -60
- package/dist/src/models/ugui/jsx.js +1 -1
- package/dist/src/models/uitoolkit/components.d.ts +82 -82
- package/dist/src/models/uitoolkit/components.js +1 -1
- package/dist/src/models/uitoolkit/events.d.ts +64 -64
- package/dist/src/models/uitoolkit/events.js +1 -1
- package/dist/src/models/uitoolkit/index.d.ts +3 -3
- package/dist/src/models/uitoolkit/index.js +3 -3
- package/dist/src/models/uitoolkit/jsx.d.ts +71 -64
- package/dist/src/models/uitoolkit/jsx.js +1 -1
- package/dist/src/renderer/async/callbacks.d.ts +5 -6
- package/dist/src/renderer/async/callbacks.js +52 -52
- package/dist/src/renderer/async/commands.d.ts +98 -47
- package/dist/src/renderer/async/commands.js +1 -1
- package/dist/src/renderer/async/objects.d.ts +7 -8
- package/dist/src/renderer/async/objects.js +31 -31
- package/dist/src/renderer/async/reconciler.d.ts +2 -2
- package/dist/src/renderer/async/reconciler.js +304 -283
- package/dist/src/renderer/async/serializer.d.ts +6 -9
- package/dist/src/renderer/async/serializer.js +31 -31
- package/dist/src/renderer/async/types.d.ts +45 -45
- package/dist/src/renderer/async/types.js +1 -1
- package/dist/src/renderer/constants.d.ts +30 -30
- package/dist/src/renderer/constants.js +70 -70
- package/dist/src/renderer/diffing.d.ts +3 -3
- package/dist/src/renderer/diffing.js +83 -83
- package/dist/src/renderer/renderer.d.ts +26 -26
- package/dist/src/renderer/renderer.js +93 -93
- package/dist/src/renderer/subcontexts/index.d.ts +6 -6
- package/dist/src/renderer/subcontexts/index.js +6 -6
- package/dist/src/renderer/subcontexts/richtext.d.ts +3 -3
- package/dist/src/renderer/subcontexts/richtext.js +52 -52
- package/dist/src/renderer/subcontexts/svg.d.ts +3 -3
- package/dist/src/renderer/subcontexts/svg.js +70 -70
- package/dist/src/renderer/sync/reconciler.d.ts +2 -2
- package/dist/src/renderer/sync/reconciler.js +35 -35
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/views/default-view.d.ts +8 -8
- package/dist/src/views/default-view.js +7 -7
- package/dist/src/views/error-boundary.d.ts +10 -10
- package/dist/src/views/error-boundary.js +42 -53
- package/dist/src/webgl-compat/error-messages.d.ts +9 -9
- package/dist/src/webgl-compat/error-messages.js +10 -10
- package/dist/src/webgl-compat/index.d.ts +13 -13
- package/dist/src/webgl-compat/index.js +8 -8
- package/dist/src/webgl-compat/types.d.ts +21 -21
- package/dist/src/webgl-compat/types.js +1 -1
- package/dist/src/webgl-compat/use-event-system.d.ts +3 -3
- package/dist/src/webgl-compat/use-event-system.js +77 -76
- package/dist/src/webgl-compat/use-unity-context.d.ts +31 -31
- package/dist/src/webgl-compat/use-unity-context.js +92 -91
- package/dist/tests.d.ts +1 -1
- package/dist/tests.js +1 -1
- package/dist/ugui/index.d.ts +1 -0
- package/dist/ugui/index.js +1 -0
- package/dist/ugui/jsx-dev-runtime.d.ts +2 -0
- package/dist/ugui/jsx-dev-runtime.js +1 -0
- package/dist/ugui/jsx-runtime.d.ts +2 -0
- package/dist/ugui/jsx-runtime.js +1 -0
- package/dist/uitoolkit/index.d.ts +1 -0
- package/dist/uitoolkit/index.js +1 -0
- package/dist/uitoolkit/jsx-dev-runtime.d.ts +2 -0
- package/dist/uitoolkit/jsx-dev-runtime.js +1 -0
- package/dist/uitoolkit/jsx-runtime.d.ts +2 -0
- package/dist/uitoolkit/jsx-runtime.js +1 -0
- package/dist/webgl-compat.d.ts +1 -1
- package/dist/webgl-compat.js +1 -1
- package/editor/jsx-dev-runtime.ts +4 -0
- package/editor/jsx-runtime.ts +4 -0
- package/package.json +13 -32
- package/ugui/jsx-dev-runtime.ts +4 -0
- package/ugui/jsx-runtime.ts +4 -0
- package/uitoolkit/jsx-dev-runtime.ts +4 -0
- package/uitoolkit/jsx-runtime.ts +4 -0
- package/dist/editor.d.ts +0 -1
- package/dist/editor.js +0 -1
- package/dist/src/models/environment/jsx.d.ts +0 -45
- package/dist/src/models/environment/jsx.js +0 -1
- package/dist/ugui.d.ts +0 -1
- package/dist/ugui.js +0 -1
- package/dist/uitoolkit.d.ts +0 -1
- package/dist/uitoolkit.js +0 -1
- package/editor.ts +0 -1
- package/tsconfig.editor.json +0 -6
- package/tsconfig.ugui.json +0 -6
- package/tsconfig.uitoolkit.json +0 -6
- package/ugui.ts +0 -1
- package/uitoolkit.ts +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../src/models/editor';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../src/models/editor';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react/jsx-dev-runtime';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react/jsx-runtime';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './src/helpers/dictionary-watcher';
|
|
2
|
-
export * from './src/helpers/hooks/use-globals';
|
|
3
|
-
export * from './src/helpers/hooks/use-reactive-value';
|
|
4
|
-
export * from './src/helpers/icons';
|
|
5
|
-
export * from './src/models/environment';
|
|
6
|
-
export * from './src/models/generated';
|
|
7
|
-
export * from './src/models/properties';
|
|
8
|
-
export * from './src/models/renderer';
|
|
9
|
-
export {
|
|
1
|
+
export * from './src/helpers/dictionary-watcher';
|
|
2
|
+
export * from './src/helpers/hooks/use-globals';
|
|
3
|
+
export * from './src/helpers/hooks/use-reactive-value';
|
|
4
|
+
export * from './src/helpers/icons';
|
|
5
|
+
export * from './src/models/environment';
|
|
6
|
+
export * from './src/models/generated';
|
|
7
|
+
export * from './src/models/properties';
|
|
8
|
+
export * from './src/models/renderer';
|
|
9
|
+
export { Renderer, batchedUpdates, flushSync, render, batchedUpdates as unstable_batchedUpdates } from './src/renderer/renderer';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './src/helpers/dictionary-watcher';
|
|
2
|
-
export * from './src/helpers/hooks/use-globals';
|
|
3
|
-
export * from './src/helpers/hooks/use-reactive-value';
|
|
4
|
-
export * from './src/helpers/icons';
|
|
5
|
-
export * from './src/models/environment';
|
|
6
|
-
export * from './src/models/generated';
|
|
7
|
-
export * from './src/models/properties';
|
|
8
|
-
export * from './src/models/renderer';
|
|
9
|
-
export {
|
|
1
|
+
export * from './src/helpers/dictionary-watcher';
|
|
2
|
+
export * from './src/helpers/hooks/use-globals';
|
|
3
|
+
export * from './src/helpers/hooks/use-reactive-value';
|
|
4
|
+
export * from './src/helpers/icons';
|
|
5
|
+
export * from './src/models/environment';
|
|
6
|
+
export * from './src/models/generated';
|
|
7
|
+
export * from './src/models/properties';
|
|
8
|
+
export * from './src/models/renderer';
|
|
9
|
+
export { Renderer, batchedUpdates, flushSync, render, batchedUpdates as unstable_batchedUpdates } from './src/renderer/renderer';
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { ReactUnity } from '../models/generated';
|
|
2
|
-
export interface DictionaryWatcher<T = Record<string, any>> {
|
|
3
|
-
/** React Context that provides the value */
|
|
4
|
-
context: React.Context<T>;
|
|
5
|
-
/**
|
|
6
|
-
* The provider component that should be used to wrap the components where this context will be used
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
*
|
|
10
|
-
* ```tsx
|
|
11
|
-
* <watcher.Provider>
|
|
12
|
-
* <App />
|
|
13
|
-
* </watcher.Provider>
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
Provider: (props: {
|
|
17
|
-
children?: React.ReactNode;
|
|
18
|
-
}) => React.FunctionComponentElement<React.ProviderProps<T>>;
|
|
19
|
-
/**
|
|
20
|
-
* React Hook for getting the value from Context
|
|
21
|
-
*
|
|
22
|
-
* Usage:
|
|
23
|
-
*
|
|
24
|
-
* ```tsx
|
|
25
|
-
* function App() {
|
|
26
|
-
* const values = watcher.useContext();
|
|
27
|
-
* ...
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
useContext: () => T;
|
|
32
|
-
/**
|
|
33
|
-
* React Hook for getting the value of this Dictionary. This one will subscribe only to the properties that are accessed.
|
|
34
|
-
*
|
|
35
|
-
* Usage:
|
|
36
|
-
*
|
|
37
|
-
* ```tsx
|
|
38
|
-
* function App() {
|
|
39
|
-
* const { a, b } = watcher.useValue();
|
|
40
|
-
* ...
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
useValue: (subscribeToAllFields?: boolean, isEqual?: IsEqual) => T;
|
|
45
|
-
/**
|
|
46
|
-
* React Hook for getting a partial value from Context
|
|
47
|
-
*
|
|
48
|
-
* Usage:
|
|
49
|
-
*
|
|
50
|
-
* ```tsx
|
|
51
|
-
* function App() {
|
|
52
|
-
* const count = watcher.useSelector(st => st.count);
|
|
53
|
-
* ...
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
useSelector<Res>(selector: (store: T) => Res, isEqual?: IsEqual<Res>): Res;
|
|
58
|
-
}
|
|
59
|
-
type IsEqual<T = any> = (a: T, b: T) => boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Creates a context that updates its value when the values in the dictionary change
|
|
62
|
-
* @param dictionary The dictionary to be watched. Must implement the EventDictionary type in the C#
|
|
63
|
-
* @param displayName A displayName to identify this context easier in case of problems
|
|
64
|
-
*/
|
|
65
|
-
export declare function createDictionaryWatcher<ValueType = any, RecordType = Record<string, ValueType>>(dictionary: ReactUnity.Reactive.ReactiveRecord<ValueType>, displayName?: string): DictionaryWatcher<RecordType>;
|
|
66
|
-
export {};
|
|
1
|
+
import { ReactUnity } from '../models/generated';
|
|
2
|
+
export interface DictionaryWatcher<T = Record<string, any>> {
|
|
3
|
+
/** React Context that provides the value */
|
|
4
|
+
context: React.Context<T>;
|
|
5
|
+
/**
|
|
6
|
+
* The provider component that should be used to wrap the components where this context will be used
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <watcher.Provider>
|
|
12
|
+
* <App />
|
|
13
|
+
* </watcher.Provider>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
Provider: (props: {
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
}) => React.FunctionComponentElement<React.ProviderProps<T>>;
|
|
19
|
+
/**
|
|
20
|
+
* React Hook for getting the value from Context
|
|
21
|
+
*
|
|
22
|
+
* Usage:
|
|
23
|
+
*
|
|
24
|
+
* ```tsx
|
|
25
|
+
* function App() {
|
|
26
|
+
* const values = watcher.useContext();
|
|
27
|
+
* ...
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
useContext: () => T;
|
|
32
|
+
/**
|
|
33
|
+
* React Hook for getting the value of this Dictionary. This one will subscribe only to the properties that are accessed.
|
|
34
|
+
*
|
|
35
|
+
* Usage:
|
|
36
|
+
*
|
|
37
|
+
* ```tsx
|
|
38
|
+
* function App() {
|
|
39
|
+
* const { a, b } = watcher.useValue();
|
|
40
|
+
* ...
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
useValue: (subscribeToAllFields?: boolean, isEqual?: IsEqual) => T;
|
|
45
|
+
/**
|
|
46
|
+
* React Hook for getting a partial value from Context
|
|
47
|
+
*
|
|
48
|
+
* Usage:
|
|
49
|
+
*
|
|
50
|
+
* ```tsx
|
|
51
|
+
* function App() {
|
|
52
|
+
* const count = watcher.useSelector(st => st.count);
|
|
53
|
+
* ...
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
useSelector<Res>(selector: (store: T) => Res, isEqual?: IsEqual<Res>): Res;
|
|
58
|
+
}
|
|
59
|
+
type IsEqual<T = any> = (a: T, b: T) => boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a context that updates its value when the values in the dictionary change
|
|
62
|
+
* @param dictionary The dictionary to be watched. Must implement the EventDictionary type in the C#
|
|
63
|
+
* @param displayName A displayName to identify this context easier in case of problems
|
|
64
|
+
*/
|
|
65
|
+
export declare function createDictionaryWatcher<ValueType = any, RecordType = Record<string, ValueType>>(dictionary: ReactUnity.Reactive.ReactiveRecord<ValueType>, displayName?: string): DictionaryWatcher<RecordType>;
|
|
66
|
+
export {};
|
|
@@ -1,98 +1,100 @@
|
|
|
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 { createContext, createElement, useContext, useMemo, useState } from 'react';
|
|
13
|
-
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
14
|
-
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';
|
|
15
|
-
/**
|
|
16
|
-
* Creates a context that updates its value when the values in the dictionary change
|
|
17
|
-
* @param dictionary The dictionary to be watched. Must implement the EventDictionary type in the C#
|
|
18
|
-
* @param displayName A displayName to identify this context easier in case of problems
|
|
19
|
-
*/
|
|
20
|
-
export function createDictionaryWatcher(dictionary, displayName) {
|
|
21
|
-
var ctx = createContext(undefined);
|
|
22
|
-
if (displayName)
|
|
23
|
-
ctx.displayName = displayName;
|
|
24
|
-
var createSubscriber = function (fields, isEqual) {
|
|
25
|
-
var snapshot = (__assign({}, dictionary));
|
|
26
|
-
return {
|
|
27
|
-
subscribe: function (onStoreChange) {
|
|
28
|
-
snapshot = (__assign({}, dictionary));
|
|
29
|
-
var remove = dictionary === null || dictionary === void 0 ? void 0 : dictionary.AddListener(function () {
|
|
30
|
-
var prev = snapshot;
|
|
31
|
-
snapshot = (__assign({}, dictionary));
|
|
32
|
-
if (!fields)
|
|
33
|
-
onStoreChange();
|
|
34
|
-
else {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
var
|
|
76
|
-
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
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 { createContext, createElement, useContext, useMemo, useRef, useState } from 'react';
|
|
13
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
14
|
+
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';
|
|
15
|
+
/**
|
|
16
|
+
* Creates a context that updates its value when the values in the dictionary change
|
|
17
|
+
* @param dictionary The dictionary to be watched. Must implement the EventDictionary type in the C#
|
|
18
|
+
* @param displayName A displayName to identify this context easier in case of problems
|
|
19
|
+
*/
|
|
20
|
+
export function createDictionaryWatcher(dictionary, displayName) {
|
|
21
|
+
var ctx = createContext(undefined);
|
|
22
|
+
if (displayName)
|
|
23
|
+
ctx.displayName = displayName;
|
|
24
|
+
var createSubscriber = function (fields, isEqual) {
|
|
25
|
+
var snapshot = (__assign({}, dictionary));
|
|
26
|
+
return {
|
|
27
|
+
subscribe: function (onStoreChange) {
|
|
28
|
+
snapshot = (__assign({}, dictionary));
|
|
29
|
+
var remove = dictionary === null || dictionary === void 0 ? void 0 : dictionary.AddListener(function () {
|
|
30
|
+
var prev = snapshot;
|
|
31
|
+
snapshot = (__assign({}, dictionary));
|
|
32
|
+
if (!fields)
|
|
33
|
+
onStoreChange();
|
|
34
|
+
else {
|
|
35
|
+
var it = fields.values();
|
|
36
|
+
for (var field = it.next().value; field; field = it.next().value) {
|
|
37
|
+
if (isEqual ? !isEqual(prev[field], snapshot[field]) : (prev[field] !== snapshot[field])) {
|
|
38
|
+
onStoreChange();
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
if (!remove) {
|
|
45
|
+
if (displayName)
|
|
46
|
+
console.warn("".concat(displayName, " dictionary does not provide a change listener"));
|
|
47
|
+
else
|
|
48
|
+
console.warn('The dictionary does not provide a change listener');
|
|
49
|
+
}
|
|
50
|
+
return function () { return remove === null || remove === void 0 ? void 0 : remove(); };
|
|
51
|
+
},
|
|
52
|
+
getSnapshot: function () { return snapshot; },
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
var defaultSubscriber = createSubscriber();
|
|
56
|
+
var Provider = function GlobalsProvider(_a) {
|
|
57
|
+
var children = _a.children;
|
|
58
|
+
var value = useSyncExternalStore(defaultSubscriber.subscribe, defaultSubscriber.getSnapshot, defaultSubscriber.getSnapshot);
|
|
59
|
+
return createElement(ctx.Provider, { value: value }, children);
|
|
60
|
+
};
|
|
61
|
+
function useDictionaryContext() {
|
|
62
|
+
var context = useContext(ctx);
|
|
63
|
+
if (context === undefined) {
|
|
64
|
+
if (displayName)
|
|
65
|
+
throw new Error("".concat(displayName, ".useContext must be used within a ").concat(displayName, ".Provider"));
|
|
66
|
+
else
|
|
67
|
+
throw new Error('useContext must be used within a provider');
|
|
68
|
+
}
|
|
69
|
+
return context;
|
|
70
|
+
}
|
|
71
|
+
function useValue(subscribeToAllFields, fieldEqual) {
|
|
72
|
+
if (subscribeToAllFields === void 0) { subscribeToAllFields = false; }
|
|
73
|
+
var fields = useMemo(function () { return new Set(); }, []);
|
|
74
|
+
var fieldsRef = useRef(fields);
|
|
75
|
+
var _a = useState(false), allFieldsSubscribed = _a[0], setAllFieldsSubscribed = _a[1];
|
|
76
|
+
subscribeToAllFields || (subscribeToAllFields = allFieldsSubscribed);
|
|
77
|
+
var subscriber = useMemo(function () { return subscribeToAllFields ? defaultSubscriber : createSubscriber(fieldsRef.current, fieldEqual); }, [subscribeToAllFields, fieldEqual]);
|
|
78
|
+
var value = useSyncExternalStore(subscriber.subscribe, subscriber.getSnapshot, subscriber.getSnapshot);
|
|
79
|
+
var proxy = new Proxy(value, {
|
|
80
|
+
get: function (target, p, receiver) {
|
|
81
|
+
fields.add(p);
|
|
82
|
+
return value[p];
|
|
83
|
+
},
|
|
84
|
+
ownKeys: function (target) {
|
|
85
|
+
if (!allFieldsSubscribed)
|
|
86
|
+
setAllFieldsSubscribed(true);
|
|
87
|
+
return Reflect.ownKeys(target);
|
|
88
|
+
},
|
|
89
|
+
getOwnPropertyDescriptor: function (target, p) {
|
|
90
|
+
fields.add(p);
|
|
91
|
+
return __assign(__assign({}, Reflect.getOwnPropertyDescriptor(target, p)), { value: value[p] });
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
return proxy;
|
|
95
|
+
}
|
|
96
|
+
function useSelector(selector, isEqual) {
|
|
97
|
+
return useSyncExternalStoreWithSelector(defaultSubscriber.subscribe, defaultSubscriber.getSnapshot, defaultSubscriber.getSnapshot, selector, isEqual);
|
|
98
|
+
}
|
|
99
|
+
return { context: ctx, Provider: Provider, useValue: useValue, useContext: useDictionaryContext, useSelector: useSelector };
|
|
100
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const useGlobals: (subscribeToAllFields?: boolean, isEqual?: (a: any, b: any) => boolean) => DefaultGlobals;
|
|
2
|
-
export declare const useGlobalsContext: () => DefaultGlobals;
|
|
3
|
-
export declare const useGlobalsSelector: <Res>(selector: (store: DefaultGlobals) => Res, isEqual?: (a: Res, b: Res) => boolean) => Res;
|
|
4
|
-
export declare const GlobalsProvider: (props: {
|
|
5
|
-
children?: import("react").ReactNode;
|
|
6
|
-
}) => import("react").FunctionComponentElement<import("react").ProviderProps<DefaultGlobals>>;
|
|
1
|
+
export declare const useGlobals: (subscribeToAllFields?: boolean, isEqual?: (a: any, b: any) => boolean) => DefaultGlobals;
|
|
2
|
+
export declare const useGlobalsContext: () => DefaultGlobals;
|
|
3
|
+
export declare const useGlobalsSelector: <Res>(selector: (store: DefaultGlobals) => Res, isEqual?: (a: Res, b: Res) => boolean) => Res;
|
|
4
|
+
export declare const GlobalsProvider: (props: {
|
|
5
|
+
children?: import("react").ReactNode;
|
|
6
|
+
}) => import("react").FunctionComponentElement<import("react").ProviderProps<DefaultGlobals>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createDictionaryWatcher } from
|
|
2
|
-
var globalsWatcher = createDictionaryWatcher(Globals, 'globalsContext');
|
|
3
|
-
export var useGlobals = globalsWatcher.useValue;
|
|
4
|
-
export var useGlobalsContext = globalsWatcher.useContext;
|
|
5
|
-
export var useGlobalsSelector = globalsWatcher.useSelector;
|
|
6
|
-
export var GlobalsProvider = globalsWatcher.Provider;
|
|
1
|
+
import { createDictionaryWatcher } from '../dictionary-watcher';
|
|
2
|
+
var globalsWatcher = createDictionaryWatcher(Globals, 'globalsContext');
|
|
3
|
+
export var useGlobals = globalsWatcher.useValue;
|
|
4
|
+
export var useGlobalsContext = globalsWatcher.useContext;
|
|
5
|
+
export var useGlobalsSelector = globalsWatcher.useSelector;
|
|
6
|
+
export var GlobalsProvider = globalsWatcher.Provider;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactUnity } from '../../models/generated';
|
|
2
|
-
type IsEqual<T = any> = (a: T, b: T) => boolean;
|
|
3
|
-
export declare function useReactiveValue<T>(obj: ReactUnity.Reactive.IReactive<T>, isEqual?: IsEqual<T>): T;
|
|
4
|
-
export {};
|
|
1
|
+
import { ReactUnity } from '../../models/generated';
|
|
2
|
+
type IsEqual<T = any> = (a: T, b: T) => boolean;
|
|
3
|
+
export declare function useReactiveValue<T>(obj: ReactUnity.Reactive.IReactive<T>, isEqual?: IsEqual<T>): T;
|
|
4
|
+
export {};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
3
|
-
function createSubscriber(obj, isEqual) {
|
|
4
|
-
var isReactive = obj && typeof obj === 'object' && ('Value' in obj);
|
|
5
|
-
var snapshot = isReactive ? obj.Value : undefined;
|
|
6
|
-
return {
|
|
7
|
-
subscribe: function (onStoreChange) {
|
|
8
|
-
snapshot = isReactive ? obj.Value : undefined;
|
|
9
|
-
var remove = isReactive && typeof obj.AddListener === 'function' &&
|
|
10
|
-
(obj === null || obj === void 0 ? void 0 : obj.AddListener(function () {
|
|
11
|
-
var prev = snapshot;
|
|
12
|
-
snapshot = isReactive ? obj.Value : undefined;
|
|
13
|
-
if (typeof isEqual !== 'function' || !isEqual(prev, snapshot)) {
|
|
14
|
-
onStoreChange();
|
|
15
|
-
}
|
|
16
|
-
}));
|
|
17
|
-
if (isReactive && typeof remove !== 'function')
|
|
18
|
-
console.warn(
|
|
19
|
-
return function () { return remove === null || remove === void 0 ? void 0 : remove(); };
|
|
20
|
-
},
|
|
21
|
-
getSnapshot: function () { return snapshot; },
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export function useReactiveValue(obj, isEqual) {
|
|
25
|
-
var sb = useMemo(function () { return createSubscriber(obj, isEqual); }, [obj, isEqual]);
|
|
26
|
-
return useSyncExternalStore(sb.subscribe, sb.getSnapshot, sb.getSnapshot);
|
|
27
|
-
}
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
3
|
+
function createSubscriber(obj, isEqual) {
|
|
4
|
+
var isReactive = obj && typeof obj === 'object' && ('Value' in obj);
|
|
5
|
+
var snapshot = isReactive ? obj.Value : undefined;
|
|
6
|
+
return {
|
|
7
|
+
subscribe: function (onStoreChange) {
|
|
8
|
+
snapshot = isReactive ? obj.Value : undefined;
|
|
9
|
+
var remove = isReactive && typeof obj.AddListener === 'function' &&
|
|
10
|
+
(obj === null || obj === void 0 ? void 0 : obj.AddListener(function () {
|
|
11
|
+
var prev = snapshot;
|
|
12
|
+
snapshot = isReactive ? obj.Value : undefined;
|
|
13
|
+
if (typeof isEqual !== 'function' || !isEqual(prev, snapshot)) {
|
|
14
|
+
onStoreChange();
|
|
15
|
+
}
|
|
16
|
+
}));
|
|
17
|
+
if (isReactive && typeof remove !== 'function')
|
|
18
|
+
console.warn('The reactive value does not provide a change listener');
|
|
19
|
+
return function () { return remove === null || remove === void 0 ? void 0 : remove(); };
|
|
20
|
+
},
|
|
21
|
+
getSnapshot: function () { return snapshot; },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function useReactiveValue(obj, isEqual) {
|
|
25
|
+
var sb = useMemo(function () { return createSubscriber(obj, isEqual); }, [obj, isEqual]);
|
|
26
|
+
return useSyncExternalStore(sb.subscribe, sb.getSnapshot, sb.getSnapshot);
|
|
27
|
+
}
|