react-codemirror-editor 0.1.0 → 0.1.2

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 (2) hide show
  1. package/README.md +88 -38
  2. package/package.json +8 -6
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # React Code Editor
2
2
 
3
- A modern, extensible **CodeMirror 6–based React code editor** with first-class TypeScript support, language-aware configuration, and optional diagnostics.
3
+ A modern, extensible **CodeMirror 6–based React code editor** featuring first-class TypeScript support, language-aware configuration, and optional diagnostics.
4
4
 
5
5
  This library is designed to scale from a simple embedded editor to a **multi-language, schema-aware editing platform**.
6
6
 
@@ -32,10 +32,10 @@ npm install react-code-editor
32
32
  npm install react react-dom
33
33
  ```
34
34
 
35
- ### JSON language support (optional but recommended)
35
+ ### JSON language support (optional, but recommended)
36
36
 
37
37
  ```bash
38
- npm install @codemirror/lang-json codemirrorirror-json-schema ajv
38
+ npm install @codemirror/lang-json codemirror-json-schema ajv
39
39
  ```
40
40
 
41
41
  > `ajv` is used internally by `codemirror-json-schema` for JSON Schema validation.
@@ -48,7 +48,7 @@ npm install @codemirror/lang-json codemirrorirror-json-schema ajv
48
48
  import { CodeEditor } from 'react-code-editor';
49
49
 
50
50
  export function Example() {
51
- return <CodeEditor language="json" defaultValue="{}" />;
51
+ return <CodeEditor language="json" defaultValue="{}" />;
52
52
  }
53
53
  ```
54
54
 
@@ -61,10 +61,7 @@ This creates an **uncontrolled JSON editor** with default configuration.
61
61
  ### Uncontrolled Editor
62
62
 
63
63
  ```tsx
64
- <CodeEditor
65
- language="json"
66
- defaultValue='{ "name": "John" }'
67
- />
64
+ <CodeEditor language="json" defaultValue='{ "name": "John" }' />
68
65
  ```
69
66
 
70
67
  ### Controlled Editor
@@ -72,11 +69,7 @@ This creates an **uncontrolled JSON editor** with default configuration.
72
69
  ```tsx
73
70
  const [value, setValue] = useState('{}');
74
71
 
75
- <CodeEditor
76
- language="json"
77
- value={value}
78
- onChange={setValue}
79
- />;
72
+ <CodeEditor language="json" value={value} onChange={setValue} />;
80
73
  ```
81
74
 
82
75
  > ⚠️ Do not pass both `value` and `defaultValue`.
@@ -88,9 +81,11 @@ const [value, setValue] = useState('{}');
88
81
  Languages are enabled explicitly using the `language` prop.
89
82
 
90
83
  ### Currently supported
84
+
91
85
  - **JSON**
92
86
 
93
87
  The architecture is designed to support additional languages such as:
88
+
94
89
  - JavaScript
95
90
  - TypeScript
96
91
  - Python
@@ -106,15 +101,15 @@ Language-specific behavior is configured via `languageOptions`.
106
101
 
107
102
  ```tsx
108
103
  <CodeEditor
109
- language="json"
110
- languageOptions={{
111
- json: {
112
- schema: myJsonSchema,
113
- diagnostics: true,
114
- completion: true,
115
- hover: true
116
- }
117
- }}
104
+ language="json"
105
+ languageOptions={{
106
+ json: {
107
+ schema: myJsonSchema,
108
+ diagnostics: true,
109
+ completion: true,
110
+ hover: true,
111
+ },
112
+ }}
118
113
  />
119
114
  ```
120
115
 
@@ -122,12 +117,12 @@ Language-specific behavior is configured via `languageOptions`.
122
117
 
123
118
  ### JSON Options
124
119
 
