dreaction-react-native 1.0.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 (98) hide show
  1. package/lib/components/ConfigDialog.d.ts +9 -0
  2. package/lib/components/ConfigDialog.d.ts.map +1 -0
  3. package/lib/components/ConfigDialog.js +83 -0
  4. package/lib/components/DraggableBall.d.ts +3 -0
  5. package/lib/components/DraggableBall.d.ts.map +1 -0
  6. package/lib/components/DraggableBall.js +136 -0
  7. package/lib/dreaction.d.ts +29 -0
  8. package/lib/dreaction.d.ts.map +1 -0
  9. package/lib/dreaction.js +134 -0
  10. package/lib/helpers/getHost.d.ts +9 -0
  11. package/lib/helpers/getHost.d.ts.map +1 -0
  12. package/lib/helpers/getHost.js +31 -0
  13. package/lib/helpers/getReactNativeDimensions.d.ts +3 -0
  14. package/lib/helpers/getReactNativeDimensions.d.ts.map +1 -0
  15. package/lib/helpers/getReactNativeDimensions.js +18 -0
  16. package/lib/helpers/getReactNativeDimensions.test.d.ts +2 -0
  17. package/lib/helpers/getReactNativeDimensions.test.d.ts.map +1 -0
  18. package/lib/helpers/getReactNativeDimensions.test.js +20 -0
  19. package/lib/helpers/getReactNativeDimensionsWithDimensions.d.ts +12 -0
  20. package/lib/helpers/getReactNativeDimensionsWithDimensions.d.ts.map +1 -0
  21. package/lib/helpers/getReactNativeDimensionsWithDimensions.js +31 -0
  22. package/lib/helpers/getReactNativePlatformConstants.d.ts +13 -0
  23. package/lib/helpers/getReactNativePlatformConstants.d.ts.map +1 -0
  24. package/lib/helpers/getReactNativePlatformConstants.js +37 -0
  25. package/lib/helpers/getReactNativeVersion.d.ts +2 -0
  26. package/lib/helpers/getReactNativeVersion.d.ts.map +1 -0
  27. package/lib/helpers/getReactNativeVersion.js +8 -0
  28. package/lib/helpers/getReactNativeVersion.test.d.ts +2 -0
  29. package/lib/helpers/getReactNativeVersion.test.d.ts.map +1 -0
  30. package/lib/helpers/getReactNativeVersion.test.js +19 -0
  31. package/lib/helpers/getReactNativeVersionWithModules.d.ts +3 -0
  32. package/lib/helpers/getReactNativeVersionWithModules.d.ts.map +1 -0
  33. package/lib/helpers/getReactNativeVersionWithModules.js +32 -0
  34. package/lib/helpers/parseErrorStack.d.ts +5 -0
  35. package/lib/helpers/parseErrorStack.d.ts.map +1 -0
  36. package/lib/helpers/parseErrorStack.js +2 -0
  37. package/lib/helpers/parseURL.d.ts +9 -0
  38. package/lib/helpers/parseURL.d.ts.map +1 -0
  39. package/lib/helpers/parseURL.js +21 -0
  40. package/lib/helpers/parseURL.test.d.ts +2 -0
  41. package/lib/helpers/parseURL.test.d.ts.map +1 -0
  42. package/lib/helpers/parseURL.test.js +61 -0
  43. package/lib/helpers/symbolicateStackTrace.d.ts +18 -0
  44. package/lib/helpers/symbolicateStackTrace.d.ts.map +1 -0
  45. package/lib/helpers/symbolicateStackTrace.js +2 -0
  46. package/lib/index.d.ts +5 -0
  47. package/lib/index.d.ts.map +1 -0
  48. package/lib/index.js +20 -0
  49. package/lib/plugins/asyncStorage.d.ts +12 -0
  50. package/lib/plugins/asyncStorage.d.ts.map +1 -0
  51. package/lib/plugins/asyncStorage.js +173 -0
  52. package/lib/plugins/devTools.d.ts +3 -0
  53. package/lib/plugins/devTools.d.ts.map +1 -0
  54. package/lib/plugins/devTools.js +24 -0
  55. package/lib/plugins/networking.d.ts +10 -0
  56. package/lib/plugins/networking.d.ts.map +1 -0
  57. package/lib/plugins/networking.js +139 -0
  58. package/lib/plugins/openInEditor.d.ts +9 -0
  59. package/lib/plugins/openInEditor.d.ts.map +1 -0
  60. package/lib/plugins/openInEditor.js +21 -0
  61. package/lib/plugins/overlay/index.d.ts +3 -0
  62. package/lib/plugins/overlay/index.d.ts.map +1 -0
  63. package/lib/plugins/overlay/index.js +29 -0
  64. package/lib/plugins/overlay/overlay.d.ts +161 -0
  65. package/lib/plugins/overlay/overlay.d.ts.map +1 -0
  66. package/lib/plugins/overlay/overlay.js +99 -0
  67. package/lib/plugins/storybook/index.d.ts +6 -0
  68. package/lib/plugins/storybook/index.d.ts.map +1 -0
  69. package/lib/plugins/storybook/index.js +27 -0
  70. package/lib/plugins/storybook/storybook.d.ts +22 -0
  71. package/lib/plugins/storybook/storybook.d.ts.map +1 -0
  72. package/lib/plugins/storybook/storybook.js +31 -0
  73. package/lib/plugins/trackGlobalErrors.d.ts +32 -0
  74. package/lib/plugins/trackGlobalErrors.d.ts.map +1 -0
  75. package/lib/plugins/trackGlobalErrors.js +100 -0
  76. package/lib/plugins/trackGlobalLogs.d.ts +9 -0
  77. package/lib/plugins/trackGlobalLogs.d.ts.map +1 -0
  78. package/lib/plugins/trackGlobalLogs.js +31 -0
  79. package/package.json +29 -0
  80. package/src/components/ConfigDialog.tsx +79 -0
  81. package/src/components/DraggableBall.tsx +139 -0
  82. package/src/dreaction.ts +221 -0
  83. package/src/helpers/getHost.ts +30 -0
  84. package/src/helpers/getReactNativeDimensions.ts +20 -0
  85. package/src/helpers/getReactNativeDimensionsWithDimensions.ts +45 -0
  86. package/src/helpers/getReactNativePlatformConstants.ts +52 -0
  87. package/src/helpers/getReactNativeVersion.ts +6 -0
  88. package/src/helpers/getReactNativeVersionWithModules.ts +37 -0
  89. package/src/helpers/parseErrorStack.ts +13 -0
  90. package/src/helpers/parseURL.ts +19 -0
  91. package/src/helpers/symbolicateStackTrace.ts +28 -0
  92. package/src/index.ts +6 -0
  93. package/src/plugins/asyncStorage.ts +222 -0
  94. package/src/plugins/devTools.ts +30 -0
  95. package/src/plugins/networking.ts +172 -0
  96. package/src/plugins/openInEditor.ts +30 -0
  97. package/src/plugins/trackGlobalErrors.ts +156 -0
  98. package/src/plugins/trackGlobalLogs.ts +42 -0
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ interface ConfigDialogProps {
3
+ visible: boolean;
4
+ onConfirm: (value: string) => void;
5
+ onCancel: () => void;
6
+ }
7
+ export declare const ConfigDialog: React.FC<ConfigDialogProps>;
8
+ export {};
9
+ //# sourceMappingURL=ConfigDialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigDialog.d.ts","sourceRoot":"","sources":["../../src/components/ConfigDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAIxC,UAAU,iBAAiB;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AACD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAiCnD,CAAC"}
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ConfigDialog = void 0;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_1 = __importStar(require("react"));
39
+ const react_native_1 = require("react-native");
40
+ const getHost_1 = require("../helpers/getHost");
41
+ exports.ConfigDialog = react_1.default.memo((props) => {
42
+ const { visible, onConfirm, onCancel } = props;
43
+ const [inputValue, setInputValue] = (0, react_1.useState)((0, getHost_1.getHost)());
44
+ const handleConfirm = () => {
45
+ onConfirm(inputValue);
46
+ };
47
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { animationType: "fade", transparent: true, visible: visible, onRequestClose: () => onCancel(), children: (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.modalOverlay, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.modalContent, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.title, children: "DReaction Desktop Application Url" }), (0, jsx_runtime_1.jsx)(react_native_1.TextInput, { style: styles.input, value: inputValue, keyboardType: "url", onChangeText: setInputValue, placeholder: (0, getHost_1.getHost)() }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.buttonContainer, children: [(0, jsx_runtime_1.jsx)(react_native_1.Button, { title: "Cancel", onPress: onCancel }), (0, jsx_runtime_1.jsx)(react_native_1.Button, { title: "Confirm", onPress: handleConfirm })] })] }) }) }));
48
+ });
49
+ exports.ConfigDialog.displayName = 'ConfigDialog';
50
+ const styles = react_native_1.StyleSheet.create({
51
+ container: {
52
+ flex: 1,
53
+ justifyContent: 'center',
54
+ alignItems: 'center',
55
+ },
56
+ modalOverlay: {
57
+ flex: 1,
58
+ justifyContent: 'center',
59
+ backgroundColor: 'rgba(0, 0, 0, 0.5)',
60
+ },
61
+ modalContent: {
62
+ backgroundColor: 'white',
63
+ marginHorizontal: 20,
64
+ borderRadius: 10,
65
+ padding: 20,
66
+ },
67
+ title: {
68
+ fontSize: 18,
69
+ marginBottom: 10,
70
+ textAlign: 'center',
71
+ },
72
+ input: {
73
+ borderWidth: 1,
74
+ borderColor: '#ccc',
75
+ borderRadius: 5,
76
+ padding: 10,
77
+ marginBottom: 20,
78
+ },
79
+ buttonContainer: {
80
+ flexDirection: 'row',
81
+ justifyContent: 'space-around',
82
+ },
83
+ });
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ export declare const DraggableBall: React.FC;
3
+ //# sourceMappingURL=DraggableBall.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DraggableBall.d.ts","sourceRoot":"","sources":["../../src/components/DraggableBall.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAsBhD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAgGhC,CAAC"}
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.DraggableBall = void 0;
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_1 = __importStar(require("react"));
39
+ const react_native_1 = require("react-native");
40
+ const ConfigDialog_1 = require("./ConfigDialog");
41
+ const dreaction_1 = require("../dreaction");
42
+ const getHost_1 = require("../helpers/getHost");
43
+ const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = react_native_1.Dimensions.get('window');
44
+ const BALL_SIZE = 60;
45
+ const CLICK_THRESHOLD = 5;
46
+ const initialPosition = {
47
+ x: SCREEN_WIDTH - BALL_SIZE,
48
+ y: SCREEN_HEIGHT - BALL_SIZE - 100,
49
+ };
50
+ exports.DraggableBall = react_1.default.memo(() => {
51
+ const position = (0, react_1.useRef)(new react_native_1.Animated.ValueXY(initialPosition)).current;
52
+ const lastPosition = (0, react_1.useRef)(initialPosition);
53
+ const [isDragging, setIsDragging] = (0, react_1.useState)(false);
54
+ const [modalVisible, setModalVisible] = (0, react_1.useState)(false);
55
+ const handleClick = (value) => {
56
+ try {
57
+ const host = (0, getHost_1.getHost)(value);
58
+ dreaction_1.dreaction
59
+ .configure({
60
+ host,
61
+ })
62
+ .close()
63
+ .connect();
64
+ setModalVisible(false);
65
+ }
66
+ catch (e) {
67
+ react_native_1.Alert.alert('Connected Failed', 'Please check your url');
68
+ }
69
+ };
70
+ const panResponder = (0, react_1.useRef)(react_native_1.PanResponder.create({
71
+ onStartShouldSetPanResponder: () => true,
72
+ onPanResponderGrant: () => {
73
+ setIsDragging(true);
74
+ position.stopAnimation();
75
+ },
76
+ onPanResponderMove: (_, gestureState) => {
77
+ // 使用 lastPosition 计算位置
78
+ position.setValue({
79
+ x: lastPosition.current.x + gestureState.dx,
80
+ y: lastPosition.current.y + gestureState.dy,
81
+ });
82
+ },
83
+ onPanResponderRelease: (_, gestureState) => {
84
+ setIsDragging(false);
85
+ lastPosition.current = {
86
+ x: lastPosition.current.x + gestureState.dx,
87
+ y: lastPosition.current.y + gestureState.dy,
88
+ };
89
+ if (Math.abs(gestureState.dx) < CLICK_THRESHOLD &&
90
+ Math.abs(gestureState.dy) < CLICK_THRESHOLD) {
91
+ setModalVisible(true);
92
+ return;
93
+ }
94
+ const { moveX, moveY } = gestureState;
95
+ // Calculate adsorption to the nearest edge
96
+ let newX = moveX <= SCREEN_WIDTH / 2 ? 0 : SCREEN_WIDTH - BALL_SIZE; // Adsorb to the left or right
97
+ let newY = Math.min(Math.max(moveY, 0), // Limit the top boundary
98
+ SCREEN_HEIGHT - BALL_SIZE // Limit the bottom boundary
99
+ );
100
+ // Animation
101
+ react_native_1.Animated.spring(position, {
102
+ toValue: { x: newX, y: newY },
103
+ useNativeDriver: false,
104
+ friction: 5,
105
+ }).start(() => {
106
+ lastPosition.current = { x: newX, y: newY };
107
+ });
108
+ },
109
+ })).current;
110
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_native_1.Animated.View, { style: [
111
+ styles.ball,
112
+ {
113
+ transform: [{ translateX: position.x }, { translateY: position.y }],
114
+ backgroundColor: isDragging ? '#eee' : '#fff',
115
+ },
116
+ ], ...panResponder.panHandlers, children: (0, jsx_runtime_1.jsx)(react_native_1.Image, { style: styles.icon, source: require('../../assets/icon.png') }) }), (0, jsx_runtime_1.jsx)(ConfigDialog_1.ConfigDialog, { visible: modalVisible, onCancel: () => setModalVisible(false), onConfirm: handleClick })] }));
117
+ });
118
+ exports.DraggableBall.displayName = 'DraggableBall';
119
+ const styles = react_native_1.StyleSheet.create({
120
+ ball: {
121
+ width: BALL_SIZE,
122
+ height: BALL_SIZE,
123
+ borderRadius: BALL_SIZE / 2,
124
+ position: 'absolute',
125
+ overflow: 'hidden',
126
+ borderWidth: 1,
127
+ borderColor: '#eee',
128
+ justifyContent: 'center',
129
+ alignItems: 'center',
130
+ backgroundColor: '#fff',
131
+ },
132
+ icon: {
133
+ width: BALL_SIZE * 0.8,
134
+ height: BALL_SIZE * 0.8,
135
+ },
136
+ });
@@ -0,0 +1,29 @@
1
+ import type { ClientOptions, InferFeaturesFromPlugins, Reactotron, DReactionCore } from 'dreaction-client-core';
2
+ import type { AsyncStorageStatic } from '@react-native-async-storage/async-storage';
3
+ import { AsyncStorageOptions } from './plugins/asyncStorage';
4
+ import { OpenInEditorOptions } from './plugins/openInEditor';
5
+ import { TrackGlobalErrorsOptions } from './plugins/trackGlobalErrors';
6
+ import { NetworkingOptions } from './plugins/networking';
7
+ import { DataWatchPayload } from 'dreaction-protocol';
8
+ export type { ClientOptions };
9
+ export declare const reactNativeCorePlugins: any[];
10
+ export interface UseReactNativeOptions {
11
+ errors?: TrackGlobalErrorsOptions | boolean;
12
+ log?: boolean;
13
+ editor?: OpenInEditorOptions | boolean;
14
+ asyncStorage?: AsyncStorageOptions | boolean;
15
+ networking?: NetworkingOptions | boolean;
16
+ devTools?: boolean;
17
+ }
18
+ type ReactNativePluginFeatures = InferFeaturesFromPlugins<DReactionCore, typeof reactNativeCorePlugins>;
19
+ export interface ReactotronReactNative extends Reactotron, ReactNativePluginFeatures {
20
+ useReactNative: (options?: UseReactNativeOptions) => this;
21
+ asyncStorageHandler?: AsyncStorageStatic;
22
+ setAsyncStorageHandler: (asyncStorage: AsyncStorageStatic) => this;
23
+ registerDataWatcher: (name: string, type: DataWatchPayload['type']) => {
24
+ updateDebugValue: (data: unknown) => void;
25
+ useDebugDataWatch: (target: unknown) => void;
26
+ };
27
+ }
28
+ export declare const dreaction: ReactotronReactNative;
29
+ //# sourceMappingURL=dreaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dreaction.d.ts","sourceRoot":"","sources":["../src/dreaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EAExB,UAAU,EACV,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAC;AAGpF,OAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAA0B,EACxB,wBAAwB,EACzB,MAAM,6BAA6B,CAAC;AACrC,OAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAItD,YAAY,EAAE,aAAa,EAAE,CAAC;AAM9B,eAAO,MAAM,sBAAsB,OAOO,CAAC;AAE3C,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC;IAC5C,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC;IACvC,YAAY,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC;IAC7C,UAAU,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,KAAK,yBAAyB,GAAG,wBAAwB,CACvD,aAAa,EACb,OAAO,sBAAsB,CAC9B,CAAC;AAEF,MAAM,WAAW,qBACf,SAAQ,UAAU,EAEhB,yBAAyB;IAC3B,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC1D,mBAAmB,CAAC,EAAE,kBAAkB,CAAC;IACzC,sBAAsB,EAAE,CAAC,YAAY,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACnE,mBAAmB,EAAE,CACnB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,gBAAgB,CAAC,MAAM,CAAC,KAC3B;QACH,gBAAgB,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;QAC1C,iBAAiB,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;KAC9C,CAAC;CACH;AAkFD,eAAO,MAAM,SAAS,uBAAgD,CAAC"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.dreaction = exports.reactNativeCorePlugins = void 0;
7
+ const react_native_1 = require("react-native");
8
+ const dreaction_client_core_1 = require("dreaction-client-core");
9
+ const getReactNativeVersion_1 = __importDefault(require("./helpers/getReactNativeVersion"));
10
+ const getReactNativeDimensions_1 = __importDefault(require("./helpers/getReactNativeDimensions"));
11
+ const asyncStorage_1 = __importDefault(require("./plugins/asyncStorage"));
12
+ const openInEditor_1 = __importDefault(require("./plugins/openInEditor"));
13
+ const trackGlobalErrors_1 = __importDefault(require("./plugins/trackGlobalErrors"));
14
+ const networking_1 = __importDefault(require("./plugins/networking"));
15
+ const devTools_1 = __importDefault(require("./plugins/devTools"));
16
+ const trackGlobalLogs_1 = __importDefault(require("./plugins/trackGlobalLogs"));
17
+ const getReactNativePlatformConstants_1 = __importDefault(require("./helpers/getReactNativePlatformConstants"));
18
+ const react_1 = require("react");
19
+ const getHost_1 = require("./helpers/getHost");
20
+ const DREACTION_ASYNC_CLIENT_ID = '@REACTOTRON/clientId';
21
+ let tempClientId = null;
22
+ exports.reactNativeCorePlugins = [
23
+ (0, asyncStorage_1.default)(),
24
+ (0, trackGlobalErrors_1.default)(),
25
+ (0, trackGlobalLogs_1.default)(),
26
+ (0, openInEditor_1.default)(),
27
+ (0, networking_1.default)(),
28
+ (0, devTools_1.default)(),
29
+ ];
30
+ const { osRelease, model, serverHost, forceTouch, interfaceIdiom, systemName, uiMode, serial, } = (0, getReactNativePlatformConstants_1.default)();
31
+ const DEFAULTS = {
32
+ createSocket: (path) => new WebSocket(path), // eslint-disable-line
33
+ host: (0, getHost_1.getHost)('localhost'),
34
+ port: 9600,
35
+ name: 'React Native App',
36
+ environment: process.env.NODE_ENV || (__DEV__ ? 'development' : 'production'),
37
+ client: {
38
+ dreactionLibraryName: 'dreaction-react-native',
39
+ dreactionLibraryVersion: 'DREACTION_REACT_NATIVE_VERSION',
40
+ platform: react_native_1.Platform.OS,
41
+ platformVersion: react_native_1.Platform.Version,
42
+ osRelease,
43
+ model,
44
+ serverHost,
45
+ forceTouch,
46
+ interfaceIdiom,
47
+ systemName,
48
+ uiMode,
49
+ serial,
50
+ reactNativeVersion: (0, getReactNativeVersion_1.default)(),
51
+ ...(0, getReactNativeDimensions_1.default)(),
52
+ },
53
+ /* eslint-disable @typescript-eslint/no-use-before-define */
54
+ getClientId: async (name = '') => {
55
+ if (exports.dreaction.asyncStorageHandler) {
56
+ return (await exports.dreaction.asyncStorageHandler.getItem(DREACTION_ASYNC_CLIENT_ID));
57
+ }
58
+ // Generate clientId based on the device info
59
+ const { screenWidth, screenHeight, screenScale } = (0, getReactNativeDimensions_1.default)();
60
+ // Accounting for screen rotation
61
+ const dimensions = [screenWidth, screenHeight].sort().join('-');
62
+ const additionalInfo = react_native_1.Platform.select({
63
+ ios: systemName,
64
+ android: model,
65
+ default: '',
66
+ });
67
+ tempClientId = [
68
+ name,
69
+ react_native_1.Platform.OS,
70
+ react_native_1.Platform.Version,
71
+ additionalInfo,
72
+ dimensions,
73
+ screenScale,
74
+ ]
75
+ .filter(Boolean)
76
+ .join('-');
77
+ return tempClientId;
78
+ },
79
+ setClientId: async (clientId) => {
80
+ if (exports.dreaction.asyncStorageHandler) {
81
+ return exports.dreaction.asyncStorageHandler.setItem(DREACTION_ASYNC_CLIENT_ID, clientId);
82
+ }
83
+ tempClientId = clientId;
84
+ },
85
+ proxyHack: true,
86
+ };
87
+ exports.dreaction = (0, dreaction_client_core_1.createClient)(DEFAULTS);
88
+ function getPluginOptions(options) {
89
+ return typeof options === 'object' ? options : null;
90
+ }
91
+ exports.dreaction.useReactNative = (options = {}) => {
92
+ if (options.errors !== false) {
93
+ exports.dreaction.use((0, trackGlobalErrors_1.default)(getPluginOptions(options.errors)));
94
+ }
95
+ if (options.log !== false) {
96
+ exports.dreaction.use((0, trackGlobalLogs_1.default)());
97
+ }
98
+ if (options.editor !== false) {
99
+ exports.dreaction.use((0, openInEditor_1.default)(getPluginOptions(options.editor)));
100
+ }
101
+ if (options.asyncStorage !== false) {
102
+ exports.dreaction.use((0, asyncStorage_1.default)(getPluginOptions(options.asyncStorage)));
103
+ }
104
+ if (options.networking !== false) {
105
+ exports.dreaction.use((0, networking_1.default)(getPluginOptions(options.networking)));
106
+ }
107
+ if (options.devTools !== false) {
108
+ exports.dreaction.use((0, devTools_1.default)());
109
+ }
110
+ return exports.dreaction;
111
+ };
112
+ exports.dreaction.setAsyncStorageHandler = (asyncStorage) => {
113
+ exports.dreaction.asyncStorageHandler = asyncStorage;
114
+ return exports.dreaction;
115
+ };
116
+ exports.dreaction.registerDataWatcher = (name, type) => {
117
+ if (!__DEV__) {
118
+ return {
119
+ updateDebugValue: () => { },
120
+ useDebugDataWatch: () => { },
121
+ };
122
+ }
123
+ const updateDebugValue = (data) => {
124
+ exports.dreaction.send('dataWatch', { name, type, data });
125
+ };
126
+ return {
127
+ updateDebugValue,
128
+ useDebugDataWatch: (target) => {
129
+ (0, react_1.useEffect)(() => {
130
+ updateDebugValue(target);
131
+ }, [target]);
132
+ },
133
+ };
134
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Most of the time, host should be 'localhost'.
3
+ * But sometimes, it's not. So we need to figure out what it is.
4
+ * @see https://github.com/infinitered/dreaction/issues/1107
5
+ *
6
+ * On an Android emulator, if you want to connect any servers of local, you will need run adb reverse on your terminal. This function gets the localhost IP of host machine directly to bypass this.
7
+ */
8
+ export declare const getHost: (defaultHost?: string) => string;
9
+ //# sourceMappingURL=getHost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getHost.d.ts","sourceRoot":"","sources":["../../src/helpers/getHost.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,kCAkBnB,CAAC"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getHost = void 0;
7
+ // @ts-ignore
8
+ const NativeSourceCode_1 = __importDefault(require("react-native/Libraries/NativeModules/specs/NativeSourceCode"));
9
+ const parseURL_1 = require("./parseURL");
10
+ /**
11
+ * Most of the time, host should be 'localhost'.
12
+ * But sometimes, it's not. So we need to figure out what it is.
13
+ * @see https://github.com/infinitered/dreaction/issues/1107
14
+ *
15
+ * On an Android emulator, if you want to connect any servers of local, you will need run adb reverse on your terminal. This function gets the localhost IP of host machine directly to bypass this.
16
+ */
17
+ const getHost = (defaultHost = 'localhost') => {
18
+ try {
19
+ // RN Reference: https://github.com/facebook/react-native/blob/main/packages/react-native/src/private/specs/modules/NativeSourceCode.js
20
+ const scriptURL = NativeSourceCode_1.default.getConstants().scriptURL;
21
+ if (typeof scriptURL !== 'string') {
22
+ throw new Error('Invalid non-string URL');
23
+ }
24
+ return (0, parseURL_1.getHostFromUrl)(scriptURL);
25
+ }
26
+ catch (error) {
27
+ console.warn(`getHost: "${error.message}" for scriptURL - Falling back to ${defaultHost}`);
28
+ return defaultHost;
29
+ }
30
+ };
31
+ exports.getHost = getHost;
@@ -0,0 +1,3 @@
1
+ import { AppDimensions } from './getReactNativeDimensionsWithDimensions';
2
+ export default function getReactNativeDimensions(): AppDimensions | null;
3
+ //# sourceMappingURL=getReactNativeDimensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getReactNativeDimensions.d.ts","sourceRoot":"","sources":["../../src/helpers/getReactNativeDimensions.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EAEd,MAAM,0CAA0C,CAAC;AAElD,MAAM,CAAC,OAAO,UAAU,wBAAwB,IAAI,aAAa,GAAG,IAAI,CAavE"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getReactNativeDimensions;
4
+ const react_native_1 = require("react-native");
5
+ const getReactNativeDimensionsWithDimensions_1 = require("./getReactNativeDimensionsWithDimensions");
6
+ function getReactNativeDimensions() {
7
+ let screen = null;
8
+ let win = null;
9
+ try {
10
+ screen = react_native_1.Dimensions.get('screen');
11
+ }
12
+ catch { }
13
+ try {
14
+ win = react_native_1.Dimensions.get('window');
15
+ }
16
+ catch { }
17
+ return (0, getReactNativeDimensionsWithDimensions_1.getReactNativeDimensionsWithDimensions)(screen, win);
18
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=getReactNativeDimensions.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getReactNativeDimensions.test.d.ts","sourceRoot":"","sources":["../../src/helpers/getReactNativeDimensions.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getReactNativeDimensionsWithDimensions_1 = require("./getReactNativeDimensionsWithDimensions");
4
+ describe("getReactNativeDimensions", () => {
5
+ it("should return dimensions", () => {
6
+ const screenDimensions = { width: 10, height: 51, scale: 1, fontScale: 3 };
7
+ const windowDimensions = { width: 10, height: 15, scale: 23, fontScale: 3 };
8
+ const result = (0, getReactNativeDimensionsWithDimensions_1.getReactNativeDimensionsWithDimensions)(screenDimensions, windowDimensions);
9
+ expect(result).toEqual({
10
+ screenWidth: Math.ceil(screenDimensions.width),
11
+ screenHeight: Math.ceil(screenDimensions.height),
12
+ screenScale: screenDimensions.scale,
13
+ screenFontScale: screenDimensions.fontScale,
14
+ windowWidth: Math.ceil(windowDimensions.width),
15
+ windowHeight: Math.ceil(windowDimensions.height),
16
+ windowScale: windowDimensions.scale,
17
+ windowFontScale: windowDimensions.fontScale,
18
+ });
19
+ });
20
+ });
@@ -0,0 +1,12 @@
1
+ export interface AppDimensions {
2
+ screenWidth?: number;
3
+ screenHeight?: number;
4
+ screenScale?: number;
5
+ screenFontScale?: number;
6
+ windowWidth?: number;
7
+ windowHeight?: number;
8
+ windowScale?: number;
9
+ windowFontScale?: number;
10
+ }
11
+ export declare function getReactNativeDimensionsWithDimensions(screen: any, win: any): AppDimensions | null;
12
+ //# sourceMappingURL=getReactNativeDimensionsWithDimensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getReactNativeDimensionsWithDimensions.d.ts","sourceRoot":"","sources":["../../src/helpers/getReactNativeDimensionsWithDimensions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,wBAAgB,sCAAsC,CACpD,MAAM,EAAE,GAAG,EACX,GAAG,EAAE,GAAG,GACP,aAAa,GAAG,IAAI,CA8BtB"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getReactNativeDimensionsWithDimensions = getReactNativeDimensionsWithDimensions;
4
+ function getReactNativeDimensionsWithDimensions(screen, win) {
5
+ try {
6
+ let screenInfo = {};
7
+ let windowInfo = {};
8
+ if (screen) {
9
+ screenInfo = {
10
+ screenWidth: Math.ceil(screen.width),
11
+ screenHeight: Math.ceil(screen.height),
12
+ screenScale: screen.scale,
13
+ screenFontScale: screen.fontScale,
14
+ };
15
+ }
16
+ if (win) {
17
+ windowInfo = {
18
+ windowWidth: Math.ceil(win.width),
19
+ windowHeight: Math.ceil(win.height),
20
+ windowScale: win.scale,
21
+ windowFontScale: win.fontScale,
22
+ };
23
+ }
24
+ return {
25
+ ...screenInfo,
26
+ ...windowInfo,
27
+ };
28
+ }
29
+ catch (e) { }
30
+ return null;
31
+ }
@@ -0,0 +1,13 @@
1
+ interface PlatformConstants {
2
+ osRelease: string;
3
+ model: string;
4
+ serverHost: string;
5
+ uiMode: string;
6
+ serial: string;
7
+ forceTouch: boolean;
8
+ interfaceIdiom: string;
9
+ systemName: string;
10
+ }
11
+ export default function getReactNativePlatformConstants(): PlatformConstants;
12
+ export {};
13
+ //# sourceMappingURL=getReactNativePlatformConstants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getReactNativePlatformConstants.d.ts","sourceRoot":"","sources":["../../src/helpers/getReactNativePlatformConstants.ts"],"names":[],"mappings":"AAMA,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,CAAC,OAAO,UAAU,+BAA+B,IAAI,iBAAiB,CAkC3E"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getReactNativePlatformConstants;
4
+ const react_native_1 = require("react-native");
5
+ function getReactNativePlatformConstants() {
6
+ const defaults = {
7
+ osRelease: '',
8
+ model: '',
9
+ serverHost: '',
10
+ uiMode: '',
11
+ serial: '',
12
+ forceTouch: false,
13
+ interfaceIdiom: '',
14
+ systemName: '',
15
+ };
16
+ if (react_native_1.Platform.OS === 'android') {
17
+ const constants = react_native_1.Platform.constants;
18
+ return {
19
+ ...defaults,
20
+ osRelease: constants.Release,
21
+ model: constants.Model,
22
+ serverHost: constants.ServerHost,
23
+ uiMode: constants.uiMode,
24
+ serial: constants.Serial,
25
+ };
26
+ }
27
+ else if (react_native_1.Platform.OS === 'ios') {
28
+ const constants = react_native_1.Platform.constants;
29
+ return {
30
+ ...defaults,
31
+ forceTouch: constants.forceTouchAvailable || false,
32
+ interfaceIdiom: constants.interfaceIdiom,
33
+ systemName: constants.systemName,
34
+ };
35
+ }
36
+ return defaults;
37
+ }
@@ -0,0 +1,2 @@
1
+ export default function getReactNativeVersion(): string | null;
2
+ //# sourceMappingURL=getReactNativeVersion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getReactNativeVersion.d.ts","sourceRoot":"","sources":["../../src/helpers/getReactNativeVersion.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,qBAAqB,IAAI,MAAM,GAAG,IAAI,CAE7D"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getReactNativeVersion;
4
+ const getReactNativeVersionWithModules_1 = require("./getReactNativeVersionWithModules");
5
+ const react_native_1 = require("react-native");
6
+ function getReactNativeVersion() {
7
+ return (0, getReactNativeVersionWithModules_1.getReactNativeVersionWithModules)(react_native_1.Platform.constants);
8
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=getReactNativeVersion.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getReactNativeVersion.test.d.ts","sourceRoot":"","sources":["../../src/helpers/getReactNativeVersion.test.ts"],"names":[],"mappings":""}