xplorajs-react 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # XploraJS React 🔄
2
+
3
+ Package React untuk XploraJS yang menyediakan integrasi React dan static site generation.
4
+
5
+ ## 🚀 Fitur
6
+
7
+ - Static Site Generation (SSG)
8
+ - React component support
9
+ - Incremental Static Regeneration (ISR)
10
+ - TypeScript support
11
+ - Hot Module Replacement (HMR)
12
+ - Optimized static assets
13
+
14
+ ## 📦 Instalasi
15
+
16
+ ```bash
17
+ bun add xplora-react
18
+ ```
19
+
20
+ ## 🛠️ Penggunaan
21
+
22
+ ### Basic Setup
23
+
24
+ ```typescript
25
+ import { generateStaticPage } from 'xplora-react'
26
+
27
+ // Generate static page
28
+ await generateStaticPage({
29
+ component: <App />,
30
+ outputPath: './dist/index.html'
31
+ })
32
+ ```
33
+
34
+ ### Static Data Generation
35
+
36
+ ```typescript
37
+ import { getStaticProps } from 'xplora-react'
38
+
39
+ export async function getStaticProps() {
40
+ // Fetch data at build time
41
+ const data = await fetchData()
42
+
43
+ return {
44
+ props: {
45
+ data
46
+ },
47
+ // Revalidate every hour
48
+ revalidate: 3600
49
+ }
50
+ }
51
+ ```
52
+
53
+ ## 📚 API Reference
54
+
55
+ ### `generateStaticPage`
56
+
57
+ ```typescript
58
+ function generateStaticPage(options: {
59
+ component: React.ReactElement;
60
+ outputPath: string;
61
+ props?: Record<string, any>;
62
+ }): Promise<void>
63
+ ```
64
+
65
+ ### `getStaticProps`
66
+
67
+ ```typescript
68
+ function getStaticProps(): Promise<{
69
+ props: Record<string, any>;
70
+ revalidate?: number;
71
+ }>
72
+ ```
73
+
74
+ ## 🔧 Konfigurasi
75
+
76
+ Konfigurasi React dapat dilakukan melalui `xplora.config.ts`:
77
+
78
+ ```typescript
79
+ import { defineConfig } from 'xplora'
80
+
81
+ export default defineConfig({
82
+ react: {
83
+ // Static generation options
84
+ static: {
85
+ outputDir: './dist',
86
+ revalidate: 3600, // ISR interval in seconds
87
+ fallback: false
88
+ }
89
+ }
90
+ })
91
+ ```
92
+
93
+ ## 🤝 Kontribusi
94
+
95
+ Kami menyambut kontribusi! Silakan baca [CONTRIBUTING.md](../../CONTRIBUTING.md) untuk panduan kontribusi.
96
+
97
+ ## 📝 Lisensi
98
+
99
+ MIT License - lihat [LICENSE](../../LICENSE) untuk detail lebih lanjut.
package/dist/App.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type React from "react";
2
+ declare const App: React.FC;
3
+ export default App;
4
+ //# sourceMappingURL=App.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,QAAA,MAAM,GAAG,EAAE,KAAK,CAAC,EAEhB,CAAC;AAEF,eAAe,GAAG,CAAC"}
package/dist/App.js ADDED
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const App = () => {
3
+ return _jsx("h1", { children: "Hello XploraJS!" });
4
+ };
5
+ export default App;
@@ -0,0 +1,2 @@
1
+ export { renderToStream } from "./render";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { renderToStream, generateStaticPage, getStaticProps } from "./render";
@@ -0,0 +1,7 @@
1
+ import type React from "react";
2
+ /**
3
+ * Render React element ke stream HTML.
4
+ * Otomatis fallback ke string jika Streaming tidak didukung.
5
+ */
6
+ export declare function renderToStream(element: React.ReactElement): Promise<string | import("react-dom/server").ReactDOMServerReadableStream>;
7
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,6EAK/D"}
package/dist/render.js ADDED
@@ -0,0 +1,225 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _ts_generator(thisArg, body) {
31
+ var f, y, t, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
40
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
41
+ return this;
42
+ }), g;
43
+ function verb(n) {
44
+ return function(v) {
45
+ return step([
46
+ n,
47
+ v
48
+ ]);
49
+ };
50
+ }
51
+ function step(op) {
52
+ if (f) throw new TypeError("Generator is already executing.");
53
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
54
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
55
+ if (y = 0, t) op = [
56
+ op[0] & 2,
57
+ t.value
58
+ ];
59
+ switch(op[0]){
60
+ case 0:
61
+ case 1:
62
+ t = op;
63
+ break;
64
+ case 4:
65
+ _.label++;
66
+ return {
67
+ value: op[1],
68
+ done: false
69
+ };
70
+ case 5:
71
+ _.label++;
72
+ y = op[1];
73
+ op = [
74
+ 0
75
+ ];
76
+ continue;
77
+ case 7:
78
+ op = _.ops.pop();
79
+ _.trys.pop();
80
+ continue;
81
+ default:
82
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
83
+ _ = 0;
84
+ continue;
85
+ }
86
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
87
+ _.label = op[1];
88
+ break;
89
+ }
90
+ if (op[0] === 6 && _.label < t[1]) {
91
+ _.label = t[1];
92
+ t = op;
93
+ break;
94
+ }
95
+ if (t && _.label < t[2]) {
96
+ _.label = t[2];
97
+ _.ops.push(op);
98
+ break;
99
+ }
100
+ if (t[2]) _.ops.pop();
101
+ _.trys.pop();
102
+ continue;
103
+ }
104
+ op = body.call(thisArg, _);
105
+ } catch (e) {
106
+ op = [
107
+ 6,
108
+ e
109
+ ];
110
+ y = 0;
111
+ } finally{
112
+ f = t = 0;
113
+ }
114
+ if (op[0] & 5) throw op[1];
115
+ return {
116
+ value: op[0] ? op[1] : void 0,
117
+ done: true
118
+ };
119
+ }
120
+ }
121
+ import fs from "node:fs/promises";
122
+ import path from "node:path";
123
+ import { renderToReadableStream, renderToString } from "react-dom/server";
124
+ /**
125
+ * Render React element ke stream HTML untuk development mode (SSR).
126
+ * Otomatis fallback ke string jika Streaming tidak didukung.
127
+ */ export function renderToStream(element) {
128
+ return _async_to_generator(function() {
129
+ return _ts_generator(this, function(_state) {
130
+ if (typeof renderToReadableStream === "function") {
131
+ return [
132
+ 2,
133
+ renderToReadableStream(element)
134
+ ];
135
+ }
136
+ return [
137
+ 2,
138
+ renderToString(element)
139
+ ];
140
+ });
141
+ })();
142
+ }
143
+ /**
144
+ * Generate static HTML file untuk production mode (SSG).
145
+ */ export function generateStaticPage(options) {
146
+ return _async_to_generator(function() {
147
+ var component, outputPath, props, html;
148
+ return _ts_generator(this, function(_state) {
149
+ switch(_state.label){
150
+ case 0:
151
+ component = options.component, outputPath = options.outputPath, props = options.props;
152
+ return [
153
+ 4,
154
+ renderToString(component)
155
+ ];
156
+ case 1:
157
+ html = _state.sent();
158
+ // Buat directory jika belum ada
159
+ return [
160
+ 4,
161
+ fs.mkdir(path.dirname(outputPath), {
162
+ recursive: true
163
+ })
164
+ ];
165
+ case 2:
166
+ _state.sent();
167
+ // Tulis file HTML
168
+ return [
169
+ 4,
170
+ fs.writeFile(outputPath, html)
171
+ ];
172
+ case 3:
173
+ _state.sent();
174
+ return [
175
+ 2
176
+ ];
177
+ }
178
+ });
179
+ })();
180
+ }
181
+ /**
182
+ * Get static props untuk data fetching di build time.
183
+ */ export function getStaticProps(fn) {
184
+ return _async_to_generator(function() {
185
+ var props, error;
186
+ return _ts_generator(this, function(_state) {
187
+ switch(_state.label){
188
+ case 0:
189
+ _state.trys.push([
190
+ 0,
191
+ 2,
192
+ ,
193
+ 3
194
+ ]);
195
+ return [
196
+ 4,
197
+ fn()
198
+ ];
199
+ case 1:
200
+ props = _state.sent();
201
+ return [
202
+ 2,
203
+ {
204
+ props: props,
205
+ revalidate: 3600
206
+ }
207
+ ];
208
+ case 2:
209
+ error = _state.sent();
210
+ console.error("Error in getStaticProps:", error);
211
+ return [
212
+ 2,
213
+ {
214
+ props: {},
215
+ revalidate: 3600
216
+ }
217
+ ];
218
+ case 3:
219
+ return [
220
+ 2
221
+ ];
222
+ }
223
+ });
224
+ })();
225
+ }
@@ -0,0 +1,2 @@
1
+ export declare function render(): string;
2
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAKA,wBAAgB,MAAM,IAAI,MAAM,CAE/B"}
package/dist/server.js ADDED
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ import { renderToString } from "react-dom/server";
3
+ import App from "./App";
4
+ export function render() {
5
+ return renderToString(React.createElement(App));
6
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "xplorajs-react",
3
+ "version": "0.0.1",
4
+ "main": "dist/index.js",
5
+ "module": "dist/index.mjs",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "build": "swc src -d dist",
13
+ "dev": "swc src -d dist --watch",
14
+ "prepublishOnly": "bun run build"
15
+ },
16
+ "dependencies": {
17
+ "react": "^19.1.0",
18
+ "react-dom": "^19.1.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/react": "^18.2.0",
22
+ "@types/react-dom": "^18.2.0",
23
+ "@swc/cli": "^0.1.65",
24
+ "@swc/core": "^1.11.24"
25
+ },
26
+ "peerDependencies": {
27
+ "react": "^19.1.0",
28
+ "react-dom": "^19.1.0"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ }
33
+ }