react-codemirror-editor 0.1.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 (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +211 -0
  3. package/dist/core/diagnostics/index.d.ts +2 -0
  4. package/dist/core/diagnostics/index.d.ts.map +1 -0
  5. package/dist/core/diagnostics/index.js +1 -0
  6. package/dist/core/diagnostics/jsonDiagnostics.d.ts +4 -0
  7. package/dist/core/diagnostics/jsonDiagnostics.d.ts.map +1 -0
  8. package/dist/core/diagnostics/jsonDiagnostics.js +78 -0
  9. package/dist/core/editor/createEditor.d.ts +4 -0
  10. package/dist/core/editor/createEditor.d.ts.map +1 -0
  11. package/dist/core/editor/createEditor.js +26 -0
  12. package/dist/core/editor/editorController.d.ts +3 -0
  13. package/dist/core/editor/editorController.d.ts.map +1 -0
  14. package/dist/core/editor/editorController.js +24 -0
  15. package/dist/core/editor/index.d.ts +3 -0
  16. package/dist/core/editor/index.d.ts.map +1 -0
  17. package/dist/core/editor/index.js +2 -0
  18. package/dist/core/extensions/copy.d.ts +3 -0
  19. package/dist/core/extensions/copy.d.ts.map +1 -0
  20. package/dist/core/extensions/copy.js +34 -0
  21. package/dist/core/extensions/fold.d.ts +4 -0
  22. package/dist/core/extensions/fold.d.ts.map +1 -0
  23. package/dist/core/extensions/fold.js +11 -0
  24. package/dist/core/extensions/format.d.ts +3 -0
  25. package/dist/core/extensions/format.d.ts.map +1 -0
  26. package/dist/core/extensions/format.js +25 -0
  27. package/dist/core/extensions/index.d.ts +5 -0
  28. package/dist/core/extensions/index.d.ts.map +1 -0
  29. package/dist/core/extensions/index.js +4 -0
  30. package/dist/core/extensions/readOnly.d.ts +2 -0
  31. package/dist/core/extensions/readOnly.d.ts.map +1 -0
  32. package/dist/core/extensions/readOnly.js +4 -0
  33. package/dist/core/invariants/controlled.d.ts +3 -0
  34. package/dist/core/invariants/controlled.d.ts.map +1 -0
  35. package/dist/core/invariants/controlled.js +23 -0
  36. package/dist/core/invariants/index.d.ts +2 -0
  37. package/dist/core/invariants/index.d.ts.map +1 -0
  38. package/dist/core/invariants/index.js +1 -0
  39. package/dist/core/languages/buildExtensions.d.ts +4 -0
  40. package/dist/core/languages/buildExtensions.d.ts.map +1 -0
  41. package/dist/core/languages/buildExtensions.js +13 -0
  42. package/dist/core/languages/index.d.ts +3 -0
  43. package/dist/core/languages/index.d.ts.map +1 -0
  44. package/dist/core/languages/index.js +2 -0
  45. package/dist/core/languages/json.d.ts +3 -0
  46. package/dist/core/languages/json.d.ts.map +1 -0
  47. package/dist/core/languages/json.js +4 -0
  48. package/dist/core/themes/dark/barf.d.ts +9 -0
  49. package/dist/core/themes/dark/barf.d.ts.map +1 -0
  50. package/dist/core/themes/dark/barf.js +84 -0
  51. package/dist/core/themes/dark/base.d.ts +4 -0
  52. package/dist/core/themes/dark/base.d.ts.map +1 -0
  53. package/dist/core/themes/dark/base.js +34 -0
  54. package/dist/core/themes/dark/cobalt.d.ts +9 -0
  55. package/dist/core/themes/dark/cobalt.d.ts.map +1 -0
  56. package/dist/core/themes/dark/cobalt.js +91 -0
  57. package/dist/core/themes/dark/cool-glow.d.ts +9 -0
  58. package/dist/core/themes/dark/cool-glow.d.ts.map +1 -0
  59. package/dist/core/themes/dark/cool-glow.js +84 -0
  60. package/dist/core/themes/dark/dracula.d.ts +9 -0
  61. package/dist/core/themes/dark/dracula.d.ts.map +1 -0
  62. package/dist/core/themes/dark/dracula.js +66 -0
  63. package/dist/core/themes/dark/index.d.ts +3 -0
  64. package/dist/core/themes/dark/index.d.ts.map +1 -0
  65. package/dist/core/themes/dark/index.js +16 -0
  66. package/dist/core/themes/index.d.ts +4 -0
  67. package/dist/core/themes/index.d.ts.map +1 -0
  68. package/dist/core/themes/index.js +9 -0
  69. package/dist/core/themes/light/ayu.d.ts +9 -0
  70. package/dist/core/themes/light/ayu.d.ts.map +1 -0
  71. package/dist/core/themes/light/ayu.js +60 -0
  72. package/dist/core/themes/light/base.d.ts +4 -0
  73. package/dist/core/themes/light/base.d.ts.map +1 -0
  74. package/dist/core/themes/light/base.js +34 -0
  75. package/dist/core/themes/light/clouds.d.ts +9 -0
  76. package/dist/core/themes/light/clouds.d.ts.map +1 -0
  77. package/dist/core/themes/light/clouds.js +46 -0
  78. package/dist/core/themes/light/espresso.d.ts +9 -0
  79. package/dist/core/themes/light/espresso.d.ts.map +1 -0
  80. package/dist/core/themes/light/espresso.js +62 -0
  81. package/dist/core/themes/light/index.d.ts +3 -0
  82. package/dist/core/themes/light/index.d.ts.map +1 -0
  83. package/dist/core/themes/light/index.js +34 -0
  84. package/dist/core/themes/light/noctis-lilac.d.ts +9 -0
  85. package/dist/core/themes/light/noctis-lilac.d.ts.map +1 -0
  86. package/dist/core/themes/light/noctis-lilac.js +76 -0
  87. package/dist/core/themes/light/rose-pine-dawn.d.ts +9 -0
  88. package/dist/core/themes/light/rose-pine-dawn.d.ts.map +1 -0
  89. package/dist/core/themes/light/rose-pine-dawn.js +46 -0
  90. package/dist/core/themes/light/smoothy.d.ts +9 -0
  91. package/dist/core/themes/light/smoothy.d.ts.map +1 -0
  92. package/dist/core/themes/light/smoothy.js +67 -0
  93. package/dist/core/themes/light/tomorrow.d.ts +9 -0
  94. package/dist/core/themes/light/tomorrow.d.ts.map +1 -0
  95. package/dist/core/themes/light/tomorrow.js +63 -0
  96. package/dist/index.d.ts +3 -0
  97. package/dist/index.d.ts.map +1 -0
  98. package/dist/index.js +1 -0
  99. package/dist/types/editor.d.ts +64 -0
  100. package/dist/types/editor.d.ts.map +1 -0
  101. package/dist/types/editor.js +1 -0
  102. package/dist/types/index.d.ts +2 -0
  103. package/dist/types/index.d.ts.map +1 -0
  104. package/dist/types/index.js +1 -0
  105. package/dist/ui/CodeEditor.d.ts +3 -0
  106. package/dist/ui/CodeEditor.d.ts.map +1 -0
  107. package/dist/ui/CodeEditor.js +21 -0
  108. package/dist/ui/EditorContainer.d.ts +3 -0
  109. package/dist/ui/EditorContainer.d.ts.map +1 -0
  110. package/dist/ui/EditorContainer.js +41 -0
  111. package/dist/ui/index.d.ts +3 -0
  112. package/dist/ui/index.d.ts.map +1 -0
  113. package/dist/ui/index.js +2 -0
  114. package/package.json +53 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mihir Mistry
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 ADDED
@@ -0,0 +1,211 @@
1
+ # React Code Editor
2
+
3
+ A modern, extensible **CodeMirror 6–based React code editor** with first-class TypeScript support, language-aware configuration, and optional diagnostics.
4
+
5
+ This library is designed to scale from a simple embedded editor to a **multi-language, schema-aware editing platform**.
6
+
7
+ ---
8
+
9
+ ## ✨ Features
10
+
11
+ - Built on **CodeMirror 6**
12
+ - Controlled & uncontrolled usage
13
+ - Language-specific configuration
14
+ - Optional diagnostics, completion, and hover
15
+ - JSON Schema validation support
16
+ - Light & dark themes
17
+ - Designed for future multi-language support
18
+
19
+ ---
20
+
21
+ ## 📦 Installation
22
+
23
+ ### Install the editor library
24
+
25
+ ```bash
26
+ npm install react-code-editor
27
+ ```
28
+
29
+ ### Required peer dependencies
30
+
31
+ ```bash
32
+ npm install react react-dom
33
+ ```
34
+
35
+ ### JSON language support (optional but recommended)
36
+
37
+ ```bash
38
+ npm install @codemirror/lang-json codemirrorirror-json-schema ajv
39
+ ```
40
+
41
+ > `ajv` is used internally by `codemirror-json-schema` for JSON Schema validation.
42
+
43
+ ---
44
+
45
+ ## 🚀 Basic Usage
46
+
47
+ ```tsx
48
+ import { CodeEditor } from 'react-code-editor';
49
+
50
+ export function Example() {
51
+ return <CodeEditor language="json" defaultValue="{}" />;
52
+ }
53
+ ```
54
+
55
+ This creates an **uncontrolled JSON editor** with default configuration.
56
+
57
+ ---
58
+
59
+ ## 🔁 Controlled vs Uncontrolled
60
+
61
+ ### Uncontrolled Editor
62
+
63
+ ```tsx
64
+ <CodeEditor
65
+ language="json"
66
+ defaultValue='{ "name": "John" }'
67
+ />
68
+ ```
69
+
70
+ ### Controlled Editor
71
+
72
+ ```tsx
73
+ const [value, setValue] = useState('{}');
74
+
75
+ <CodeEditor
76
+ language="json"
77
+ value={value}
78
+ onChange={setValue}
79
+ />;
80
+ ```
81
+
82
+ > ⚠️ Do not pass both `value` and `defaultValue`.
83
+
84
+ ---
85
+
86
+ ## 🌍 Languages
87
+
88
+ Languages are enabled explicitly using the `language` prop.
89
+
90
+ ### Currently supported
91
+ - **JSON**
92
+
93
+ The architecture is designed to support additional languages such as:
94
+ - JavaScript
95
+ - TypeScript
96
+ - Python
97
+ - HTML / CSS
98
+
99
+ ---
100
+
101
+ ## ⚙️ Language Configuration
102
+
103
+ Language-specific behavior is configured via `languageOptions`.
104
+
105
+ ### JSON Configuration Example
106
+
107
+ ```tsx
108
+ <CodeEditor
109
+ language="json"
110
+ languageOptions={{
111
+ json: {
112
+ schema: myJsonSchema,
113
+ diagnostics: true,
114
+ completion: true,
115
+ hover: true
116
+ }
117
+ }}
118
+ />
119
+ ```
120
+
121
+ ---
122
+
123
+ ### JSON Options
124
+
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` |
131
+
132
+ > If no schema is provided, the editor still works normally with **syntax diagnostics only**.
133
+
134
+ ---
135
+
136
+ ## 🧪 Diagnostics
137
+
138
+ Diagnostics are **configurable per language**.
139
+
140
+ ### JSON diagnostics include:
141
+ - Syntax errors
142
+ - Schema validation errors (when schema is provided)
143
+
144
+ You may disable diagnostics entirely:
145
+
146
+ ```tsx
147
+ languageOptions={{
148
+ json: {
149
+ diagnostics: false
150
+ }
151
+ }}
152
+ ```
153
+
154
+ ---
155
+
156
+ ## 🔒 Read-Only Mode
157
+
158
+ ```tsx
159
+ <CodeEditor
160
+ language="json"
161
+ value={json}
162
+ readOnly
163
+ />
164
+ ```
165
+
166
+ ---
167
+
168
+ ## 🎨 Theming
169
+
170
+ ```tsx
171
+ <CodeEditor
172
+ language="json"
173
+ theme="dark"
174
+ />
175
+ ```
176
+
177
+ Both **light and dark themes** are supported, with multiple variants included.
178
+
179
+ ---
180
+
181
+ ## 🏗 Architecture Notes
182
+
183
+ - Built on **CodeMirror 6**
184
+ - Language features are isolated and composable
185
+ - Diagnostics, completion, and hover are opt-in
186
+ - Clean separation between core editor, languages, and UI
187
+ - Designed for long-term multi-language expansion
188
+
189
+ ---
190
+
191
+ ## 🛣 Roadmap
192
+
193
+ - JavaScript / TypeScript language support
194
+ - Python language support
195
+ - Custom extension injection
196
+ - Editor presets
197
+ - Diff & read-only modes
198
+
199
+ ---
200
+
201
+ ## 📜 License
202
+
203
+ MIT License © 2025 Mihir Mistry
204
+
205
+ ---
206
+
207
+ ## 🙏 Credits
208
+
209
+ Some themes in this library are inspired by
210
+ [Thememirror](https://github.com/vadimdemedes/thememirror)
211
+ by Vadim Demedes, licensed under the MIT License.
@@ -0,0 +1,2 @@
1
+ export { jsonDiagnosticsExtension } from './jsonDiagnostics';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/diagnostics/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1 @@
1
+ export { jsonDiagnosticsExtension } from './jsonDiagnostics';
@@ -0,0 +1,4 @@
1
+ import { Extension } from '@codemirror/state';
2
+ import { JsonEditorConfig } from '../../types';
3
+ export declare const jsonDiagnosticsExtension: (options?: JsonEditorConfig) => Extension;
4
+ //# sourceMappingURL=jsonDiagnostics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonDiagnostics.d.ts","sourceRoot":"","sources":["../../../src/core/diagnostics/jsonDiagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAS9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAsE/C,eAAO,MAAM,wBAAwB,aACxB,gBAAgB,KAC1B,SAuCF,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { hoverTooltip } from '@codemirror/view';
2
+ import { linter, lintGutter } from '@codemirror/lint';
3
+ import { autocompletion, } from '@codemirror/autocomplete';
4
+ import { syntaxTree } from '@codemirror/language';
5
+ import { jsonSchemaLinter, jsonSchemaHover, jsonCompletion, stateExtensions, } from 'codemirror-json-schema';
6
+ const getErrorMessage = (view, from) => {
7
+ const doc = view.state.doc;
8
+ const charBefore = from > 0 ? doc.sliceString(from - 1, from) : '';
9
+ const charAfter = doc.sliceString(from, from + 1);
10
+ if (charBefore === ',') {
11
+ return 'Trailing comma is not allowed in JSON';
12
+ }
13
+ if (charAfter === '}' || charAfter === ']') {
14
+ return 'Missing value before closing bracket';
15
+ }
16
+ if (charAfter === ':') {
17
+ return 'Missing value after ":"';
18
+ }
19
+ if (charBefore === ':') {
20
+ return 'Missing value after ":"';
21
+ }
22
+ if (!charAfter) {
23
+ return 'Unexpected end of JSON input';
24
+ }
25
+ return 'Invalid JSON syntax';
26
+ };
27
+ const jsonLinter = (view) => {
28
+ const diagnostics = [];
29
+ const tree = syntaxTree(view.state);
30
+ const docLength = view.state.doc.length;
31
+ tree.iterate({
32
+ enter(node) {
33
+ if (!node.type.isError)
34
+ return;
35
+ const from = node.from;
36
+ const to = Math.min(node.to, docLength);
37
+ diagnostics.push({
38
+ from,
39
+ to: from === to ? from + 1 : to,
40
+ severity: 'error',
41
+ message: getErrorMessage(view, from),
42
+ });
43
+ },
44
+ });
45
+ return diagnostics;
46
+ };
47
+ const safeJsonCompletion = (schema) => {
48
+ const source = jsonCompletion(schema);
49
+ return (ctx) => {
50
+ const result = source(ctx);
51
+ return Array.isArray(result) ? null : result;
52
+ };
53
+ };
54
+ export const jsonDiagnosticsExtension = (options = {}) => {
55
+ const { diagnostics = true, gutter = true, schema, schemaLint = !!schema, hover = !!schema, autocomplete = !!schema, } = options;
56
+ const extensions = [];
57
+ if (diagnostics) {
58
+ extensions.push(linter(jsonLinter));
59
+ if (gutter) {
60
+ extensions.push(lintGutter());
61
+ }
62
+ }
63
+ if (schema) {
64
+ extensions.push(stateExtensions(schema));
65
+ if (schemaLint) {
66
+ extensions.push(linter(jsonSchemaLinter(schema)));
67
+ }
68
+ if (hover) {
69
+ extensions.push(hoverTooltip(jsonSchemaHover(schema)));
70
+ }
71
+ if (autocomplete) {
72
+ extensions.push(autocompletion({
73
+ override: [safeJsonCompletion(schema)],
74
+ }));
75
+ }
76
+ }
77
+ return extensions;
78
+ };
@@ -0,0 +1,4 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ import { CreateEditorOptions } from '../../types';
3
+ export declare const createEditor: ({ value, parent, theme, readOnly, language, languageOptions, onChange, }: CreateEditorOptions) => EditorView;
4
+ //# sourceMappingURL=createEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createEditor.d.ts","sourceRoot":"","sources":["../../../src/core/editor/createEditor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAM9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD,eAAO,MAAM,YAAY,6EAQtB,mBAAmB,eAoBrB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { EditorState } from '@codemirror/state';
2
+ import { EditorView } from '@codemirror/view';
3
+ import { basicSetup } from 'codemirror';
4
+ import { readOnlyExtension } from '../extensions';
5
+ import { buildLanguageExtensions } from '../languages';
6
+ import { getThemeExtension } from '../themes';
7
+ export const createEditor = ({ value, parent, theme, readOnly = false, language, languageOptions, onChange, }) => {
8
+ const state = EditorState.create({
9
+ doc: value,
10
+ extensions: [
11
+ basicSetup,
12
+ ...buildLanguageExtensions(language, languageOptions),
13
+ getThemeExtension(theme),
14
+ readOnlyExtension(readOnly),
15
+ EditorView.updateListener.of((update) => {
16
+ if (update.docChanged) {
17
+ onChange?.(update.state.doc.toString());
18
+ }
19
+ }),
20
+ ],
21
+ });
22
+ return new EditorView({
23
+ state,
24
+ parent,
25
+ });
26
+ };
@@ -0,0 +1,3 @@
1
+ import type { EditorController } from '../../types';
2
+ export declare function createEditorController(): EditorController;
3
+ //# sourceMappingURL=editorController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorController.d.ts","sourceRoot":"","sources":["../../../src/core/editor/editorController.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD,wBAAgB,sBAAsB,IAAI,gBAAgB,CAuBzD"}
@@ -0,0 +1,24 @@
1
+ import { copyToClipboard, foldAllCode, unfoldAllCode, formatCode, } from '../extensions';
2
+ export function createEditorController() {
3
+ let view = null;
4
+ return {
5
+ getView() {
6
+ return view;
7
+ },
8
+ setView(v) {
9
+ view = v;
10
+ },
11
+ async copy() {
12
+ return await copyToClipboard(view);
13
+ },
14
+ foldAll() {
15
+ return foldAllCode(view);
16
+ },
17
+ unfoldAll() {
18
+ return unfoldAllCode(view);
19
+ },
20
+ format(formatter) {
21
+ return formatCode(view, formatter);
22
+ },
23
+ };
24
+ }
@@ -0,0 +1,3 @@
1
+ export { createEditor } from './createEditor';
2
+ export { createEditorController } from './editorController';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createEditor } from './createEditor';
2
+ export { createEditorController } from './editorController';
@@ -0,0 +1,3 @@
1
+ import type { EditorView } from '@codemirror/view';
2
+ export declare const copyToClipboard: (view: EditorView | null | undefined) => Promise<boolean>;
3
+ //# sourceMappingURL=copy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/copy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,eAAO,MAAM,eAAe,SAClB,UAAU,GAAG,IAAI,GAAG,SAAS,KACpC,OAAO,CAAC,OAAO,CAyCjB,CAAC"}
@@ -0,0 +1,34 @@
1
+ export const copyToClipboard = async (view) => {
2
+ if (!view)
3
+ return false;
4
+ const { state } = view;
5
+ const selection = state.selection.main;
6
+ const text = selection.empty
7
+ ? state.doc.toString()
8
+ : state.doc.sliceString(selection.from, selection.to);
9
+ if (!text)
10
+ return false;
11
+ try {
12
+ if (typeof navigator !== 'undefined' &&
13
+ navigator.clipboard?.writeText) {
14
+ await navigator.clipboard.writeText(text);
15
+ return true;
16
+ }
17
+ if (typeof document !== 'undefined') {
18
+ const textarea = document.createElement('textarea');
19
+ textarea.value = text;
20
+ textarea.setAttribute('readonly', '');
21
+ textarea.style.position = 'fixed';
22
+ textarea.style.left = '-9999px';
23
+ document.body.appendChild(textarea);
24
+ textarea.select();
25
+ const success = document.execCommand('copy');
26
+ document.body.removeChild(textarea);
27
+ return success;
28
+ }
29
+ return false;
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ };
@@ -0,0 +1,4 @@
1
+ import type { EditorView } from '@codemirror/view';
2
+ export declare const foldAllCode: (view: EditorView | null | undefined) => boolean;
3
+ export declare const unfoldAllCode: (view: EditorView | null | undefined) => boolean;
4
+ //# sourceMappingURL=fold.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fold.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/fold.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGnD,eAAO,MAAM,WAAW,SAAU,UAAU,GAAG,IAAI,GAAG,SAAS,YAI9D,CAAC;AAEF,eAAO,MAAM,aAAa,SAAU,UAAU,GAAG,IAAI,GAAG,SAAS,YAIhE,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { foldAll, unfoldAll } from '@codemirror/language';
2
+ export const foldAllCode = (view) => {
3
+ if (!view)
4
+ return false;
5
+ return foldAll(view);
6
+ };
7
+ export const unfoldAllCode = (view) => {
8
+ if (!view)
9
+ return false;
10
+ return unfoldAll(view);
11
+ };
@@ -0,0 +1,3 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ export declare const formatCode: (view: EditorView | null | undefined, formatter?: (code: string) => string) => boolean;
3
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,eAAO,MAAM,UAAU,SACb,UAAU,GAAG,IAAI,GAAG,SAAS,cACvB,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,KACrC,OA2BF,CAAC"}
@@ -0,0 +1,25 @@
1
+ export const formatCode = (view, formatter) => {
2
+ if (!view || !formatter)
3
+ return false;
4
+ const { state } = view;
5
+ const selection = state.selection.main;
6
+ const from = selection.empty ? 0 : selection.from;
7
+ const to = selection.empty ? state.doc.length : selection.to;
8
+ const text = state.doc.sliceString(from, to);
9
+ if (!text)
10
+ return false;
11
+ try {
12
+ const formatted = formatter(text);
13
+ view.dispatch({
14
+ changes: { from, to, insert: formatted },
15
+ selection: {
16
+ anchor: from + formatted.length,
17
+ },
18
+ });
19
+ return true;
20
+ }
21
+ catch (error) {
22
+ console.error('Formatting error:', error);
23
+ return false;
24
+ }
25
+ };
@@ -0,0 +1,5 @@
1
+ export { copyToClipboard } from './copy';
2
+ export { foldAllCode, unfoldAllCode } from './fold';
3
+ export { formatCode } from './format';
4
+ export { readOnlyExtension } from './readOnly';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { copyToClipboard } from './copy';
2
+ export { foldAllCode, unfoldAllCode } from './fold';
3
+ export { formatCode } from './format';
4
+ export { readOnlyExtension } from './readOnly';
@@ -0,0 +1,2 @@
1
+ export declare const readOnlyExtension: (readOnly: boolean) => import("@codemirror/state").Extension;
2
+ //# sourceMappingURL=readOnly.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readOnly.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/readOnly.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,aAAc,OAAO,0CAElD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ export const readOnlyExtension = (readOnly) => {
3
+ return EditorView.editable.of(!readOnly);
4
+ };
@@ -0,0 +1,3 @@
1
+ import { CodeEditorProps, ResolvedControlledInvariant } from '../../types';
2
+ export declare const resolveControlledInvariant: (props: CodeEditorProps) => ResolvedControlledInvariant;
3
+ //# sourceMappingURL=controlled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controlled.d.ts","sourceRoot":"","sources":["../../../src/core/invariants/controlled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAI3E,eAAO,MAAM,0BAA0B,UAC5B,eAAe,KACvB,2BA4BF,CAAC"}
@@ -0,0 +1,23 @@
1
+ const __DEV__ = process.env.NODE_ENV !== 'production';
2
+ export const resolveControlledInvariant = (props) => {
3
+ const { value, defaultValue } = props;
4
+ const isControlled = value !== undefined;
5
+ if (__DEV__) {
6
+ if (value !== undefined && defaultValue !== undefined) {
7
+ console.warn('CodeEditor: Do not use both value and defaultValue.');
8
+ }
9
+ if (value === undefined && defaultValue === undefined) {
10
+ console.warn('CodeEditor: Either value or defaultValue should be provided.');
11
+ }
12
+ if (value !== undefined && typeof value !== 'string') {
13
+ throw new Error('CodeEditor: value must be a string.');
14
+ }
15
+ if (defaultValue !== undefined && typeof defaultValue !== 'string') {
16
+ throw new Error('CodeEditor: defaultValue must be a string.');
17
+ }
18
+ }
19
+ return {
20
+ mode: isControlled ? 'controlled' : 'uncontrolled',
21
+ value: isControlled ? value : (defaultValue ?? ''),
22
+ };
23
+ };
@@ -0,0 +1,2 @@
1
+ export { resolveControlledInvariant } from './controlled';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/invariants/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1 @@
1
+ export { resolveControlledInvariant } from './controlled';
@@ -0,0 +1,4 @@
1
+ import { Extension } from '@codemirror/state';
2
+ import { EditorLanguage, LanguageOptions } from '../../types';
3
+ export declare const buildLanguageExtensions: (language: EditorLanguage, options: LanguageOptions | undefined) => Extension[];
4
+ //# sourceMappingURL=buildExtensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildExtensions.d.ts","sourceRoot":"","sources":["../../../src/core/languages/buildExtensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAK9D,eAAO,MAAM,uBAAuB,aACtB,cAAc,WACf,eAAe,GAAG,SAAS,KACrC,SAAS,EAUX,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { jsonLanguage } from '.';
2
+ import { jsonDiagnosticsExtension } from '../diagnostics';
3
+ export const buildLanguageExtensions = (language, options) => {
4
+ switch (language) {
5
+ case 'json':
6
+ return [
7
+ jsonLanguage(),
8
+ jsonDiagnosticsExtension(options?.[language] ?? {}),
9
+ ];
10
+ default:
11
+ return [];
12
+ }
13
+ };
@@ -0,0 +1,3 @@
1
+ export { jsonLanguage } from './json';
2
+ export { buildLanguageExtensions } from './buildExtensions';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/languages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { jsonLanguage } from './json';
2
+ export { buildLanguageExtensions } from './buildExtensions';
@@ -0,0 +1,3 @@
1
+ import { Extension } from '@codemirror/state';
2
+ export declare const jsonLanguage: () => Extension;
3
+ //# sourceMappingURL=json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../src/core/languages/json.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,eAAO,MAAM,YAAY,QAAO,SAE/B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { json } from '@codemirror/lang-json';
2
+ export const jsonLanguage = () => {
3
+ return json();
4
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Theme inspired by Thememirror
3
+ * https://github.com/vadimdemedes/thememirror
4
+ * MIT License
5
+ */
6
+ import { HighlightStyle } from '@codemirror/language';
7
+ export declare const barfDarkTheme: import("@codemirror/state").Extension;
8
+ export declare const barfDarkHighlight: HighlightStyle;
9
+ //# sourceMappingURL=barf.d.ts.map