@reactunity/renderer 0.14.6 → 0.15.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './src/helpers/dictionary-watcher';
2
2
  export * from './src/helpers/hooks/use-globals';
3
- export * from './src/helpers/hooks/use-watchable';
3
+ export * from './src/helpers/hooks/use-reactive-value';
4
4
  export * from './src/helpers/icons';
5
5
  export * from './src/models/environment';
6
6
  export * from './src/models/generated';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './src/helpers/dictionary-watcher';
2
2
  export * from './src/helpers/hooks/use-globals';
3
- export * from './src/helpers/hooks/use-watchable';
3
+ export * from './src/helpers/hooks/use-reactive-value';
4
4
  export * from './src/helpers/icons';
5
5
  export * from './src/models/environment';
6
6
  export * from './src/models/generated';
@@ -62,5 +62,5 @@ type IsEqual<T = any> = (a: T, b: T) => boolean;
62
62
  * @param dictionary The dictionary to be watched. Must implement the EventDictionary type in the C#
63
63
  * @param displayName A displayName to identify this context easier in case of problems
64
64
  */
65
- export declare function createDictionaryWatcher<ValueType = any, RecordType = Record<string, ValueType>>(dictionary: ReactUnity.Helpers.WatchableRecord<ValueType>, displayName?: string): DictionaryWatcher<RecordType>;
65
+ export declare function createDictionaryWatcher<ValueType = any, RecordType = Record<string, ValueType>>(dictionary: ReactUnity.Reactive.ReactiveRecord<ValueType>, displayName?: string): DictionaryWatcher<RecordType>;
66
66
  export {};
@@ -1,4 +1,4 @@
1
1
  import { ReactUnity } from '../../models/generated';
2
2
  type IsEqual<T = any> = (a: T, b: T) => boolean;
3
- export declare function useWatchable<T>(obj: ReactUnity.Helpers.IWatchable<T>, isEqual?: IsEqual<T>): T;
3
+ export declare function useReactiveValue<T>(obj: ReactUnity.Reactive.IReactive<T>, isEqual?: IsEqual<T>): T;
4
4
  export {};
@@ -1,27 +1,27 @@
1
1
  import { useMemo } from 'react';
2
2
  import { useSyncExternalStore } from 'use-sync-external-store/shim';
3
3
  function createSubscriber(obj, isEqual) {
4
- var isWatchable = obj && typeof obj === 'object' && ('Value' in obj);
5
- var snapshot = isWatchable ? obj.Value : undefined;
4
+ var isReactive = obj && typeof obj === 'object' && ('Value' in obj);
5
+ var snapshot = isReactive ? obj.Value : undefined;
6
6
  return {
7
7
  subscribe: function (onStoreChange) {
8
- snapshot = isWatchable ? obj.Value : undefined;
9
- var remove = isWatchable && typeof obj.AddListener === 'function' &&
8
+ snapshot = isReactive ? obj.Value : undefined;
9
+ var remove = isReactive && typeof obj.AddListener === 'function' &&
10
10
  (obj === null || obj === void 0 ? void 0 : obj.AddListener(function () {
11
11
  var prev = snapshot;
12
- snapshot = isWatchable ? obj.Value : undefined;
12
+ snapshot = isReactive ? obj.Value : undefined;
13
13
  if (typeof isEqual !== 'function' || !isEqual(prev, snapshot)) {
14
14
  onStoreChange();
15
15
  }
16
16
  }));
17
- if (isWatchable && typeof remove !== 'function')
18
- console.warn("The watchable does not provide a change listener");
17
+ if (isReactive && typeof remove !== 'function')
18
+ console.warn("The reactive value does not provide a change listener");
19
19
  return function () { return remove === null || remove === void 0 ? void 0 : remove(); };
20
20
  },
21
21
  getSnapshot: function () { return snapshot; },
22
22
  };
23
23
  }
