@kong-ui-public/monaco-editor 0.7.3 → 0.7.4

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 +212 -7
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -1,29 +1,234 @@
1
1
  # @kong-ui-public/monaco-editor
2
2
 
3
- TBD
3
+ A kong UI Monaco Editor wrapper for Vue 3 with syntax highlighting powered by Shiki.
4
4
 
5
5
  - [Features](#features)
6
6
  - [Requirements](#requirements)
7
7
  - [Usage](#usage)
8
8
  - [Install](#install)
9
- - [Props](#props)
9
+ - [Register](#register)
10
+ - [MonacoEditor Component](#monacoeditor-component)
11
+ - [Props](#props)
12
+ - [v-model](#v-model)
13
+ - [Slots](#slots)
14
+ - [Usage Example](#usage-example)
15
+ - [useMonacoEditor Composable](#usemonacoeditor-composable)
16
+ - [Vite Plugin](#vite-plugin)
10
17
 
11
18
  ## Features
12
19
 
13
- TBD
20
+ - Vue 3 wrapper component for [Monaco Editor](https://microsoft.github.io/monaco-editor/)
21
+ - Syntax highlighting powered by [Shiki](https://shiki.matsu.io/)
22
+ - Two-way data binding with `v-model`
23
+ - TypeScript support
24
+ - Light and dark themes
25
+ - Customizable editor options
26
+ - Loading and empty states with customizable slots
27
+ - Composable API for advanced use cases
28
+ - Vite plugin for optimized builds
14
29
 
15
30
  ## Requirements
16
31
 
17
- TBD
32
+ - `vue` must be initialized in the host application
33
+ - `@kong/kongponents` must be available as a `dependency` in the host application (for icons)
18
34
 
19
35
  ## Usage
20
36
 
21
37
  ### Install
22
38
 
23
- ```bash
24
- pnpm i @kong-ui-public/monaco-editor
39
+ Install the package in your host application
40
+
41
+ ```sh
42
+ pnpm add @kong-ui-public/monaco-editor
43
+ ```
44
+
45
+ Import the styles in your application:
46
+
47
+ ```typescript
48
+ import '@kong-ui-public/monaco-editor/dist/runtime/style.css'
49
+ ```
50
+
51
+ or if you prefer css
52
+
53
+ ```css
54
+ @import "@kong-ui-public/monaco-editor/dist/runtime/style.css";
55
+ ```
56
+
57
+ ### Register
58
+
59
+ You can register the `MonacoEditor` component globally or import it locally in your components.
60
+
61
+ #### Global Registration
62
+
63
+ ```typescript
64
+ import { createApp } from 'vue'
65
+ import { MonacoEditor } from '@kong-ui-public/monaco-editor'
66
+
67
+ const app = createApp(App)
68
+
69
+ app.component('MonacoEditor', MonacoEditor)
25
70
  ```
26
71
 
72
+ #### Local Registration
73
+
74
+ ```vue
75
+ <script setup lang="ts">
76
+ import { MonacoEditor } from '@kong-ui-public/monaco-editor'
77
+ </script>
78
+ ```
79
+
80
+ ## MonacoEditor Component
81
+
27
82
  ### Props
28
83
 
29
- TBD
84
+ #### `theme`
85
+
86
+ - type: `'light' | 'dark'`
87
+ - required: `false`
88
+ - default: `'light'`
89
+
90
+ The theme of the Monaco Editor instance.
91
+
92
+ #### `language`
93
+
94
+ - type: `string`
95
+ - required: `false`
96
+ - default: `'markdown'`
97
+
98
+ The programming language for syntax highlighting. Supports all languages available in [Shiki](https://shiki.matsu.io/languages).
99
+
100
+ #### `loading`
101
+
102
+ - type: `boolean`
103
+ - required: `false`
104
+ - default: `false`
105
+
106
+ Whether the editor is in a loading state. When true, displays a loading overlay.
107
+
108
+ #### `options`
109
+
110
+ - type: `Partial<editor.IStandaloneEditorConstructionOptions>`
111
+ - required: `false`
112
+ - default: `undefined`
113
+
114
+ Additional Monaco Editor options to customize the editor further. See [Monaco Editor API](https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IStandaloneEditorConstructionOptions.html) for available options.
115
+
116
+ ### v-model
117
+
118
+ The component requires a `v-model` binding to manage the editor content:
119
+
120
+ ```vue
121
+ <MonacoEditor v-model="code" />
122
+ ```
123
+
124
+ ### Slots
125
+
126
+ #### `state-loading`
127
+
128
+ Slot for customizing the loading state overlay. Receives `isLoading` as a slot prop.
129
+
130
+ ```vue
131
+ <MonacoEditor v-model="code">
132
+ <template #state-loading="{ isLoading }">
133
+ <div v-if="isLoading">Custom loading...</div>
134
+ </template>
135
+ </MonacoEditor>
136
+ ```
137
+
138
+ #### `state-empty`
139
+
140
+ Slot for customizing the empty state overlay. Receives `isEmpty` as a slot prop.
141
+
142
+ ```vue
143
+ <MonacoEditor v-model="code">
144
+ <template #state-empty="{ isEmpty }">
145
+ <div v-if="isEmpty">Custom empty state...</div>
146
+ </template>
147
+ </MonacoEditor>
148
+ ```
149
+
150
+ ### Usage Example
151
+
152
+ ```vue
153
+ <template>
154
+ <div class="editor-wrapper">
155
+ <MonacoEditor
156
+ v-model="code"
157
+ :theme="isDark ? 'dark' : 'light'"
158
+ language="json"
159
+ :options="{
160
+ readOnly: false,
161
+ minimap: {
162
+ enabled: false,
163
+ },
164
+ }"
165
+ />
166
+ </div>
167
+ </template>
168
+
169
+ <script setup lang="ts">
170
+ import { ref } from 'vue'
171
+ import { MonacoEditor } from '@kong-ui-public/monaco-editor'
172
+
173
+ const code = ref('{\n "hello": "world"\n}')
174
+ const isDark = ref(false)
175
+ </script>
176
+
177
+ <style scoped>
178
+ .editor-wrapper {
179
+ height: 500px;
180
+ width: 100%;
181
+ }
182
+ </style>
183
+ ```
184
+
185
+ ## useMonacoEditor Composable
186
+
187
+ For advanced use cases, you can use the `useMonacoEditor` composable directly:
188
+
189
+ ```typescript
190
+ import { useMonacoEditor } from '@kong-ui-public/monaco-editor'
191
+
192
+ const monacoEditor = useMonacoEditor(editorRef, {
193
+ language: 'javascript',
194
+ code: codeRef,
195
+ theme: 'light',
196
+ monacoOptions: {
197
+ readOnly: false,
198
+ minimap: {
199
+ enabled: false,
200
+ },
201
+ },
202
+ })
203
+
204
+ // Access editor states
205
+ console.log(monacoEditor.editorStates.hasContent)
206
+
207
+ // Access editor methods
208
+ monacoEditor.setContent('new content')
209
+ monacoEditor.focus()
210
+ ```
211
+
212
+ ## Vite Plugin
213
+
214
+ This package includes a Vite plugin for optimized builds. The plugin reduces bundle size by allowing you to selectively include only the languages and features you need.
215
+
216
+ ```typescript
217
+ import { defineConfig } from 'vite'
218
+ import MonacoVitePlugin from '@kong-ui-public/monaco-editor/vite-plugin'
219
+
220
+ export default defineConfig({
221
+ plugins: [
222
+ MonacoVitePlugin({
223
+ languages: ['json', 'yaml', 'javascript'],
224
+ features: ['bracketMatching', 'comment', 'format'],
225
+ shiki: {
226
+ langs: ['json', 'yaml', 'javascript'],
227
+ themes: ['catppuccin-latte', 'catppuccin-mocha'],
228
+ },
229
+ }),
230
+ ],
231
+ })
232
+ ```
233
+
234
+ For more details on configuration options, see the [Vite Plugin README](https://github.com/Kong/public-ui-components/blob/main/packages/core/monaco-editor/vite-plugin/README.md).
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@kong-ui-public/monaco-editor",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "type": "module",
5
+ "description": "A kong UI Monaco Editor wrapper for Vue 3 with syntax highlighting powered by Shiki.",
5
6
  "main": "./dist/runtime/monaco-editor.umd.js",
6
7
  "module": "./dist/runtime/monaco-editor.es.js",
7
8
  "types": "./dist/types/src/index.d.ts",