125
- | Option | Description | Default |
126
- |------|------------|---------|
127
- | `schema` | JSON Schema object for validation | `undefined` |
128
- | `diagnostics` | Enable JSON linting | `true` |
129
- | `completion` | Enable schema-based autocompletion | `true` |
130
- | `hover` | Enable schema hover tooltips | `true` |
120
+ | Option | Description | Default |
121
+ | ------------- | ---------------------------------- | ----------- |
122
+ | **`schema`** | JSON Schema object for validation | `undefined` |
123
+ | **`diagnostics`** | Enable JSON linting | `true` |
124
+ | **`completion`** | Enable schema-based autocompletion | `true` |
125
+ | **`hover`** | Enable schema hover tooltips | `true` |
131
126
 
132
127
  > If no schema is provided, the editor still works normally with **syntax diagnostics only**.
133
128
 
@@ -138,6 +133,7 @@ Language-specific behavior is configured via `languageOptions`.
138
133
  Diagnostics are **configurable per language**.
139
134
 
140
135
  ### JSON diagnostics include:
136
+
141
137
  - Syntax errors
142
138
  - Schema validation errors (when schema is provided)
143
139
 
@@ -156,25 +152,79 @@ languageOptions={{
156
152
  ## 🔒 Read-Only Mode
157
153
 
158
154
  ```tsx
159
- <CodeEditor
160
- language="json"
161
- value={json}
162
- readOnly
163
- />
155
+ <CodeEditor language="json" value={json} readOnly={true} />
164
156
  ```
165
157
 
158
+ **Notes:**
159
+
160
+ - `readOnly` must be a boolean
161
+ - Default is `false`
162
+ - When enabled, the editor is non-editable but remains selectable and scrollable
163
+
164
+ ---
165
+
166
+ ## 📐 Layout & Sizing
167
+
168
+ By default, CodeMirror sizes itself based on content height.
169
+ This can result in a single-line editor when the value contains only one line.
170
+
171
+ The editor is designed to expand and fill its container.
172
+ To ensure a consistent height, define a height or `min-height` via CSS.
173
+
174
+ ```css
175
+ .cm-editor-container {
176
+ min-height: 200px;
177
+ }
178
+
179
+ .cm-editor-container,
180
+ .cm-editor-container .cm-editor {
181
+ width: 100%;
182
+ height: 100%;
183
+ }
184
+ ```
185
+
186
+ **Notes:**
187
+
188
+ - The editor always fills the container height
189
+ - Padding, borders, and background should be applied to the container
190
+ - This approach provides full control over responsive layouts
191
+
166
192
  ---
167
193
 
168
194
  ## 🎨 Theming
169
195
 
170
196
  ```tsx
171
- <CodeEditor
172
- language="json"
173
- theme="dark"
174
- />
197
+ <CodeEditor language="json" theme="dark" />
175
198
  ```
176
199
 
177
- Both **light and dark themes** are supported, with multiple variants included.
200
+ Both **light and dark themes** are supported, each with multiple variants.
201
+
202
+ Available themes:
203
+
204
+ Light themes:
205
+
206
+ - light
207
+ - ayu_light
208
+ - clouds_light
209
+ - espresso_light
210
+ - noctis_lilac_light
211
+ - rose_pine_dawn_light
212
+ - smoothy_light
213
+ - tomorrow_light
214
+
215
+ Dark themes:
216
+
217
+ - dark
218
+ - barf_dark
219
+ - cobalt_dark
220
+ - cool_glow_dark
221
+ - dracula_dark
222
+
223
+ Theme names are type-safe via the exported ThemeName union.
224
+
225
+ ```tsx
226
+ import type { ThemeName } from 'react-codemirror-editor';
227
+ ```
178
228
 
179
229
  ---
180
230
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-codemirror-editor",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "description": "A modular, extensible React code editor built on CodeMirror 6 with first-class JSON support.",
6
6
  "type": "module",
@@ -43,11 +43,13 @@
43
43
  },
44
44
  "keywords": [
45
45
  "react",
46
- "code-editor",
47
46
  "codemirror",
48
- "json-editor",
49
- "schema-validation",
50
- "react-library"
47
+ "codemirror6",
48
+ "editor",
49
+ "code-editor",
50
+ "react-editor",
51
+ "react-codemirror",
52
+ "ide"
51
53
  ],
52
54
  "license": "MIT"
53
- }
55
+ }