24
- export function useWatchable(obj, isEqual) {
24
+ export function useReactiveValue(obj, isEqual) {
25
25
  var sb = useMemo(function () { return createSubscriber(obj, isEqual); }, [obj, isEqual]);
26
26
  return useSyncExternalStore(sb.subscribe, sb.getSnapshot, sb.getSnapshot);
27
27
  }
@@ -18,6 +18,7 @@ export interface EditorElements extends BaseElements<BaseElement<any>> {
18
18
  tag?: string;
19
19
  };
20
20
  box: BaseElement;
21
+ a: Components.Anchor & rc.RefAttributes<Cmp.UIToolkitComponent> & Children;
21
22
  anchor: Components.Anchor & rc.RefAttributes<Cmp.UIToolkitComponent> & Children;
22
23
  text: Components.View & rc.RefAttributes<Cmp.TextComponent> & Children<Textable | Textable[]>;
23
24
  richtext: Components.View & rc.RefAttributes<Cmp.TextComponent> & Children<Textable | Textable[]>;
@@ -77,25 +78,27 @@ export interface EditorElements extends BaseElements<BaseElement<any>> {
77
78
  'tb-spacer': BaseElement;
78
79
  'tb-toggle': BaseElement;
79
80
  }
80
- declare module 'react/jsx-runtime' {
81
+ declare global {
82
+ interface ReactUnityCustomElements {
83
+ }
84
+ interface DefaultComponentProps extends Components.View {
85
+ ref?: React.Ref<ReactUnity.UIToolkit.UIToolkitComponent>;
86
+ }
81
87
  namespace JSX {
82
- interface ElementAttributesProperty {
83
- props: {};
84
- }
85
- interface ElementChildrenAttribute {
86
- children: {};
87
- }
88
- interface IntrinsicAttributes extends React.Attributes {
89
- }
90
- interface IntrinsicClassAttributes<T> extends React.ClassAttributes<T> {
88
+ interface IntrinsicElements extends EditorElements, ReactUnityCustomElements {
91
89
  }
92
- interface IntrinsicElements extends EditorElements {
90
+ }
91
+ }
92
+ declare module 'react' {
93
+ namespace JSX {
94
+ interface IntrinsicElements extends EditorElements, ReactUnityCustomElements {
93
95
  }
94
96
  }
95
97
  }
96
- declare global {
97
- interface DefaultComponentProps extends Components.View {
98
- ref?: React.Ref<ReactUnity.UIToolkit.UIToolkitComponent>;
98
+ declare module 'react/jsx-runtime' {
99
+ namespace JSX {
100
+ interface IntrinsicElements extends EditorElements, ReactUnityCustomElements {
101
+ }
99
102
  }
100
103
  }
101
104
  export {};
@@ -1,3 +1,4 @@
1
+ import { ReactUnity } from '../../generated';
1
2
  import { FormData as TFormData, URL as TURL } from './common';
2
3
  import { fetch as Tfetch } from './fetch';
3
4
  import { XMLHttpRequest as TXHR } from './xhr';
@@ -6,4 +7,5 @@ declare global {
6
7
  var URL: typeof TURL;
7
8
  var fetch: typeof Tfetch;
8
9
  var XMLHttpRequest: typeof TXHR;
10
+ var WebSocket: ReactUnity.Scripting.DomProxies.WebSocketProxy;
9
11
  }
@@ -1,5 +1,6 @@
1
1
  import { ReactUnity } from '../generated';
2
2
  import './dom/global';
3
+ import './jsx';
3
4
  export * from './interop';
4
5
  interface Console {
5
6
  assert(condition?: boolean, ...data: any[]): void;
@@ -34,7 +35,7 @@ declare global {
34
35
  interface DefaultComponentProps {
35
36
  [key: string]: any;
36
37
  }
37
- var Globals: ReactUnity.Helpers.WatchableRecord<any> & DefaultGlobals;
38
+ var Globals: ReactUnity.Reactive.ReactiveRecord<any> & DefaultGlobals;
38
39
  var setImmediate: (callback: () => void) => number;
39
40
  var setTimeout: (callback: () => void, timeout: number) => number;
40
41
  var setInterval: (callback: () => void, timeout: number) => number;
@@ -1,2 +1,3 @@
1
1
  import './dom/global';
2
+ import './jsx';
2
3
  export * from './interop';
@@ -0,0 +1,45 @@
1
+ import { Attributes, ClassAttributes } from 'react';
2
+ declare global {
3
+ interface ReactUnityCustomAttributes {
4
+ }
5
+ namespace JSX {
6
+ interface ElementAttributesProperty {
7
+ props: {};
8
+ }
9
+ interface ElementChildrenAttribute {
10
+ children: {};
11
+ }
12
+ interface IntrinsicAttributes extends Attributes, ReactUnityCustomAttributes {
13
+ }
14
+ interface IntrinsicClassAttributes<T> extends ClassAttributes<T> {
15
+ }
16
+ }
17
+ }
18
+ declare module 'react' {
19
+ namespace JSX {
20
+ interface ElementAttributesProperty {
21
+ props: {};
22
+ }
23
+ interface ElementChildrenAttribute {
24
+ children: {};
25
+ }
26
+ interface IntrinsicAttributes extends React.Attributes, ReactUnityCustomAttributes {
27
+ }
28
+ interface IntrinsicClassAttributes<T> extends React.ClassAttributes<T> {
29
+ }
30
+ }
31
+ }
32
+ declare module 'react/jsx-runtime' {
33
+ namespace JSX {
34
+ interface ElementAttributesProperty {
35
+ props: {};
36
+ }
37
+ interface ElementChildrenAttribute {
38
+ children: {};
39
+ }
40
+ interface IntrinsicAttributes extends React.Attributes, ReactUnityCustomAttributes {
41
+ }
42
+ interface IntrinsicClassAttributes<T> extends React.ClassAttributes<T> {
43
+ }
44
+ }
45
+ }
@@ -0,0 +1 @@
1
+ export {};