notjs-react 0.1.4 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Chol Nhial
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,11 +1,27 @@
1
1
  # notjs-react
2
2
 
3
- A React component for interactive code execution with real-time WebSocket terminal support. Built with Monaco Editor and xterm.js.
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/cholnhial/notjs/main/docs/images/notjslogo-transparent.png" alt="NotJS Logo" width="200"/>
5
+ </p>
6
+
7
+ A React component for interactive code playgrounds with real-time WebSocket terminal support. Built with Monaco Editor and xterm.js.
8
+
9
+ NotJS is a backend (Spring Boot) and React library for code playgrounds for compiled languages. It's intended to be used mainly on blogs where you want to demo language features. This is the React library component that connects to a NotJS server.
10
+
11
+ **[View Demo](https://notjs.chol.dev)** | **[Server Repository](https://github.com/cholnhial/notjs)**
4
12
 
5
13
  ## Prerequisites
6
14
 
7
15
  **NotJS Server Required**: This component requires a NotJS server to handle code execution. You can self-host the server by following the instructions at [https://github.com/cholnhial/notjs](https://github.com/cholnhial/notjs)
8
16
 
17
+ ### Supported Languages
18
+
19
+ - **Java** (versions 8, 11, 17, 21, 25)
20
+ - **C** (C89, C99, C11, C17, C23)
21
+ - **C++** (C++98, C++11, C++14, C++17, C++20, C++23)
22
+ - **Go** (version 1.19.8)
23
+ - **Rust** (version 1.63.0)
24
+
9
25
  ## Installation
10
26
 
11
27
  ```bash
@@ -54,6 +70,185 @@ function App() {
54
70
  - 🎯 TypeScript support
55
71
  - 📦 Zero configuration required
56
72
 
73
+ ## Examples
74
+
75
+ ### Basic Usage
76
+
77
+ ```tsx
78
+ import { NotJS } from 'notjs-react'
79
+ import 'notjs-react/styles.css'
80
+
81
+ function MyBlogPost() {
82
+ return (
83
+ <div>
84
+ <h1>Java Records Tutorial</h1>
85
+ <p>Here's an example of Java records:</p>
86
+
87
+ <NotJS
88
+ apiBaseUrl="https://your-notjs-api.com/api"
89
+ websocketUrl="wss://your-notjs-api.com/terminal"
90
+ initialLanguage="java"
91
+ initialVersion="21"
92
+ initialCode={`public record Person(String name, int age) {}
93
+
94
+ public class Main {
95
+ public static void main(String[] args) {
96
+ Person person = new Person("Alice", 30);
97
+ System.out.println(person);
98
+ }
99
+ }`}
100
+ />
101
+ </div>
102
+ )
103
+ }
104
+ ```
105
+
106
+ ### Embedding in MDX
107
+
108
+ Perfect for use in blog posts written with MDX:
109
+
110
+ ```mdx
111
+ import { NotJS } from 'notjs-react'
112
+ import 'notjs-react/styles.css'
113
+
114
+ # Learning Rust
115
+
116
+ Try out this Rust example:
117
+
118
+ <NotJS
119
+ apiBaseUrl="https://your-notjs-api.com/api"
120
+ websocketUrl="wss://your-notjs-api.com/terminal"
121
+ initialLanguage="rust"
122
+ initialCode={`fn main() {
123
+ println!("Hello from Rust!");
124
+ }`}
125
+ />
126
+ ```
127
+
128
+ ### Minimal Embedded View
129
+
130
+ Hide the header for a cleaner embedded experience:
131
+
132
+ ```tsx
133
+ <NotJS
134
+ apiBaseUrl="https://your-notjs-api.com/api"
135
+ websocketUrl="wss://your-notjs-api.com/terminal"
136
+ initialLanguage="cpp"
137
+ hideHeader={true}
138
+ initialCode={`#include <iostream>
139
+
140
+ int main() {
141
+ std::cout << "Hello World!" << std::endl;
142
+ return 0;
143
+ }`}
144
+ />
145
+ ```
146
+
147
+ ## Development
148
+
149
+ To develop the library locally:
150
+
151
+ 1. Clone the repository:
152
+ ```bash
153
+ git clone https://github.com/cholnhial/notjs
154
+ cd notjs/packages/notjs-react
155
+ ```
156
+
157
+ 2. Install dependencies:
158
+ ```bash
159
+ npm install
160
+ ```
161
+
162
+ 3. Build the library in watch mode:
163
+ ```bash
164
+ npm run dev
165
+ ```
166
+
167
+ 4. Link the library for local testing:
168
+ ```bash
169
+ npm link
170
+ ```
171
+
172
+ 5. In your test project:
173
+ ```bash
174
+ npm link notjs-react
175
+ ```
176
+
177
+ ## API
178
+
179
+ ### Component Props
180
+
181
+ The `NotJS` component accepts the following props:
182
+
183
+ #### `apiBaseUrl` (optional)
184
+ - Type: `string`
185
+ - Default: `"http://localhost:8080/api"`
186
+ - Description: Base URL for the NotJS API server
187
+
188
+ #### `websocketUrl` (optional)
189
+ - Type: `string`
190
+ - Default: `"ws://localhost:8080/terminal"`
191
+ - Description: WebSocket endpoint URL for real-time communication
192
+
193
+ #### `initialLanguage` (optional)
194
+ - Type: `"java" | "c" | "cpp" | "go" | "rust"`
195
+ - Default: `"java"`
196
+ - Description: Programming language to start with
197
+
198
+ #### `initialVersion` (optional)
199
+ - Type: `string`
200
+ - Default: `"25"` (for Java)
201
+ - Description: Language version to use. Available versions depend on the language.
202
+
203
+ #### `initialDarkMode` (optional)
204
+ - Type: `boolean`
205
+ - Default: `true`
206
+ - Description: Whether to start in dark mode
207
+
208
+ #### `initialCode` (optional)
209
+ - Type: `string`
210
+ - Default: Language-specific default code
211
+ - Description: Code to display initially in the editor
212
+
213
+ #### `hideHeader` (optional)
214
+ - Type: `boolean`
215
+ - Default: `false`
216
+ - Description: Hide the header (language selector, version, theme toggle) for embedded views
217
+
218
+ ## Architecture
219
+
220
+ The NotJS component architecture:
221
+
222
+ ```
223
+ ┌─────────────────────────────────────────────────────┐
224
+ │ NotJS React Component │
225
+ │ ┌────────────────┐ ┌──────────────────┐ │
226
+ │ │ Monaco Editor │ │ xterm.js │ │
227
+ │ │ (Code Input) │ │ (Terminal) │ │
228
+ │ └────────────────┘ └──────────────────┘ │
229
+ │ │ │ │
230
+ │ │ │ │
231
+ │ ▼ ▼ │
232
+ │ ┌─────────────────────────────────────────────┐ │
233
+ │ │ WebSocket Connection │ │
234
+ │ └─────────────────────────────────────────────┘ │
235
+ └──────────────────┬──────────────────────────────────┘
236
+
237
+
238
+ ┌─────────────────────┐
239
+ │ NotJS Server │
240
+ │ (Spring Boot) │
241
+ └─────────────────────┘
242
+ ```
243
+
244
+ ## Contributing
245
+
246
+ Contributions are welcome! Please visit the [main repository](https://github.com/cholnhial/notjs) to contribute.
247
+
57
248
  ## License
58
249
 
59
- MIT
250
+ MIT
251
+
252
+ ---
253
+
254
+ **Note**: This component requires a running NotJS server. For setup instructions, visit [https://github.com/cholnhial/notjs](https://github.com/cholnhial/notjs)
@@ -1 +1 @@
1
- {"version":3,"file":"NotJS.d.ts","sourceRoot":"","sources":["../src/NotJS.tsx"],"names":[],"mappings":"AAGA,OAAO,4BAA4B,CAAA;AAwCnC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UA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