@rork-ai/toolkit-dev-sdk 0.2.6
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/LICENSE +20 -0
- package/README.md +37 -0
- package/lib/module/error-boundary.js +133 -0
- package/lib/module/error-boundary.js.map +1 -0
- package/lib/module/index.js +15 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/safe-insets-content.js +13 -0
- package/lib/module/safe-insets-content.js.map +1 -0
- package/lib/module/safe-insets-content.web.js +61 -0
- package/lib/module/safe-insets-content.web.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/error-boundary.d.ts +20 -0
- package/lib/typescript/src/error-boundary.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/safe-insets-content.d.ts +3 -0
- package/lib/typescript/src/safe-insets-content.d.ts.map +1 -0
- package/lib/typescript/src/safe-insets-content.web.d.ts +3 -0
- package/lib/typescript/src/safe-insets-content.web.d.ts.map +1 -0
- package/package.json +131 -0
- package/src/error-boundary.tsx +161 -0
- package/src/index.tsx +10 -0
- package/src/safe-insets-content.tsx +7 -0
- package/src/safe-insets-content.web.tsx +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Levan Kvirkvelia
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @rork-ai/toolkit-sdk
|
|
2
|
+
|
|
3
|
+
toolkit-sdk
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @rork-ai/toolkit-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { multiply } from '@rork-ai/toolkit-sdk';
|
|
18
|
+
|
|
19
|
+
// ...
|
|
20
|
+
|
|
21
|
+
const result = await multiply(3, 7);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
28
|
+
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
29
|
+
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
MIT
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { requireOptionalNativeModule } from "expo-modules-core";
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { Platform, StyleSheet, Text, View } from "react-native";
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
const IFRAME_ID = "rork-web-preview";
|
|
8
|
+
const webTargetOrigins = ["http://localhost:3000", "https://rorkai.com", "https://rork.com"];
|
|
9
|
+
const BridgeModule = requireOptionalNativeModule("Bridge");
|
|
10
|
+
function sendErrorToIframeParent(error, errorInfo) {
|
|
11
|
+
const errorData = {
|
|
12
|
+
message: error?.message || error?.toString() || "Unknown error",
|
|
13
|
+
stack: error?.stack,
|
|
14
|
+
componentStack: errorInfo?.componentStack,
|
|
15
|
+
timestamp: new Date().toISOString()
|
|
16
|
+
};
|
|
17
|
+
if (Platform.OS === "web" && typeof window !== "undefined") {
|
|
18
|
+
console.debug("Sending error to parent via postMessage:", {
|
|
19
|
+
error,
|
|
20
|
+
errorInfo,
|
|
21
|
+
referrer: document.referrer
|
|
22
|
+
});
|
|
23
|
+
const errorMessage = {
|
|
24
|
+
type: "ERROR",
|
|
25
|
+
error: errorData,
|
|
26
|
+
iframeId: IFRAME_ID
|
|
27
|
+
};
|
|
28
|
+
try {
|
|
29
|
+
window.parent.postMessage(errorMessage, webTargetOrigins.includes(document.referrer) ? document.referrer : "*");
|
|
30
|
+
} catch (postMessageError) {
|
|
31
|
+
console.warn("Failed to send error to parent:", postMessageError);
|
|
32
|
+
}
|
|
33
|
+
} else if (Platform.OS !== "web" && BridgeModule) {
|
|
34
|
+
BridgeModule?.sendMessage({
|
|
35
|
+
type: "runtime-error",
|
|
36
|
+
data: JSON.stringify(errorData)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (Platform.OS === "web" && typeof window !== "undefined") {
|
|
41
|
+
window.addEventListener("error", event => {
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
const errorDetails = event.error ?? {
|
|
44
|
+
message: event.message ?? "Unknown error",
|
|
45
|
+
filename: event.filename ?? "Unknown file",
|
|
46
|
+
lineno: event.lineno ?? "Unknown line",
|
|
47
|
+
colno: event.colno ?? "Unknown column"
|
|
48
|
+
};
|
|
49
|
+
sendErrorToIframeParent(errorDetails);
|
|
50
|
+
}, true);
|
|
51
|
+
window.addEventListener("unhandledrejection", event => {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
sendErrorToIframeParent(event.reason);
|
|
54
|
+
}, true);
|
|
55
|
+
}
|
|
56
|
+
const originalConsoleError = console.error;
|
|
57
|
+
console.error = (...args) => {
|
|
58
|
+
sendErrorToIframeParent(args.join(" "));
|
|
59
|
+
originalConsoleError.apply(console, args);
|
|
60
|
+
};
|
|
61
|
+
export class RorkErrorBoundary extends React.Component {
|
|
62
|
+
constructor(props) {
|
|
63
|
+
super(props);
|
|
64
|
+
this.state = {
|
|
65
|
+
hasError: false,
|
|
66
|
+
error: null
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
static getDerivedStateFromError(error) {
|
|
70
|
+
return {
|
|
71
|
+
hasError: true,
|
|
72
|
+
error
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
componentDidCatch(error, errorInfo) {
|
|
76
|
+
sendErrorToIframeParent(error, errorInfo);
|
|
77
|
+
if (this.props.onError) {
|
|
78
|
+
this.props.onError(error, errorInfo);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
render() {
|
|
82
|
+
if (this.state.hasError) {
|
|
83
|
+
return /*#__PURE__*/_jsx(View, {
|
|
84
|
+
style: styles.container,
|
|
85
|
+
children: /*#__PURE__*/_jsxs(View, {
|
|
86
|
+
style: styles.content,
|
|
87
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
88
|
+
style: styles.title,
|
|
89
|
+
children: "Something went wrong"
|
|
90
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
91
|
+
style: styles.subtitle,
|
|
92
|
+
children: this.state.error?.message
|
|
93
|
+
}), Platform.OS !== "web" && /*#__PURE__*/_jsx(Text, {
|
|
94
|
+
style: styles.description,
|
|
95
|
+
children: "Please check your device logs for more details."
|
|
96
|
+
})]
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return this.props.children;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const styles = StyleSheet.create({
|
|
104
|
+
container: {
|
|
105
|
+
flex: 1,
|
|
106
|
+
backgroundColor: "#fff"
|
|
107
|
+
},
|
|
108
|
+
content: {
|
|
109
|
+
flex: 1,
|
|
110
|
+
alignItems: "center",
|
|
111
|
+
justifyContent: "center",
|
|
112
|
+
padding: 20
|
|
113
|
+
},
|
|
114
|
+
title: {
|
|
115
|
+
fontSize: 36,
|
|
116
|
+
textAlign: "center",
|
|
117
|
+
fontWeight: "bold",
|
|
118
|
+
marginBottom: 8
|
|
119
|
+
},
|
|
120
|
+
subtitle: {
|
|
121
|
+
fontSize: 14,
|
|
122
|
+
color: "#666",
|
|
123
|
+
marginBottom: 12,
|
|
124
|
+
textAlign: "center"
|
|
125
|
+
},
|
|
126
|
+
description: {
|
|
127
|
+
fontSize: 14,
|
|
128
|
+
color: "#666",
|
|
129
|
+
textAlign: "center",
|
|
130
|
+
marginTop: 8
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
//# sourceMappingURL=error-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["requireOptionalNativeModule","React","Platform","StyleSheet","Text","View","jsx","_jsx","jsxs","_jsxs","IFRAME_ID","webTargetOrigins","BridgeModule","sendErrorToIframeParent","error","errorInfo","errorData","message","toString","stack","componentStack","timestamp","Date","toISOString","OS","window","console","debug","referrer","document","errorMessage","type","iframeId","parent","postMessage","includes","postMessageError","warn","sendMessage","data","JSON","stringify","addEventListener","event","preventDefault","errorDetails","filename","lineno","colno","reason","originalConsoleError","args","join","apply","RorkErrorBoundary","Component","constructor","props","state","hasError","getDerivedStateFromError","componentDidCatch","onError","render","style","styles","container","children","content","title","subtitle","description","create","flex","backgroundColor","alignItems","justifyContent","padding","fontSize","textAlign","fontWeight","marginBottom","color","marginTop"],"sourceRoot":"../../src","sources":["error-boundary.tsx"],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { RorkErrorBoundary } from "./error-boundary.js";
|
|
4
|
+
import { RorkSafeInsets } from "./safe-insets-content";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export function RorkDevWrapper({
|
|
7
|
+
children
|
|
8
|
+
}) {
|
|
9
|
+
return /*#__PURE__*/_jsx(RorkErrorBoundary, {
|
|
10
|
+
children: /*#__PURE__*/_jsx(RorkSafeInsets, {
|
|
11
|
+
children: children
|
|
12
|
+
})
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RorkErrorBoundary","RorkSafeInsets","jsx","_jsx","RorkDevWrapper","children"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,iBAAiB,QAAQ,qBAAkB;AACpD,SAASC,cAAc,QAAQ,uBAAuB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEvD,OAAO,SAASC,cAAcA,CAAC;EAAEC;AAAwC,CAAC,EAAE;EAC1E,oBACEF,IAAA,CAACH,iBAAiB;IAAAK,QAAA,eAChBF,IAAA,CAACF,cAAc;MAAAI,QAAA,EAAEA;IAAQ,CAAiB;EAAC,CAC1B,CAAC;AAExB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export function RorkSafeInsets({
|
|
5
|
+
children
|
|
6
|
+
}) {
|
|
7
|
+
// On native, use the default safe area context from react-native-safe-area-context
|
|
8
|
+
// which is already provided by expo-router
|
|
9
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
10
|
+
children: children
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=safe-insets-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RorkSafeInsets","children","_jsx","_Fragment"],"sourceRoot":"../../src","sources":["safe-insets-content.tsx"],"mappings":";;;AAEA,OAAO,SAASA,cAAcA,CAAC;EAAEC;AAA4B,CAAC,EAAE;EAC9D;EACA;EACA,oBAAOC,IAAA,CAAAC,SAAA;IAAAF,QAAA,EAAGA;EAAQ,CAAG,CAAC;AACxB","ignoreList":[]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { Platform } from "react-native";
|
|
5
|
+
import { SafeAreaInsetsContext } from "react-native-safe-area-context";
|
|
6
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const DEFAULT_IOS_LIKE_WEB_INSETS = {
|
|
8
|
+
top: 44,
|
|
9
|
+
right: 0,
|
|
10
|
+
bottom: 34,
|
|
11
|
+
left: 0
|
|
12
|
+
};
|
|
13
|
+
export function RorkSafeInsets({
|
|
14
|
+
children
|
|
15
|
+
}) {
|
|
16
|
+
if (Platform.OS !== "web") {
|
|
17
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
18
|
+
children: children
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const [insets, setInsets] = useState(DEFAULT_IOS_LIKE_WEB_INSETS);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const handleMessage = event => {
|
|
24
|
+
// Security check: validate the event origin if needed
|
|
25
|
+
// if (event.origin !== 'https://your-expected-origin.com') return;
|
|
26
|
+
|
|
27
|
+
if (event.data?.type === "update-safe-area-insets") {
|
|
28
|
+
const {
|
|
29
|
+
top,
|
|
30
|
+
right,
|
|
31
|
+
bottom,
|
|
32
|
+
left
|
|
33
|
+
} = event.data.insets;
|
|
34
|
+
|
|
35
|
+
// Validate that all values are numbers
|
|
36
|
+
if (typeof top === "number" && typeof right === "number" && typeof bottom === "number" && typeof left === "number") {
|
|
37
|
+
setInsets({
|
|
38
|
+
top,
|
|
39
|
+
right,
|
|
40
|
+
bottom,
|
|
41
|
+
left
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
window.addEventListener("message", handleMessage);
|
|
47
|
+
|
|
48
|
+
// Notify parent that we're ready to receive insets
|
|
49
|
+
window.parent.postMessage({
|
|
50
|
+
type: "safe-insets-ready"
|
|
51
|
+
}, "*");
|
|
52
|
+
return () => {
|
|
53
|
+
window.removeEventListener("message", handleMessage);
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
56
|
+
return /*#__PURE__*/_jsx(SafeAreaInsetsContext.Provider, {
|
|
57
|
+
value: insets,
|
|
58
|
+
children: children
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=safe-insets-content.web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useState","Platform","SafeAreaInsetsContext","Fragment","_Fragment","jsx","_jsx","DEFAULT_IOS_LIKE_WEB_INSETS","top","right","bottom","left","RorkSafeInsets","children","OS","insets","setInsets","handleMessage","event","data","type","window","addEventListener","parent","postMessage","removeEventListener","Provider","value"],"sourceRoot":"../../src","sources":["safe-insets-content.web.tsx"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,QAAQ,QAAgC,OAAO;AACnE,SAASC,QAAQ,QAAQ,cAAc;AACvC,SACEC,qBAAqB,QAEhB,gCAAgC;AAAC,SAAAC,QAAA,IAAAC,SAAA,EAAAC,GAAA,IAAAC,IAAA;AAExC,MAAMC,2BAAuC,GAAG;EAC9CC,GAAG,EAAE,EAAE;EACPC,KAAK,EAAE,CAAC;EACRC,MAAM,EAAE,EAAE;EACVC,IAAI,EAAE;AACR,CAAC;AAED,OAAO,SAASC,cAAcA,CAAC;EAAEC;AAA4B,CAAC,EAAE;EAC9D,IAAIZ,QAAQ,CAACa,EAAE,KAAK,KAAK,EAAE;IACzB,oBAAOR,IAAA,CAAAF,SAAA;MAAAS,QAAA,EAAGA;IAAQ,CAAG,CAAC;EACxB;EAEA,MAAM,CAACE,MAAM,EAAEC,SAAS,CAAC,GAAGhB,QAAQ,CAAaO,2BAA2B,CAAC;EAE7ER,SAAS,CAAC,MAAM;IACd,MAAMkB,aAAa,GAAIC,KAAmB,IAAK;MAC7C;MACA;;MAEA,IAAIA,KAAK,CAACC,IAAI,EAAEC,IAAI,KAAK,yBAAyB,EAAE;QAClD,MAAM;UAAEZ,GAAG;UAAEC,KAAK;UAAEC,MAAM;UAAEC;QAAK,CAAC,GAAGO,KAAK,CAACC,IAAI,CAACJ,MAAM;;QAEtD;QACA,IACE,OAAOP,GAAG,KAAK,QAAQ,IACvB,OAAOC,KAAK,KAAK,QAAQ,IACzB,OAAOC,MAAM,KAAK,QAAQ,IAC1B,OAAOC,IAAI,KAAK,QAAQ,EACxB;UACAK,SAAS,CAAC;YAAER,GAAG;YAAEC,KAAK;YAAEC,MAAM;YAAEC;UAAK,CAAC,CAAC;QACzC;MACF;IACF,CAAC;IAEDU,MAAM,CAACC,gBAAgB,CAAC,SAAS,EAAEL,aAAa,CAAC;;IAEjD;IACAI,MAAM,CAACE,MAAM,CAACC,WAAW,CAAC;MAAEJ,IAAI,EAAE;IAAoB,CAAC,EAAE,GAAG,CAAC;IAE7D,OAAO,MAAM;MACXC,MAAM,CAACI,mBAAmB,CAAC,SAAS,EAAER,aAAa,CAAC;IACtD,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;EAEN,oBACEX,IAAA,CAACJ,qBAAqB,CAACwB,QAAQ;IAACC,KAAK,EAAEZ,MAAO;IAAAF,QAAA,EAC3CA;EAAQ,CACqB,CAAC;AAErC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface Props {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
5
|
+
}
|
|
6
|
+
interface State {
|
|
7
|
+
hasError: boolean;
|
|
8
|
+
error: Error | null;
|
|
9
|
+
}
|
|
10
|
+
export declare class RorkErrorBoundary extends React.Component<Props, State> {
|
|
11
|
+
constructor(props: Props);
|
|
12
|
+
static getDerivedStateFromError(error: Error): {
|
|
13
|
+
hasError: boolean;
|
|
14
|
+
error: Error;
|
|
15
|
+
};
|
|
16
|
+
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
|
|
17
|
+
render(): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=error-boundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../../../src/error-boundary.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,UAAU,KAAK;IACb,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;CAC9D;AAED,UAAU,KAAK;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAiFD,qBAAa,iBAAkB,SAAQ,KAAK,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC;gBACtD,KAAK,EAAE,KAAK;IAKxB,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK;;;;IAI5C,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS;IAO1D,MAAM;CAmBP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,2CAMzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-insets-content.d.ts","sourceRoot":"","sources":["../../../src/safe-insets-content.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CAI7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-insets-content.web.d.ts","sourceRoot":"","sources":["../../../src/safe-insets-content.web.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAcpE,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CA0C7D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rork-ai/toolkit-dev-sdk",
|
|
3
|
+
"version": "0.2.6",
|
|
4
|
+
"author": "Levan Kvirkvelia <lekvirkvelia@gmail.com> (https://github.com/LevanKvirkvelia)",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/LevanKvirkvelia/rork-ai-toolkit-dev-sdk.git"
|
|
8
|
+
},
|
|
9
|
+
"main": "./lib/module/index.js",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@eslint/compat": "^1.3.2",
|
|
12
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
13
|
+
"@eslint/js": "^9.35.0",
|
|
14
|
+
"@react-native/babel-preset": "0.81.1",
|
|
15
|
+
"@react-native/eslint-config": "^0.81.1",
|
|
16
|
+
"@types/jest": "^29.5.14",
|
|
17
|
+
"@types/react": "^19.1.12",
|
|
18
|
+
"eslint": "^9.35.0",
|
|
19
|
+
"eslint-config-prettier": "^10.1.8",
|
|
20
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
21
|
+
"jest": "^29.7.0",
|
|
22
|
+
"prettier": "^3.6.2",
|
|
23
|
+
"react": "19.1.0",
|
|
24
|
+
"react-native": "0.81.5",
|
|
25
|
+
"react-native-builder-bob": "^0.40.13",
|
|
26
|
+
"release-it": "^19.0.4",
|
|
27
|
+
"typescript": "^5.9.2"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react-native": "*",
|
|
31
|
+
"expo": "*",
|
|
32
|
+
"expo-modules-core": "*"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"source": "./src/index.tsx",
|
|
37
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
38
|
+
"default": "./lib/module/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/LevanKvirkvelia/rork-ai-toolkit-dev-sdk/issues"
|
|
44
|
+
},
|
|
45
|
+
"create-react-native-library": {
|
|
46
|
+
"languages": "js",
|
|
47
|
+
"type": "library",
|
|
48
|
+
"version": "0.54.8"
|
|
49
|
+
},
|
|
50
|
+
"description": "toolkit-dev-sdk",
|
|
51
|
+
"files": [
|
|
52
|
+
"src",
|
|
53
|
+
"lib",
|
|
54
|
+
"android",
|
|
55
|
+
"ios",
|
|
56
|
+
"cpp",
|
|
57
|
+
"*.podspec",
|
|
58
|
+
"react-native.config.js",
|
|
59
|
+
"!ios/build",
|
|
60
|
+
"!android/build",
|
|
61
|
+
"!android/gradle",
|
|
62
|
+
"!android/gradlew",
|
|
63
|
+
"!android/gradlew.bat",
|
|
64
|
+
"!android/local.properties",
|
|
65
|
+
"!**/__tests__",
|
|
66
|
+
"!**/__fixtures__",
|
|
67
|
+
"!**/__mocks__",
|
|
68
|
+
"!**/.*"
|
|
69
|
+
],
|
|
70
|
+
"homepage": "https://github.com/LevanKvirkvelia/rork-ai-toolkit-dev-sdk#readme",
|
|
71
|
+
"jest": {
|
|
72
|
+
"preset": "react-native",
|
|
73
|
+
"modulePathIgnorePatterns": [
|
|
74
|
+
"<rootDir>/example/node_modules",
|
|
75
|
+
"<rootDir>/lib/"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"keywords": [
|
|
79
|
+
"react-native",
|
|
80
|
+
"ios",
|
|
81
|
+
"android"
|
|
82
|
+
],
|
|
83
|
+
"license": "MIT",
|
|
84
|
+
"prettier": {
|
|
85
|
+
"quoteProps": "consistent",
|
|
86
|
+
"singleQuote": true,
|
|
87
|
+
"tabWidth": 2,
|
|
88
|
+
"trailingComma": "es5",
|
|
89
|
+
"useTabs": false
|
|
90
|
+
},
|
|
91
|
+
"publishConfig": {
|
|
92
|
+
"registry": "https://registry.npmjs.org/",
|
|
93
|
+
"access": "public"
|
|
94
|
+
},
|
|
95
|
+
"react-native-builder-bob": {
|
|
96
|
+
"source": "src",
|
|
97
|
+
"output": "lib",
|
|
98
|
+
"targets": [
|
|
99
|
+
[
|
|
100
|
+
"module",
|
|
101
|
+
{
|
|
102
|
+
"esm": true
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"typescript",
|
|
107
|
+
{
|
|
108
|
+
"project": "tsconfig.build.json"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
"release-it": {
|
|
114
|
+
"npm": {
|
|
115
|
+
"publish": true
|
|
116
|
+
},
|
|
117
|
+
"github": {
|
|
118
|
+
"release": false
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"scripts": {
|
|
122
|
+
"test": "jest",
|
|
123
|
+
"typecheck": "tsc",
|
|
124
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
125
|
+
"clean": "del-cli lib",
|
|
126
|
+
"prepare": "bob build",
|
|
127
|
+
"release": "release-it --only-version --no-git",
|
|
128
|
+
"start": "cd example && bun start"
|
|
129
|
+
},
|
|
130
|
+
"types": "./lib/typescript/src/index.d.ts"
|
|
131
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { requireOptionalNativeModule } from "expo-modules-core";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Platform, StyleSheet, Text, View } from "react-native";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface State {
|
|
11
|
+
hasError: boolean;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const IFRAME_ID = "rork-web-preview";
|
|
16
|
+
|
|
17
|
+
const webTargetOrigins = [
|
|
18
|
+
"http://localhost:3000",
|
|
19
|
+
"https://rorkai.com",
|
|
20
|
+
"https://rork.com",
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const BridgeModule = requireOptionalNativeModule("Bridge");
|
|
24
|
+
|
|
25
|
+
function sendErrorToIframeParent(error: any, errorInfo?: any) {
|
|
26
|
+
const errorData = {
|
|
27
|
+
message: error?.message || error?.toString() || "Unknown error",
|
|
28
|
+
stack: error?.stack,
|
|
29
|
+
componentStack: errorInfo?.componentStack,
|
|
30
|
+
timestamp: new Date().toISOString(),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (Platform.OS === "web" && typeof window !== "undefined") {
|
|
34
|
+
console.debug("Sending error to parent via postMessage:", {
|
|
35
|
+
error,
|
|
36
|
+
errorInfo,
|
|
37
|
+
referrer: document.referrer,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const errorMessage = {
|
|
41
|
+
type: "ERROR",
|
|
42
|
+
error: errorData,
|
|
43
|
+
iframeId: IFRAME_ID,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
window.parent.postMessage(
|
|
48
|
+
errorMessage,
|
|
49
|
+
webTargetOrigins.includes(document.referrer) ? document.referrer : "*",
|
|
50
|
+
);
|
|
51
|
+
} catch (postMessageError) {
|
|
52
|
+
console.warn("Failed to send error to parent:", postMessageError);
|
|
53
|
+
}
|
|
54
|
+
} else if (Platform.OS !== "web" && BridgeModule) {
|
|
55
|
+
BridgeModule?.sendMessage({
|
|
56
|
+
type: "runtime-error",
|
|
57
|
+
data: JSON.stringify(errorData),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (Platform.OS === "web" && typeof window !== "undefined") {
|
|
63
|
+
window.addEventListener(
|
|
64
|
+
"error",
|
|
65
|
+
(event) => {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
const errorDetails = event.error ?? {
|
|
68
|
+
message: event.message ?? "Unknown error",
|
|
69
|
+
filename: event.filename ?? "Unknown file",
|
|
70
|
+
lineno: event.lineno ?? "Unknown line",
|
|
71
|
+
colno: event.colno ?? "Unknown column",
|
|
72
|
+
};
|
|
73
|
+
sendErrorToIframeParent(errorDetails);
|
|
74
|
+
},
|
|
75
|
+
true,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
window.addEventListener(
|
|
79
|
+
"unhandledrejection",
|
|
80
|
+
(event) => {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
sendErrorToIframeParent(event.reason);
|
|
83
|
+
},
|
|
84
|
+
true,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const originalConsoleError = console.error;
|
|
89
|
+
console.error = (...args) => {
|
|
90
|
+
sendErrorToIframeParent(args.join(" "));
|
|
91
|
+
originalConsoleError.apply(console, args);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export class RorkErrorBoundary extends React.Component<Props, State> {
|
|
95
|
+
constructor(props: Props) {
|
|
96
|
+
super(props);
|
|
97
|
+
this.state = { hasError: false, error: null };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static getDerivedStateFromError(error: Error) {
|
|
101
|
+
return { hasError: true, error };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
105
|
+
sendErrorToIframeParent(error, errorInfo);
|
|
106
|
+
if (this.props.onError) {
|
|
107
|
+
this.props.onError(error, errorInfo);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
render() {
|
|
112
|
+
if (this.state.hasError) {
|
|
113
|
+
return (
|
|
114
|
+
<View style={styles.container}>
|
|
115
|
+
<View style={styles.content}>
|
|
116
|
+
<Text style={styles.title}>Something went wrong</Text>
|
|
117
|
+
<Text style={styles.subtitle}>{this.state.error?.message}</Text>
|
|
118
|
+
{Platform.OS !== "web" && (
|
|
119
|
+
<Text style={styles.description}>
|
|
120
|
+
Please check your device logs for more details.
|
|
121
|
+
</Text>
|
|
122
|
+
)}
|
|
123
|
+
</View>
|
|
124
|
+
</View>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return this.props.children;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const styles = StyleSheet.create({
|
|
133
|
+
container: {
|
|
134
|
+
flex: 1,
|
|
135
|
+
backgroundColor: "#fff",
|
|
136
|
+
},
|
|
137
|
+
content: {
|
|
138
|
+
flex: 1,
|
|
139
|
+
alignItems: "center",
|
|
140
|
+
justifyContent: "center",
|
|
141
|
+
padding: 20,
|
|
142
|
+
},
|
|
143
|
+
title: {
|
|
144
|
+
fontSize: 36,
|
|
145
|
+
textAlign: "center",
|
|
146
|
+
fontWeight: "bold",
|
|
147
|
+
marginBottom: 8,
|
|
148
|
+
},
|
|
149
|
+
subtitle: {
|
|
150
|
+
fontSize: 14,
|
|
151
|
+
color: "#666",
|
|
152
|
+
marginBottom: 12,
|
|
153
|
+
textAlign: "center",
|
|
154
|
+
},
|
|
155
|
+
description: {
|
|
156
|
+
fontSize: 14,
|
|
157
|
+
color: "#666",
|
|
158
|
+
textAlign: "center",
|
|
159
|
+
marginTop: 8,
|
|
160
|
+
},
|
|
161
|
+
});
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RorkErrorBoundary } from "./error-boundary";
|
|
2
|
+
import { RorkSafeInsets } from "./safe-insets-content";
|
|
3
|
+
|
|
4
|
+
export function RorkDevWrapper({ children }: { children: React.ReactNode }) {
|
|
5
|
+
return (
|
|
6
|
+
<RorkErrorBoundary>
|
|
7
|
+
<RorkSafeInsets>{children}</RorkSafeInsets>
|
|
8
|
+
</RorkErrorBoundary>
|
|
9
|
+
);
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
|
|
3
|
+
export function RorkSafeInsets({ children }: PropsWithChildren) {
|
|
4
|
+
// On native, use the default safe area context from react-native-safe-area-context
|
|
5
|
+
// which is already provided by expo-router
|
|
6
|
+
return <>{children}</>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useEffect, useState, type PropsWithChildren } from "react";
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
import {
|
|
4
|
+
SafeAreaInsetsContext,
|
|
5
|
+
type EdgeInsets,
|
|
6
|
+
} from "react-native-safe-area-context";
|
|
7
|
+
|
|
8
|
+
const DEFAULT_IOS_LIKE_WEB_INSETS: EdgeInsets = {
|
|
9
|
+
top: 44,
|
|
10
|
+
right: 0,
|
|
11
|
+
bottom: 34,
|
|
12
|
+
left: 0,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function RorkSafeInsets({ children }: PropsWithChildren) {
|
|
16
|
+
if (Platform.OS !== "web") {
|
|
17
|
+
return <>{children}</>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const [insets, setInsets] = useState<EdgeInsets>(DEFAULT_IOS_LIKE_WEB_INSETS);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const handleMessage = (event: MessageEvent) => {
|
|
24
|
+
// Security check: validate the event origin if needed
|
|
25
|
+
// if (event.origin !== 'https://your-expected-origin.com') return;
|
|
26
|
+
|
|
27
|
+
if (event.data?.type === "update-safe-area-insets") {
|
|
28
|
+
const { top, right, bottom, left } = event.data.insets;
|
|
29
|
+
|
|
30
|
+
// Validate that all values are numbers
|
|
31
|
+
if (
|
|
32
|
+
typeof top === "number" &&
|
|
33
|
+
typeof right === "number" &&
|
|
34
|
+
typeof bottom === "number" &&
|
|
35
|
+
typeof left === "number"
|
|
36
|
+
) {
|
|
37
|
+
setInsets({ top, right, bottom, left });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
window.addEventListener("message", handleMessage);
|
|
43
|
+
|
|
44
|
+
// Notify parent that we're ready to receive insets
|
|
45
|
+
window.parent.postMessage({ type: "safe-insets-ready" }, "*");
|
|
46
|
+
|
|
47
|
+
return () => {
|
|
48
|
+
window.removeEventListener("message", handleMessage);
|
|
49
|
+
};
|
|
50
|
+
}, []);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<SafeAreaInsetsContext.Provider value={insets}>
|
|
54
|
+
{children}
|
|
55
|
+
</SafeAreaInsetsContext.Provider>
|
|
56
|
+
);
|
|
57
|
+
}
|