monacozen 0.0.1 → 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/README.md +219 -0
- package/assets/antimono-ClsI0fxy.js +5 -0
- package/assets/antimono-zBXMptjq.css +1 -0
- package/assets/bat-T2vjbQzY.js +125 -0
- package/assets/bicep-B6UDBWZN.js +220 -0
- package/assets/clojure-BvXzD8Uz.js +148 -0
- package/assets/coffee-D_yet6sT.js +262 -0
- package/assets/cpp-CsfEADPM.js +232 -0
- package/assets/csharp-jw3fFksF.js +262 -0
- package/assets/css-FsiUe-xI.js +286 -0
- package/assets/css.worker-BIsSvM_Q.js +96 -0
- package/assets/css.worker-BSHdDU9y.js +6 -0
- package/assets/cssMode-7U-ime2d.js +65 -0
- package/assets/cypher-B8DgU2PH.js +214 -0
- package/assets/dart-D1x60wEn.js +238 -0
- package/assets/dist-Bx9hOuoB.js +624 -0
- package/assets/dockerfile-DSHxsy4G.js +193 -0
- package/assets/editor.api-ZYFspLPt.js +85776 -0
- package/assets/editorWebWorkerMain-BioN9fGU.js +33 -0
- package/assets/editorWebWorkerMain-DXr8-Jst.js +6 -0
- package/assets/elixir-Cr7BtjRU.js +525 -0
- package/assets/fsharp-CeVKIr0d.js +149 -0
- package/assets/go-BL4_0srD.js +167 -0
- package/assets/graphql-mhWekwK0.js +176 -0
- package/assets/handlebars-rQdtgZoQ.js +412 -0
- package/assets/hcl-CfyDj6z_.js +221 -0
- package/assets/html-DIDrd2Z7.js +333 -0
- package/assets/html.worker-BrBx6eB3.js +6 -0
- package/assets/html.worker-CEvqvEpu.js +509 -0
- package/assets/htmlMode-i6u-9r7u.js +74 -0
- package/assets/ini-DhiXkl_g.js +96 -0
- package/assets/java-Ct9YHm5L.js +175 -0
- package/assets/javascript-By915NHa.js +20 -0
- package/assets/json.worker-B0PzJ5jL.js +6 -0
- package/assets/json.worker-CAiVr-gV.js +65 -0
- package/assets/jsonMode-DAP8CNa2.js +450 -0
- package/assets/julia-BAYXm_pL.js +416 -0
- package/assets/kotlin-JEujETri.js +184 -0
- package/assets/less-oHZXXDVD.js +244 -0
- package/assets/liquid-Cvs1eMgo.js +199 -0
- package/assets/lspLanguageFeatures-D6P77uh_.js +1455 -0
- package/assets/lua-B3ViXcD8.js +202 -0
- package/assets/main-16cPxgwS.js +107 -0
- package/assets/main-CB71Lf5W.js +129 -0
- package/assets/main-HEYSEiwe.js +66 -0
- package/assets/markdown-Ggb6Rgvc.js +264 -0
- package/assets/mdx-Ce7sXDA4.js +329 -0
- package/assets/mips-cYdfQChM.js +130 -0
- package/assets/monaco-d37b1a8f.css +3 -0
- package/assets/monaco-o5F6wkXp.js +40865 -0
- package/assets/mysql-nklBC2QL.js +170 -0
- package/assets/objective-c-x5BzCYEv.js +146 -0
- package/assets/pascal-DWL5ya_C.js +178 -0
- package/assets/perl-CbRoLks6.js +318 -0
- package/assets/pgsql-CVS-AsDB.js +160 -0
- package/assets/php-6gZIubF1.js +473 -0
- package/assets/powershell-DKgJI7BG.js +213 -0
- package/assets/protobuf-N0VyW3k9.js +661 -0
- package/assets/pug-BIMEUctf.js +302 -0
- package/assets/python-BKt2Winm.js +254 -0
- package/assets/r-Cb2uCcX6.js +191 -0
- package/assets/redis-D1CRAuQ1.js +125 -0
- package/assets/ruby-BzpgsYNr.js +529 -0
- package/assets/rust-CkIXqWDr.js +180 -0
- package/assets/scala-CnJ7htCu.js +553 -0
- package/assets/scss-xP2eAFyY.js +419 -0
- package/assets/shell-JSjWPSrk.js +225 -0
- package/assets/solidity-C8AFhoIi.js +149 -0
- package/assets/sql-DqW-LmZI.js +173 -0
- package/assets/swift-BcHKQY-M.js +215 -0
- package/assets/systemverilog-Dmu-Ht4V.js +300 -0
- package/assets/ts.worker-BAchZA3W.js +6 -0
- package/assets/ts.worker-DZhhT1EO.js +67741 -0
- package/assets/tsMode-C_Fsqh0j.js +566 -0
- package/assets/twig-Bj4rwioa.js +390 -0
- package/assets/typescript-Djsb1cC9.js +257 -0
- package/assets/typespec-xwJ6QpRP.js +236 -0
- package/assets/vb-CMxAjmFH.js +262 -0
- package/assets/wgsl-CTYGQRo2.js +147 -0
- package/assets/xml-D7cJD5hW.js +130 -0
- package/assets/yaml-B8A0QdVf.js +223 -0
- package/assets/yaml.worker-Crtsysk5.js +474 -0
- package/assets/yaml.worker-DZ36155v.js +6 -0
- package/lib.d.ts +8403 -0
- package/lib.js +2 -0
- package/package.json +1 -1
- package/src/main.js +29 -0
- package/index.d.ts +0 -6
- package/index.js +0 -1
- package/readme.md +0 -1
- /package/{license.txt → LICENSE} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
<center><a href="https://npmjs.com/package/monacozen"><img src="https://shieldcn.dev/npm/v/monacozen.svg?variant=secondary&logo=npm&label=latest+version" alt="Latest version on npm"/></a> <a href="https://github.com/Jaid/monacozen/raw/HEAD/license.txt"><img src="https://shieldcn.dev/github/license/Jaid/monacozen.svg?variant=secondary" alt="License"/></a> <a href="https://bun.sh"><picture><source media="(prefers-color-scheme: dark)" srcset="https://shieldcn.dev/badge/Bun-fbf0df.svg?variant=outline&logo=bun&logoColor=fbf0df&mode=dark"><img src="https://shieldcn.dev/badge/Bun-fbf0df.svg?variant=outline&logo=bun&logoColor=fbf0df&mode=light" alt="Bun"/></picture></a></center>
|
|
2
|
+
|
|
3
|
+
# Monacozen
|
|
4
|
+
|
|
5
|
+
text editor component with batteries included and UI clutter removed
|
|
6
|
+
|
|
7
|
+
## installation
|
|
8
|
+
|
|
9
|
+
<a href="https://npmjs.com/package/monacozen"><img src="https://shieldcn.dev/badge/npm-monacozen-C23039.svg?variant=secondary&logo=npm" alt="monacozen on npm"/></a>
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install --save monacozen
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## example
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import {useState} from 'react'
|
|
19
|
+
import Monacozen from 'monacozen'
|
|
20
|
+
|
|
21
|
+
const [text, setText] = useState<string>('')
|
|
22
|
+
|
|
23
|
+
<Monacozen
|
|
24
|
+
language='typescript'
|
|
25
|
+
value={text}
|
|
26
|
+
onChange={value => setText(value ?? '')}
|
|
27
|
+
/>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## usage
|
|
31
|
+
|
|
32
|
+
### Monaco editor
|
|
33
|
+
|
|
34
|
+
`monaco` replaces the former `options` prop. Omit it to use the shared defaults or pass an options object to override them. `fontFamily` and `disableMonospaceOptimizations` are excluded because the `font` prop controls them. Padding is not part of the shared defaults.
|
|
35
|
+
|
|
36
|
+
The existing Monaco props, including `beforeMount`, `onMount`, `onChange`, `onValidate`, model paths, language settings and view-state options, remain available in Monaco mode. Ordinary DOM events such as `onFocus`, `onBlur`, `onKeyDown`, `onPaste` and `onContextMenu` are handled on the enclosing element and bubble from the editor. `wrapperProps` provides additional wrapper attributes.
|
|
37
|
+
|
|
38
|
+
The common `readOnly`, `disabled`, `placeholder`, `autoFocus` and `aria-label` props work in both modes. Explicit common props take precedence over the corresponding Monaco options.
|
|
39
|
+
|
|
40
|
+
### native editor
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
<Monacozen
|
|
44
|
+
monaco={false}
|
|
45
|
+
font='mono'
|
|
46
|
+
name='query'
|
|
47
|
+
placeholder='Enter text'
|
|
48
|
+
value={text}
|
|
49
|
+
onChange={value => setText(value)}
|
|
50
|
+
onKeyDown={event => {
|
|
51
|
+
if (event.key === 'Escape') event.currentTarget.blur()
|
|
52
|
+
}}
|
|
53
|
+
/>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`monaco={false}` renders `DummyEditor`, a multiline `<textarea>`. It does not load Monaco JavaScript, Monaco CSS or workers. Native input props such as `name`, `required`, `maxLength`, `readOnly`, `disabled` and `ref` are supported.
|
|
57
|
+
|
|
58
|
+
The native component is also a named export:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import {DummyEditor} from 'monacozen'
|
|
62
|
+
|
|
63
|
+
<DummyEditor defaultValue='Hello' onMount={textarea => textarea.select()} />
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Native `onChange` receives `(value, event)`, with a string value and the actual React textarea change event. Native `onMount` receives the textarea itself. Focus, keyboard, input, selection, composition, clipboard, pointer, mouse and other native `on*` handlers are forwarded to that element. Monaco-only lifecycle callbacks are not synthesized for a textarea.
|
|
67
|
+
|
|
68
|
+
A dynamically selected mode is supported too:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
<Monacozen
|
|
72
|
+
monaco={useMonaco ? {wordWrap: 'on'} : false}
|
|
73
|
+
value={text}
|
|
74
|
+
onChange={value => setText(value ?? '')}
|
|
75
|
+
/>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Uncontrolled text is retained when switching modes. For controlled input, keep supplying `value`. The callback types reflect the backend: a dynamically selected mode has a change-event union and an `onMount` callback that may receive either editor kind. Use `SwitchableEditorProps` when explicitly typing a dynamically selected mode.
|
|
79
|
+
|
|
80
|
+
### appearance
|
|
81
|
+
|
|
82
|
+
`dark` defaults to `true`. Monaco uses the bundled, modified `vs-dark` theme with a black background. `dark={false}` selects its light theme. The native editor uses white text on black or black text on white.
|
|
83
|
+
|
|
84
|
+
`font` defaults to `antimono` and also accepts `mono` for the system monospace font or `dense` for the system sans-serif font. Both backends support `height`, `width`, `className` and `style`.
|
|
85
|
+
|
|
86
|
+
## advanced usage
|
|
87
|
+
|
|
88
|
+
### loading
|
|
89
|
+
|
|
90
|
+
Importing Monacozen does not initialize Monaco or load either stylesheet. Rendering the Monaco backend starts the React adapter and Monaco imports concurrently. A Suspense boundary displays the `loading` prop while they load. Monaco’s stylesheet belongs to its lazy chunks rather than the public entry, so it is fetched before the editor mounts.
|
|
91
|
+
|
|
92
|
+
Antimono has a separate stylesheet and lazy import. It is loaded only when a mounted editor selects `font='antimono'`, including when that selection comes from the default. Selecting `mono` or `dense` alone does not load it. Once the font finishes loading, mounted Monaco editors remeasure their font metrics.
|
|
93
|
+
|
|
94
|
+
Modules and styles are reused across instances and mode changes. Styles are not removed when a component unmounts. Language workers are constructed on demand; an existing `MonacoEnvironment` worker configuration is respected. Loading errors can be handled by the application’s React error boundary.
|
|
95
|
+
|
|
96
|
+
### schemas
|
|
97
|
+
|
|
98
|
+
The language-agnostic `schema` prop accepts a JSON Schema object. Monacozen applies it when the active model has a schema-aware language service. JSON and YAML are supported out of the box; unsupported languages and the native textarea backend simply ignore the prop.
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
const schema = {
|
|
102
|
+
type: 'object',
|
|
103
|
+
additionalProperties: false,
|
|
104
|
+
properties: {
|
|
105
|
+
name: {
|
|
106
|
+
type: 'string',
|
|
107
|
+
description: 'Display name.',
|
|
108
|
+
},
|
|
109
|
+
enabled: {type: 'boolean'},
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
<Monacozen language='yaml' schema={schema} value={text} />
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The association follows the active Monaco model, including model and language changes, and is removed when `schema` is unset or the editor is disposed. This also works directly with JSON Schema objects generated by libraries such as Zod. Schema-aware completion, hover documentation and diagnostics are provided by the active language service.
|
|
117
|
+
|
|
118
|
+
YAML additionally includes Prettier formatting. Standard YAML language-server schema comments remain supported when no `schema` prop is supplied:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
<Monacozen
|
|
122
|
+
language='yaml'
|
|
123
|
+
path='file:///.prettierrc.yaml'
|
|
124
|
+
defaultValue={'# yaml-language-server: $schema=https://json.schemastore.org/prettierrc.json\nsingleQuote: true\nproseWrap: always\n'}
|
|
125
|
+
/>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Remote schemas and references are fetched on demand. Remote servers must allow browser requests from your application's origin. An inline `schema` can use internal fragment references and absolute remote `$ref` values; use a URL-backed YAML schema comment when relative external references need a URL base. Filenames alone do not enable automatic SchemaStore catalog lookup.
|
|
129
|
+
|
|
130
|
+
The YAML language service is registered once for the shared Monaco instance, and its bundled worker starts only when YAML is used. Consumers do not need to install `monaco-yaml` or add a YAML worker to their bundler configuration. As with other language workers, applications supplying their own `MonacoEnvironment.getWorker` or `getWorkerUrl` remain responsible for handling the `yaml` label.
|
|
131
|
+
|
|
132
|
+
### additional languages
|
|
133
|
+
|
|
134
|
+
Set `language` to one of these IDs:
|
|
135
|
+
|
|
136
|
+
| ID | Language | Extension |
|
|
137
|
+
|---|---|---|
|
|
138
|
+
| `logsql` | VictoriaLogs LogsQL | `.logsql` |
|
|
139
|
+
| `metricsql` | VictoriaMetrics MetricsQL | `.metricsql` |
|
|
140
|
+
| `clank` | Clank, as emitted by `stringify-clank` | `.clank` |
|
|
141
|
+
|
|
142
|
+
Each definition has its own lazy chunk. Registration metadata is available when Monaco loads; the tokenizer and editor configuration load when that language is used.
|
|
143
|
+
|
|
144
|
+
The definitions provide syntax highlighting and basic editing configuration, not query execution, schema validation or a language server. LogsQL and MetricsQL cover their query operators, keywords, field or label names, calls, numeric values, durations, comments and quoted strings. Clank follows its whitespace-delimited format, including bare strings, special values, raw single-quoted strings and escaped double-quoted strings. It does not invent JSON commas, colons or comments.
|
|
145
|
+
|
|
146
|
+
The Monaco build continues to exclude `abap`, `apex`, `lexon`, `sb` and `flow9`.
|
|
147
|
+
|
|
148
|
+
## props
|
|
149
|
+
|
|
150
|
+
option | type | default | info
|
|
151
|
+
--- | --- | --- | ---
|
|
152
|
+
`className` | `string` | | class name for the active editor element or Monaco wrapper
|
|
153
|
+
`aria-label` | `string` | | accessible label for both backends; mapped to Monaco’s ariaLabel option
|
|
154
|
+
`autoFocus` | `boolean` | `false` | Focuses the active editor after mounting.
|
|
155
|
+
`beforeMount` | `(monaco: MonacoApi) => void` | | callback after Monaco loads and before editor creation
|
|
156
|
+
`dark` | `boolean` | `true` | dark or light appearance
|
|
157
|
+
`defaultLanguage` | `string` | | language for newly created Monaco models
|
|
158
|
+
`defaultPath` | `string` | | path for newly created Monaco models
|
|
159
|
+
`defaultValue` | `string` | `''` | initial value for uncontrolled usage and backend switching
|
|
160
|
+
`disabled` | `boolean` | `false` | Disables editing; Monaco also receives domReadOnly.
|
|
161
|
+
`font` | `'antimono' \| 'dense' \| 'mono'` | `'antimono'` | Antimono, system sans-serif or system monospace font
|
|
162
|
+
`height` | `number \| string` | `'100%'`
|
|
163
|
+
`keepCurrentModel` | `boolean` | `false` | Keeps the current Monaco model alive after unmounting.
|
|
164
|
+
`language` | `string` | | current Monaco model language
|
|
165
|
+
`line` | `number` | | line to reveal in Monaco
|
|
166
|
+
`loading` | `ReactNode` | `'Loading…'` | Suspense fallback while the Monaco backend loads
|
|
167
|
+
`monaco` | `MonacoOptions \| boolean` | | Omit for the Monaco backend with shared defaults; false uses DummyEditor and true is shorthand for an empty Monaco options object.
|
|
168
|
+
`overrideServices` | `Monaco.editor.IEditorOverrideServices` | `{}` | Monaco editor service overrides passed to [@monaco-editor/react](https://npmx.dev/package/@monaco-editor/react)
|
|
169
|
+
`path` | `string` | | current Monaco model path
|
|
170
|
+
`placeholder` | `string` | | placeholder text supported by both backends
|
|
171
|
+
`readOnly` | `boolean` | `false` | editor read-only state
|
|
172
|
+
`saveViewState` | `boolean` | `true` | Saves and restores Monaco model view state between model changes.
|
|
173
|
+
`schema` | `EditorSchema` | | JSON Schema applied to supported Monaco languages such as JSON and YAML; ignored elsewhere.
|
|
174
|
+
`style` | `CSSProperties` | | inline styles applied after the width and height defaults
|
|
175
|
+
`value` | `string` | | controlled editor value
|
|
176
|
+
`width` | `number \| string` | `'100%'`
|
|
177
|
+
`wrapperProps` | `HTMLAttributes<HTMLDivElement>` | | attributes for the enclosing wrapper element
|
|
178
|
+
`ref` | `Ref<HTMLTextAreaElement>` | | native textarea ref when monaco is false
|
|
179
|
+
`onChange` | `(value: string \| undefined, event: ChangeEvent<HTMLTextAreaElement> \| Monaco.editor.IModelContentChangedEvent) => void` | | Called when the editor value changes; the native backend always provides a string.
|
|
180
|
+
`onMount` | `(editor: HTMLTextAreaElement \| Monaco.editor.IStandaloneCodeEditor, monaco?: MonacoApi) => void` | | Called after the active backend mounts.
|
|
181
|
+
`onValidate` | `(markers: Monaco.editor.IMarker[]) => void` | | callback when validation markers for the current model change
|
|
182
|
+
|
|
183
|
+
## development
|
|
184
|
+
|
|
185
|
+
### setting up
|
|
186
|
+
|
|
187
|
+
```sh
|
|
188
|
+
git clone git@github.com:Jaid/monacozen.git
|
|
189
|
+
cd monacozen
|
|
190
|
+
bun install
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### linting
|
|
194
|
+
|
|
195
|
+
```sh
|
|
196
|
+
bun run lint
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### type checking
|
|
200
|
+
|
|
201
|
+
```sh
|
|
202
|
+
bun run typecheck
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### testing
|
|
206
|
+
|
|
207
|
+
```sh
|
|
208
|
+
bun run test
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## license
|
|
212
|
+
|
|
213
|
+
[MIT License](https://github.com/Jaid/monacozen/raw/HEAD/license.txt)<br>
|
|
214
|
+
Copyright © 2026, Jaid \<jaid.jsx@gmail.com> (https://github.com/jaid)
|
|
215
|
+
|
|
216
|
+
<!---
|
|
217
|
+
Readme generated with tldw v8.0.3 from ./docs/tldw
|
|
218
|
+
https://github.com/Jaid/tldw
|
|
219
|
+
-->
|