@kong-ui-public/monaco-editor 0.4.11-pr.2769.31aadbf56.0 → 0.5.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/dist/runtime/monaco-editor.es.js +168 -209
- package/dist/runtime/monaco-editor.umd.js +1 -1
- package/dist/types/src/components/MonacoEditor.vue.d.ts.map +1 -1
- package/dist/types/src/components/MonacoEditorStatusOverlay.vue.d.ts.map +1 -1
- package/dist/types/src/composables/useMonacoEditor.d.ts +2 -2
- package/dist/types/src/composables/useMonacoEditor.d.ts.map +1 -1
- package/dist/types/vite-plugin/index.d.ts +32 -1
- package/dist/types/vite-plugin/index.d.ts.map +1 -1
- package/dist/vite-plugin/index.cjs +68 -49
- package/dist/vite-plugin/index.js +68 -49
- package/package.json +8 -4
- package/dist/types/src/singletons/index.d.ts +0 -2
- package/dist/types/src/singletons/index.d.ts.map +0 -1
- package/dist/types/src/singletons/lifecycle.d.ts +0 -31
- package/dist/types/src/singletons/lifecycle.d.ts.map +0 -1
|
@@ -1,49 +1,10 @@
|
|
|
1
|
-
import { toValue as
|
|
2
|
-
import { ProgressIcon as
|
|
3
|
-
import * as
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function se(o, t) {
|
|
9
|
-
function e(...r) {
|
|
10
|
-
return new Promise((n, i) => {
|
|
11
|
-
Promise.resolve(o(() => t.apply(this, r), {
|
|
12
|
-
fn: t,
|
|
13
|
-
thisArg: this,
|
|
14
|
-
args: r
|
|
15
|
-
})).then(n).catch(i);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return e;
|
|
19
|
-
}
|
|
20
|
-
function le(o, t = {}) {
|
|
21
|
-
let e, r, n = R;
|
|
22
|
-
const i = (l) => {
|
|
23
|
-
clearTimeout(l), n(), n = R;
|
|
24
|
-
};
|
|
25
|
-
let s;
|
|
26
|
-
return (l) => {
|
|
27
|
-
const C = _(o), c = _(t.maxWait);
|
|
28
|
-
return e && i(e), C <= 0 || c !== void 0 && c <= 0 ? (r && (i(r), r = void 0), Promise.resolve(l())) : new Promise((S, a) => {
|
|
29
|
-
n = t.rejectOnCancel ? a : S, s = l, c && !r && (r = setTimeout(() => {
|
|
30
|
-
e && i(e), r = void 0, S(s());
|
|
31
|
-
}, c)), e = setTimeout(() => {
|
|
32
|
-
r && i(r), r = void 0, S(l());
|
|
33
|
-
}, C);
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
// @__NO_SIDE_EFFECTS__
|
|
38
|
-
function ce(o, t = 200, e = {}) {
|
|
39
|
-
return se(le(t, e), o);
|
|
40
|
-
}
|
|
41
|
-
function de(o) {
|
|
42
|
-
var t;
|
|
43
|
-
const e = _(o);
|
|
44
|
-
return (t = e == null ? void 0 : e.$el) !== null && t !== void 0 ? t : e;
|
|
45
|
-
}
|
|
46
|
-
const ue = "'JetBrains Mono', Consolas, monospace", me = "12px", fe = "500", ge = "20px", ve = Object.freeze({
|
|
1
|
+
import { toValue as S, ref as B, reactive as D, onMounted as P, onActivated as U, onBeforeUnmount as V, watch as j, defineComponent as W, resolveComponent as K, createBlock as _, openBlock as y, createSlots as A, withCtx as b, resolveDynamicComponent as H, mergeModels as $, useModel as z, useTemplateRef as G, computed as M, createElementBlock as q, normalizeClass as J, unref as u, createElementVNode as Q, renderSlot as T, createVNode as I, Transition as k, createCommentVNode as w } from "vue";
|
|
2
|
+
import { ProgressIcon as Y, CodeblockIcon as Z } from "@kong/icons";
|
|
3
|
+
import * as m from "monaco-editor";
|
|
4
|
+
import { shikiToMonaco as X } from "@shikijs/monaco";
|
|
5
|
+
import { getSingletonHighlighter as ee, bundledLanguages as te, bundledThemes as oe } from "shiki";
|
|
6
|
+
import { createI18n as ne, i18nTComponent as ae } from "@kong-ui-public/i18n";
|
|
7
|
+
const re = "'JetBrains Mono', Consolas, monospace", ie = "12px", se = "500", le = "20px", ce = Object.freeze({
|
|
47
8
|
autoClosingQuotes: "always",
|
|
48
9
|
automaticLayout: !0,
|
|
49
10
|
// Auto resize layout
|
|
@@ -52,10 +13,10 @@ const ue = "'JetBrains Mono', Consolas, monospace", me = "12px", fe = "500", ge
|
|
|
52
13
|
},
|
|
53
14
|
hideCursorInOverviewRuler: !0,
|
|
54
15
|
// hide the cursor position in the minimap TODO: maybe hide it on first line or change it colour
|
|
55
|
-
fontFamily:
|
|
56
|
-
fontSize: Number(
|
|
57
|
-
fontWeight:
|
|
58
|
-
lineHeight: Number(
|
|
16
|
+
fontFamily: re,
|
|
17
|
+
fontSize: Number(ie.replace("px", "")),
|
|
18
|
+
fontWeight: se,
|
|
19
|
+
lineHeight: Number(le.replace("px", "")),
|
|
59
20
|
formatOnPaste: !0,
|
|
60
21
|
formatOnType: !0,
|
|
61
22
|
// Add to enable automatic formatting as the user types.
|
|
@@ -97,176 +58,174 @@ const ue = "'JetBrains Mono', Consolas, monospace", me = "12px", fe = "500", ge
|
|
|
97
58
|
// we need this set to false to get the correct absolute position, otherwise when the search box opens the content shifts
|
|
98
59
|
}
|
|
99
60
|
});
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
e.dispose = () => {
|
|
113
|
-
const s = g.get(t.source);
|
|
114
|
-
return s && (s.delete(e), s.size === 0 && g.delete(t.source)), n();
|
|
115
|
-
};
|
|
116
|
-
const i = g.get(t.source);
|
|
117
|
-
if (i)
|
|
118
|
-
i.add(e);
|
|
119
|
-
else
|
|
120
|
-
switch (g.set(t.source, /* @__PURE__ */ new Set([e])), t.type) {
|
|
121
|
-
case "editor":
|
|
122
|
-
t.source.onDidDispose(() => b(t.source));
|
|
123
|
-
break;
|
|
124
|
-
case "model":
|
|
125
|
-
t.source.onWillDispose(() => b(t.source));
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
61
|
+
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
62
|
+
const x = () => {
|
|
63
|
+
};
|
|
64
|
+
function de(o, t) {
|
|
65
|
+
function e(...n) {
|
|
66
|
+
return new Promise((a, i) => {
|
|
67
|
+
Promise.resolve(o(() => t.apply(this, n), {
|
|
68
|
+
fn: t,
|
|
69
|
+
thisArg: this,
|
|
70
|
+
args: n
|
|
71
|
+
})).then(a).catch(i);
|
|
72
|
+
});
|
|
128
73
|
}
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
function pe(o, t) {
|
|
132
|
-
return O(t, { type: "editor", source: o });
|
|
74
|
+
return e;
|
|
133
75
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
76
|
+
function ue(o, t = {}) {
|
|
77
|
+
let e, n, a = x;
|
|
78
|
+
const i = (l) => {
|
|
79
|
+
clearTimeout(l), a(), a = x;
|
|
80
|
+
};
|
|
81
|
+
let s;
|
|
82
|
+
return (l) => {
|
|
83
|
+
const v = S(o), c = S(t.maxWait);
|
|
84
|
+
return e && i(e), v <= 0 || c !== void 0 && c <= 0 ? (n && (i(n), n = void 0), Promise.resolve(l())) : new Promise((C, r) => {
|
|
85
|
+
a = t.rejectOnCancel ? r : C, s = l, c && !n && (n = setTimeout(() => {
|
|
86
|
+
e && i(e), n = void 0, C(s());
|
|
87
|
+
}, c)), e = setTimeout(() => {
|
|
88
|
+
n && i(n), n = void 0, C(l());
|
|
89
|
+
}, v);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
136
92
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
93
|
+
// @__NO_SIDE_EFFECTS__
|
|
94
|
+
function me(o, t = 200, e = {}) {
|
|
95
|
+
return de(ue(t, e), o);
|
|
140
96
|
}
|
|
141
|
-
function
|
|
142
|
-
|
|
97
|
+
function ge(o) {
|
|
98
|
+
var t;
|
|
99
|
+
const e = S(o);
|
|
100
|
+
return (t = e == null ? void 0 : e.$el) !== null && t !== void 0 ? t : e;
|
|
143
101
|
}
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
102
|
+
const L = B(!1);
|
|
103
|
+
let p = null;
|
|
104
|
+
async function fe() {
|
|
105
|
+
return p || (p = (async () => {
|
|
106
|
+
var o, t;
|
|
107
|
+
try {
|
|
108
|
+
const e = ((o = m.json) == null ? void 0 : o.jsonDefaults) || ((t = m.languages.json) == null ? void 0 : t.jsonDefaults);
|
|
109
|
+
e == null || e.setModeConfiguration({ tokens: !1 });
|
|
110
|
+
const n = await ee(
|
|
111
|
+
{
|
|
112
|
+
themes: Object.values(oe),
|
|
113
|
+
langs: Object.values(te)
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
n.getLoadedLanguages().forEach((a) => {
|
|
117
|
+
m.languages.register({ id: a });
|
|
118
|
+
}), X(n, m), L.value = !0;
|
|
119
|
+
} catch (e) {
|
|
120
|
+
throw p = null, e;
|
|
121
|
+
}
|
|
122
|
+
})(), p);
|
|
155
123
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const n = z({
|
|
124
|
+
function he(o, t) {
|
|
125
|
+
let e, n = !1;
|
|
126
|
+
const a = D({
|
|
160
127
|
editorStatus: "loading",
|
|
161
128
|
searchBoxIsRevealed: !1,
|
|
162
129
|
hasContent: !1,
|
|
163
130
|
theme: t.theme || "light"
|
|
164
|
-
}), i = (
|
|
165
|
-
!
|
|
166
|
-
}, s = (
|
|
167
|
-
var u;
|
|
168
|
-
return (u = e.value) == null ? void 0 : u.updateOptions({ readOnly: a });
|
|
169
|
-
}, m = () => {
|
|
170
|
-
var a;
|
|
171
|
-
return (a = e.value) == null ? void 0 : a.focus();
|
|
172
|
-
}, l = (a) => {
|
|
131
|
+
}), i = (r) => {
|
|
132
|
+
!n || !e || e.setValue(r);
|
|
133
|
+
}, s = (r) => e == null ? void 0 : e.updateOptions({ readOnly: r }), g = () => e == null ? void 0 : e.focus(), l = (r) => {
|
|
173
134
|
try {
|
|
174
|
-
if (!e
|
|
175
|
-
e.
|
|
176
|
-
} catch (
|
|
177
|
-
console.error(`useMonacoEditor: Failed to trigger command: ${
|
|
135
|
+
if (!e || !r) return;
|
|
136
|
+
e.focus(), e.trigger("keyboard", r, null);
|
|
137
|
+
} catch (f) {
|
|
138
|
+
console.error(`useMonacoEditor: Failed to trigger command: ${r}`, f);
|
|
178
139
|
}
|
|
179
|
-
},
|
|
180
|
-
var
|
|
140
|
+
}, v = () => {
|
|
141
|
+
var r;
|
|
181
142
|
try {
|
|
182
|
-
if (!e
|
|
183
|
-
if (
|
|
184
|
-
return (
|
|
143
|
+
if (!e) return;
|
|
144
|
+
if (a.searchBoxIsRevealed)
|
|
145
|
+
return (r = e.getContribution("editor.contrib.findController")) == null ? void 0 : r.closeFindWidget();
|
|
185
146
|
l("actions.find");
|
|
186
|
-
} catch (
|
|
187
|
-
console.error("useMonacoEditor: Failed to close findController.",
|
|
147
|
+
} catch (f) {
|
|
148
|
+
console.error("useMonacoEditor: Failed to close findController.", f);
|
|
188
149
|
}
|
|
189
|
-
}, c = /* @__PURE__ */
|
|
150
|
+
}, c = /* @__PURE__ */ me(() => m.editor.remeasureFonts(), 200);
|
|
190
151
|
return (() => {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
152
|
+
fe();
|
|
153
|
+
let r;
|
|
154
|
+
j([L, () => S(o)], ([f, R]) => {
|
|
155
|
+
var O;
|
|
156
|
+
const E = ge(R);
|
|
157
|
+
if (!(E instanceof HTMLElement) || !f) {
|
|
158
|
+
n = !1;
|
|
197
159
|
return;
|
|
198
160
|
}
|
|
199
|
-
if (!
|
|
200
|
-
|
|
201
|
-
|
|
161
|
+
if (!n) {
|
|
162
|
+
if (!r) {
|
|
163
|
+
const d = m.Uri.parse(`inmemory://model/${t.language}-${crypto.randomUUID()}`);
|
|
164
|
+
r = m.editor.createModel(t.code.value, t.language, d);
|
|
165
|
+
}
|
|
166
|
+
e = m.editor.create(E, {
|
|
167
|
+
...ce,
|
|
202
168
|
readOnly: t.readOnly || !1,
|
|
203
169
|
language: t.language,
|
|
204
|
-
theme:
|
|
205
|
-
model:
|
|
170
|
+
theme: a.theme === "light" ? "catppuccin-latte" : "catppuccin-mocha",
|
|
171
|
+
model: r,
|
|
206
172
|
editContext: !1,
|
|
207
173
|
...t.monacoOptions
|
|
208
|
-
}),
|
|
209
|
-
|
|
210
|
-
e.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
n.hasContent = !!f.length, (p = t.onChanged) == null || p.call(t, f);
|
|
214
|
-
})
|
|
215
|
-
), (I = t.onCreated) == null || I.call(t), c();
|
|
174
|
+
}), n = !0, a.editorStatus = "ready", a.hasContent = !!t.code.value, e.onDidChangeModelContent(() => {
|
|
175
|
+
var h;
|
|
176
|
+
const d = e.getValue();
|
|
177
|
+
a.hasContent = !!d.length, (h = t.onChanged) == null || h.call(t, d);
|
|
178
|
+
}), (O = t.onCreated) == null || O.call(t), c();
|
|
216
179
|
try {
|
|
217
|
-
const
|
|
218
|
-
if (
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
n.searchBoxIsRevealed = p.isRevealed;
|
|
224
|
-
})
|
|
225
|
-
// This returns a disposable
|
|
226
|
-
);
|
|
180
|
+
const d = e.getContribution("editor.contrib.findController");
|
|
181
|
+
if (d) {
|
|
182
|
+
const h = d.getState();
|
|
183
|
+
h.onFindReplaceStateChange(() => {
|
|
184
|
+
a.searchBoxIsRevealed = h.isRevealed;
|
|
185
|
+
});
|
|
227
186
|
}
|
|
228
|
-
} catch (
|
|
229
|
-
console.error("useMonacoEditor: Failed to get the state of findController",
|
|
187
|
+
} catch (d) {
|
|
188
|
+
console.error("useMonacoEditor: Failed to get the state of findController", d);
|
|
230
189
|
}
|
|
231
190
|
}
|
|
232
191
|
}, {
|
|
233
192
|
immediate: !0,
|
|
234
193
|
flush: "post"
|
|
235
194
|
});
|
|
236
|
-
})(),
|
|
237
|
-
if (!e
|
|
238
|
-
const
|
|
239
|
-
e.
|
|
195
|
+
})(), P(c), U(c), V(() => {
|
|
196
|
+
if (!e) return;
|
|
197
|
+
const r = e.getModel();
|
|
198
|
+
e.dispose(), r && r.dispose();
|
|
240
199
|
}), {
|
|
241
200
|
editor: e,
|
|
242
|
-
editorStates:
|
|
201
|
+
editorStates: a,
|
|
243
202
|
setContent: i,
|
|
244
203
|
setReadOnly: s,
|
|
245
|
-
focus:
|
|
204
|
+
focus: g,
|
|
246
205
|
remeasureFonts: c,
|
|
247
|
-
toggleSearchWidget:
|
|
206
|
+
toggleSearchWidget: v,
|
|
248
207
|
triggerKeyboardCommand: l
|
|
249
208
|
};
|
|
250
209
|
}
|
|
251
|
-
const
|
|
210
|
+
const pe = {
|
|
252
211
|
messages: {
|
|
253
212
|
empty_message: "The editor is currently empty. Start typing to add content.",
|
|
254
213
|
empty_title: "No content available",
|
|
255
214
|
loading_message: "Please wait while the {type} content is loaded.",
|
|
256
215
|
loading_title: "{type} editor"
|
|
257
216
|
}
|
|
258
|
-
},
|
|
259
|
-
editor:
|
|
217
|
+
}, ye = {
|
|
218
|
+
editor: pe
|
|
260
219
|
};
|
|
261
|
-
function
|
|
262
|
-
const o = ne("en-us",
|
|
220
|
+
function ve() {
|
|
221
|
+
const o = ne("en-us", ye);
|
|
263
222
|
return {
|
|
264
223
|
i18n: o,
|
|
265
|
-
i18nT:
|
|
224
|
+
i18nT: ae(o)
|
|
266
225
|
// Translation component <i18n-t>
|
|
267
226
|
};
|
|
268
227
|
}
|
|
269
|
-
const
|
|
228
|
+
const Ce = /* @__PURE__ */ W({
|
|
270
229
|
__name: "MonacoEditorStatusOverlay",
|
|
271
230
|
props: {
|
|
272
231
|
title: {},
|
|
@@ -275,30 +234,30 @@ const ke = /* @__PURE__ */ U({
|
|
|
275
234
|
},
|
|
276
235
|
setup(o) {
|
|
277
236
|
return (t, e) => {
|
|
278
|
-
const
|
|
279
|
-
return
|
|
237
|
+
const n = K("KEmptyState");
|
|
238
|
+
return y(), _(n, {
|
|
280
239
|
class: "monaco-editor-status-overlay",
|
|
281
240
|
message: o.message,
|
|
282
241
|
title: o.title
|
|
283
|
-
},
|
|
242
|
+
}, A({ _: 2 }, [
|
|
284
243
|
o.icon ? {
|
|
285
244
|
name: "icon",
|
|
286
|
-
fn:
|
|
287
|
-
(
|
|
245
|
+
fn: b(() => [
|
|
246
|
+
(y(), _(H(o.icon), { decorative: "" }))
|
|
288
247
|
]),
|
|
289
248
|
key: "0"
|
|
290
249
|
} : void 0
|
|
291
250
|
]), 1032, ["message", "title"]);
|
|
292
251
|
};
|
|
293
252
|
}
|
|
294
|
-
}),
|
|
253
|
+
}), N = (o, t) => {
|
|
295
254
|
const e = o.__vccOpts || o;
|
|
296
|
-
for (const [
|
|
297
|
-
e[
|
|
255
|
+
for (const [n, a] of t)
|
|
256
|
+
e[n] = a;
|
|
298
257
|
return e;
|
|
299
|
-
},
|
|
258
|
+
}, F = /* @__PURE__ */ N(Ce, [["__scopeId", "data-v-062eadb5"]]), Se = /* @__PURE__ */ W({
|
|
300
259
|
__name: "MonacoEditor",
|
|
301
|
-
props: /* @__PURE__ */
|
|
260
|
+
props: /* @__PURE__ */ $({
|
|
302
261
|
theme: { default: "light" },
|
|
303
262
|
language: { default: "markdown" },
|
|
304
263
|
options: { default: () => {
|
|
@@ -312,62 +271,62 @@ const ke = /* @__PURE__ */ U({
|
|
|
312
271
|
}),
|
|
313
272
|
emits: ["update:modelValue"],
|
|
314
273
|
setup(o) {
|
|
315
|
-
const t =
|
|
274
|
+
const t = z(o, "modelValue"), { i18n: e } = ve(), n = G("editorRef"), a = M(() => o.theme === "dark" ? "dark" : "light"), i = M(() => s.editorStates.editorStatus === "ready" && !s.editorStates.hasContent), s = he(n, {
|
|
316
275
|
language: o.language,
|
|
317
276
|
code: t,
|
|
318
|
-
theme:
|
|
277
|
+
theme: a.value,
|
|
319
278
|
monacoOptions: o.options,
|
|
320
|
-
onChanged: (
|
|
321
|
-
t.value =
|
|
279
|
+
onChanged: (g) => {
|
|
280
|
+
t.value = g;
|
|
322
281
|
}
|
|
323
282
|
});
|
|
324
|
-
return (
|
|
325
|
-
class:
|
|
326
|
-
|
|
327
|
-
{ loading:
|
|
283
|
+
return (g, l) => (y(), q("div", {
|
|
284
|
+
class: J(["monaco-editor-container", [
|
|
285
|
+
a.value,
|
|
286
|
+
{ loading: u(s).editorStates.editorStatus === "loading" }
|
|
328
287
|
]]),
|
|
329
288
|
"data-testid": "monaco-editor-container"
|
|
330
289
|
}, [
|
|
331
|
-
|
|
290
|
+
Q("div", {
|
|
332
291
|
ref_key: "editorRef",
|
|
333
|
-
ref:
|
|
292
|
+
ref: n,
|
|
334
293
|
class: "monaco-editor-target",
|
|
335
294
|
"data-testid": "monaco-editor-target"
|
|
336
295
|
}, null, 512),
|
|
337
|
-
|
|
338
|
-
isLoading:
|
|
296
|
+
T(g.$slots, "state-loading", {
|
|
297
|
+
isLoading: u(s).editorStates.editorStatus === "loading"
|
|
339
298
|
}, () => [
|
|
340
|
-
|
|
341
|
-
default:
|
|
342
|
-
|
|
299
|
+
I(k, { name: "fade" }, {
|
|
300
|
+
default: b(() => [
|
|
301
|
+
u(s).editorStates.editorStatus === "loading" ? (y(), _(F, {
|
|
343
302
|
key: 0,
|
|
344
303
|
"data-testid": "monaco-editor-status-overlay-loading",
|
|
345
|
-
icon:
|
|
346
|
-
message:
|
|
347
|
-
title:
|
|
348
|
-
}, null, 8, ["icon", "message", "title"])) :
|
|
304
|
+
icon: u(Y),
|
|
305
|
+
message: u(e).t("editor.messages.loading_message", { type: o.language }),
|
|
306
|
+
title: u(e).t("editor.messages.loading_title", { type: o.language })
|
|
307
|
+
}, null, 8, ["icon", "message", "title"])) : w("", !0)
|
|
349
308
|
]),
|
|
350
309
|
_: 1
|
|
351
310
|
})
|
|
352
311
|
], !0),
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
default:
|
|
356
|
-
i.value ? (
|
|
312
|
+
T(g.$slots, "state-empty", { isEmpty: i.value }, () => [
|
|
313
|
+
I(k, { name: "fade" }, {
|
|
314
|
+
default: b(() => [
|
|
315
|
+
i.value ? (y(), _(F, {
|
|
357
316
|
key: 0,
|
|
358
317
|
"data-testid": "monaco-editor-status-overlay-empty",
|
|
359
|
-
icon:
|
|
360
|
-
message:
|
|
361
|
-
title:
|
|
362
|
-
}, null, 8, ["icon", "message", "title"])) :
|
|
318
|
+
icon: u(Z),
|
|
319
|
+
message: u(e).t("editor.messages.empty_message"),
|
|
320
|
+
title: u(e).t("editor.messages.empty_title")
|
|
321
|
+
}, null, 8, ["icon", "message", "title"])) : w("", !0)
|
|
363
322
|
]),
|
|
364
323
|
_: 1
|
|
365
324
|
})
|
|
366
325
|
], !0)
|
|
367
326
|
], 2));
|
|
368
327
|
}
|
|
369
|
-
}), Te = /* @__PURE__ */
|
|
328
|
+
}), Te = /* @__PURE__ */ N(Se, [["__scopeId", "data-v-c8f35a88"]]);
|
|
370
329
|
export {
|
|
371
330
|
Te as MonacoEditor,
|
|
372
|
-
|
|
331
|
+
he as useMonacoEditor
|
|
373
332
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@kong/icons"),require("monaco-editor"),require("@shikijs/monaco"),require("shiki"),require("@kong-ui-public/i18n")):typeof define=="function"&&define.amd?define(["exports","vue","@kong/icons","monaco-editor","@shikijs/monaco","shiki","@kong-ui-public/i18n"],e):(s=typeof globalThis<"u"?globalThis:s||self,e(s["kong-ui-public-monaco-editor"]={},s.Vue,s.KongIcons,s.monaco,s.monaco$1,s.shiki,s["kong-ui-public-i18n"]))})(this,function(s,e,O,N,x,S,b){"use strict";function B(n){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(o,t,a.get?a:{enumerable:!0,get:()=>n[t]})}}return o.default=n,Object.freeze(o)}const f=B(N),j=Object.freeze({autoClosingQuotes:"always",automaticLayout:!0,bracketPairColorization:{enabled:!0},hideCursorInOverviewRuler:!0,fontFamily:"'JetBrains Mono', Consolas, monospace",fontSize:Number("12px".replace("px","")),fontWeight:"500",lineHeight:Number("20px".replace("px","")),formatOnPaste:!0,formatOnType:!0,lineNumbersMinChars:3,minimap:{enabled:!1},stickyScroll:{enabled:!0},suggest:{showWords:!1},quickSuggestions:!0,suggestOnTriggerCharacters:!0,wordBasedSuggestions:"off",overviewRulerLanes:0,renderWhitespace:"boundary",scrollBeyondLastLine:!1,roundedSelection:!1,wordWrapColumn:120,colorDecorators:!0,folding:!0,fixedOverflowWidgets:!0,tabSize:2,detectIndentation:!1,insertSpaces:!0,trimAutoWhitespace:!0,wordWrap:"bounded",find:{addExtraSpaceOnTop:!1}});typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const k=()=>{};function L(n,o){function t(...a){return new Promise((r,c)=>{Promise.resolve(n(()=>o.apply(this,a),{fn:o,thisArg:this,args:a})).then(r).catch(c)})}return t}function U(n,o={}){let t,a,r=k;const c=d=>{clearTimeout(d),r(),r=k};let l;return d=>{const _=e.toValue(n),u=e.toValue(o.maxWait);return t&&c(t),_<=0||u!==void 0&&u<=0?(a&&(c(a),a=void 0),Promise.resolve(d())):new Promise((C,i)=>{r=o.rejectOnCancel?i:C,l=d,u&&!a&&(a=setTimeout(()=>{t&&c(t),a=void 0,C(l())},u)),t=setTimeout(()=>{a&&c(a),a=void 0,C(d())},_)})}}function V(n,o=200,t={}){return L(U(o,t),n)}function W(n){var o;const t=e.toValue(n);return(o=t==null?void 0:t.$el)!==null&&o!==void 0?o:t}const E=e.ref(!1);let h=null;async function D(){return h||(h=(async()=>{var n,o;try{const t=((n=f.json)==null?void 0:n.jsonDefaults)||((o=f.languages.json)==null?void 0:o.jsonDefaults);t==null||t.setModeConfiguration({tokens:!1});const a=await S.getSingletonHighlighter({themes:Object.values(S.bundledThemes),langs:Object.values(S.bundledLanguages)});a.getLoadedLanguages().forEach(r=>{f.languages.register({id:r})}),x.shikiToMonaco(a,f),E.value=!0}catch(t){throw h=null,t}})(),h)}function I(n,o){let t,a=!1;const r=e.reactive({editorStatus:"loading",searchBoxIsRevealed:!1,hasContent:!1,theme:o.theme||"light"}),c=i=>{!a||!t||t.setValue(i)},l=i=>t==null?void 0:t.updateOptions({readOnly:i}),g=()=>t==null?void 0:t.focus(),d=i=>{try{if(!t||!i)return;t.focus(),t.trigger("keyboard",i,null)}catch(p){console.error(`useMonacoEditor: Failed to trigger command: ${i}`,p)}},_=()=>{var i;try{if(!t)return;if(r.searchBoxIsRevealed)return(i=t.getContribution("editor.contrib.findController"))==null?void 0:i.closeFindWidget();d("actions.find")}catch(p){console.error("useMonacoEditor: Failed to close findController.",p)}},u=V(()=>f.editor.remeasureFonts(),200);return(()=>{D();let i;e.watch([E,()=>e.toValue(n)],([p,q])=>{var F;const w=W(q);if(!(w instanceof HTMLElement)||!p){a=!1;return}if(!a){if(!i){const m=f.Uri.parse(`inmemory://model/${o.language}-${crypto.randomUUID()}`);i=f.editor.createModel(o.code.value,o.language,m)}t=f.editor.create(w,{...j,readOnly:o.readOnly||!1,language:o.language,theme:r.theme==="light"?"catppuccin-latte":"catppuccin-mocha",model:i,editContext:!1,...o.monacoOptions}),a=!0,r.editorStatus="ready",r.hasContent=!!o.code.value,t.onDidChangeModelContent(()=>{var y;const m=t.getValue();r.hasContent=!!m.length,(y=o.onChanged)==null||y.call(o,m)}),(F=o.onCreated)==null||F.call(o),u();try{const m=t.getContribution("editor.contrib.findController");if(m){const y=m.getState();y.onFindReplaceStateChange(()=>{r.searchBoxIsRevealed=y.isRevealed})}}catch(m){console.error("useMonacoEditor: Failed to get the state of findController",m)}}},{immediate:!0,flush:"post"})})(),e.onMounted(u),e.onActivated(u),e.onBeforeUnmount(()=>{if(!t)return;const i=t.getModel();t.dispose(),i&&i.dispose()}),{editor:t,editorStates:r,setContent:c,setReadOnly:l,focus:g,remeasureFonts:u,toggleSearchWidget:_,triggerKeyboardCommand:d}}const P={editor:{messages:{empty_message:"The editor is currently empty. Start typing to add content.",empty_title:"No content available",loading_message:"Please wait while the {type} content is loaded.",loading_title:"{type} editor"}}};function R(){const n=b.createI18n("en-us",P);return{i18n:n,i18nT:b.i18nTComponent(n)}}const K=e.defineComponent({__name:"MonacoEditorStatusOverlay",props:{title:{},message:{},icon:{}},setup(n){return(o,t)=>{const a=e.resolveComponent("KEmptyState");return e.openBlock(),e.createBlock(a,{class:"monaco-editor-status-overlay",message:n.message,title:n.title},e.createSlots({_:2},[n.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.icon),{decorative:""}))]),key:"0"}:void 0]),1032,["message","title"])}}}),T=(n,o)=>{const t=n.__vccOpts||n;for(const[a,r]of o)t[a]=r;return t},M=T(K,[["__scopeId","data-v-062eadb5"]]),H=T(e.defineComponent({__name:"MonacoEditor",props:e.mergeModels({theme:{default:"light"},language:{default:"markdown"},options:{default:()=>{}}},{modelValue:{type:String,required:!0},modelModifiers:{}}),emits:["update:modelValue"],setup(n){const o=e.useModel(n,"modelValue"),{i18n:t}=R(),a=e.useTemplateRef("editorRef"),r=e.computed(()=>n.theme==="dark"?"dark":"light"),c=e.computed(()=>l.editorStates.editorStatus==="ready"&&!l.editorStates.hasContent),l=I(a,{language:n.language,code:o,theme:r.value,monacoOptions:n.options,onChanged:g=>{o.value=g}});return(g,d)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["monaco-editor-container",[r.value,{loading:e.unref(l).editorStates.editorStatus==="loading"}]]),"data-testid":"monaco-editor-container"},[e.createElementVNode("div",{ref_key:"editorRef",ref:a,class:"monaco-editor-target","data-testid":"monaco-editor-target"},null,512),e.renderSlot(g.$slots,"state-loading",{isLoading:e.unref(l).editorStates.editorStatus==="loading"},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[e.unref(l).editorStates.editorStatus==="loading"?(e.openBlock(),e.createBlock(M,{key:0,"data-testid":"monaco-editor-status-overlay-loading",icon:e.unref(O.ProgressIcon),message:e.unref(t).t("editor.messages.loading_message",{type:n.language}),title:e.unref(t).t("editor.messages.loading_title",{type:n.language})},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0),e.renderSlot(g.$slots,"state-empty",{isEmpty:c.value},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[c.value?(e.openBlock(),e.createBlock(M,{key:0,"data-testid":"monaco-editor-status-overlay-empty",icon:e.unref(O.CodeblockIcon),message:e.unref(t).t("editor.messages.empty_message"),title:e.unref(t).t("editor.messages.empty_title")},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0)],2))}}),[["__scopeId","data-v-c8f35a88"]]);s.MonacoEditor=H,s.useMonacoEditor=I,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MonacoEditor.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/MonacoEditor.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MonacoEditor.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/MonacoEditor.vue"],"names":[],"mappings":"AAmTA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE5C,KAAK,WAAW,GAAG;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;MAGE;IACF,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,oCAAoC,CAAC,GAAG,SAAS,CAAA;CAC3E,CAAC;AAQF;;GAEG;AACH,QAAA,MAAM,KAAK,wDAGT,CAAA;AAyBF,KAAK,gBAAgB,GAAG;IACxB;;OAEG;IACH,UAAU,EAAE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;CACjC,CAAC;AAKF,KAAK,iBAAiB,GAAG,WAAW,GAAG,gBAAgB,CAAC;AA+IxD,QAAA,IAAI,OAAO;;CAAU,EAAE,QAAQ;;CAAY,CAAE;AAC7C,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,GACpD;IAAE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG,CAAA;CAAE,CAAC;AAOtD,QAAA,MAAM,UAAU;;;;kFAGd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MonacoEditorStatusOverlay.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/MonacoEditorStatusOverlay.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MonacoEditorStatusOverlay.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/MonacoEditorStatusOverlay.vue"],"names":[],"mappings":"AAmEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,KAAK,WAAW,GAAG;IACjB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,CAAC;AA8DF,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -8,7 +8,7 @@ import type { UseMonacoEditorOptions } from '../types';
|
|
|
8
8
|
* @returns {object} An object containing the editor instance and utility methods.
|
|
9
9
|
*/
|
|
10
10
|
export declare function useMonacoEditor<T extends MaybeElement>(target: MaybeComputedElementRef<T>, options: UseMonacoEditorOptions): {
|
|
11
|
-
editor:
|
|
11
|
+
editor: monaco.editor.IStandaloneCodeEditor | undefined;
|
|
12
12
|
editorStates: {
|
|
13
13
|
editorStatus: import("..").EditorStatus;
|
|
14
14
|
searchBoxIsRevealed: boolean;
|
|
@@ -18,7 +18,7 @@ export declare function useMonacoEditor<T extends MaybeElement>(target: MaybeCom
|
|
|
18
18
|
setContent: (content: string) => void;
|
|
19
19
|
setReadOnly: (readOnly: boolean) => void;
|
|
20
20
|
focus: () => void;
|
|
21
|
-
remeasureFonts: import("@vueuse/core").UseDebounceFnReturn<() => void
|
|
21
|
+
remeasureFonts: import("@vueuse/core").UseDebounceFnReturn<() => void>;
|
|
22
22
|
toggleSearchWidget: () => void;
|
|
23
23
|
triggerKeyboardCommand: (id: string) => void;
|
|
24
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMonacoEditor.d.ts","sourceRoot":"","sources":["../../../../src/composables/useMonacoEditor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useMonacoEditor.d.ts","sourceRoot":"","sources":["../../../../src/composables/useMonacoEditor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC,OAAO,KAAK,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,KAAK,EAAsB,sBAAsB,EAAE,MAAM,UAAU,CAAA;AAwC1E;;;;;EAKE;AACF,wBAAgB,eAAe,CAAC,CAAC,SAAS,YAAY,EACpD,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,EAClC,OAAO,EAAE,sBAAsB;;;;;;;;0BAqBF,MAAM,KAAG,IAAI;4BAOX,OAAO,KAAG,IAAI;iBAG3B,IAAI;;8BAkBS,IAAI;iCAXC,MAAM,KAAG,IAAI;EAwIlD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
2
|
import type { EditorFeature, EditorLanguage, NegatedEditorFeature, IFeatureDefinition } from 'monaco-editor/esm/metadata.js';
|
|
3
|
+
import type { BundledLanguage, BundledTheme } from 'shiki';
|
|
3
4
|
type Options = {
|
|
4
5
|
/**
|
|
5
6
|
* Include only a subset of the languages supported.
|
|
@@ -50,7 +51,37 @@ type Options = {
|
|
|
50
51
|
* ```
|
|
51
52
|
*/
|
|
52
53
|
features?: Array<EditorFeature | NegatedEditorFeature>;
|
|
54
|
+
/**
|
|
55
|
+
* Shiki configuration options.
|
|
56
|
+
* @type {{ themes?: BundledTheme[]; langs?: BundledLanguage[] }}
|
|
57
|
+
*/
|
|
58
|
+
shiki?: {
|
|
59
|
+
/**
|
|
60
|
+
* Languages to include for Shiki syntax highlighting.
|
|
61
|
+
*
|
|
62
|
+
* @type {BundledLanguage[]}
|
|
63
|
+
* @defaultValue The same languages specified in the`languages` option above
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* // Only include JavaScript and JSON support
|
|
67
|
+
* langs: ['javascript', 'json']
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
langs?: BundledLanguage[];
|
|
71
|
+
/**
|
|
72
|
+
* Themes to include for Shiki syntax highlighting.
|
|
73
|
+
*
|
|
74
|
+
* @type {BundledTheme[]}
|
|
75
|
+
* @defaultValue ['catppuccin-latte', 'catppuccin-mocha']
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* // Include the 'nord' theme
|
|
79
|
+
* themes: ['nord']
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
themes?: BundledTheme[];
|
|
83
|
+
};
|
|
53
84
|
};
|
|
54
|
-
export default function (options?: Options): Plugin;
|
|
85
|
+
export default function plugin(options?: Options): Plugin;
|
|
55
86
|
export {};
|
|
56
87
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../vite-plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../vite-plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAM1D,KAAK,OAAO,GAAG;IACb;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,cAAc,EAAE,CAAA;IAE5B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,eAAe,CAAC,EAAE,kBAAkB,EAAE,CAAA;IAEtC;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,GAAG,oBAAoB,CAAC,CAAA;IAEtD;;;KAGC;IACD,KAAK,CAAC,EAAE;QACN;;;;;;;;;;UAUE;QACF,KAAK,CAAC,EAAE,eAAe,EAAE,CAAA;QAEzB;;;;;;;;;;WAUG;QACH,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;KACxB,CAAA;CACF,CAAA;AA+GD,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAkFxD"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const metadata_js = require("monaco-editor/esm/metadata.js");
|
|
3
|
+
const shikiCodegen = require("shiki-codegen");
|
|
4
|
+
const shiki = require("shiki");
|
|
3
5
|
const WORKER_ALIASES = {
|
|
4
6
|
javascript: "typescript",
|
|
5
7
|
less: "css",
|
|
@@ -7,10 +9,17 @@ const WORKER_ALIASES = {
|
|
|
7
9
|
handlebars: "html",
|
|
8
10
|
razor: "html"
|
|
9
11
|
};
|
|
10
|
-
const
|
|
12
|
+
const VIRTUAL_MODULE_MONACO_ID = "\0virtual:monaco-editor";
|
|
13
|
+
const VIRTUAL_MODULE_SHIKI_ID = "\0virtual:shiki";
|
|
11
14
|
function generateImports(entries) {
|
|
12
15
|
const entryArray = Array.isArray(entries) ? entries : [entries];
|
|
13
|
-
return entryArray.map((entry) =>
|
|
16
|
+
return entryArray.map((entry) => {
|
|
17
|
+
if (entry.endsWith("monaco.contribution")) {
|
|
18
|
+
const lang = entry.split("/").at(-2);
|
|
19
|
+
return `export * as ${lang} from 'monaco-editor/esm/${entry}'`;
|
|
20
|
+
}
|
|
21
|
+
return `import 'monaco-editor/esm/${entry}'`;
|
|
22
|
+
});
|
|
14
23
|
}
|
|
15
24
|
function resolveFeatures(requestedFeatures, allFeatureIds) {
|
|
16
25
|
if (!requestedFeatures) {
|
|
@@ -66,62 +75,72 @@ function generateWorkerCode(languageIds, languagesDict, customLanguages) {
|
|
|
66
75
|
"}"
|
|
67
76
|
];
|
|
68
77
|
}
|
|
69
|
-
function
|
|
78
|
+
function plugin(options) {
|
|
70
79
|
return {
|
|
71
80
|
name: "vite-plugin-monaco",
|
|
72
81
|
enforce: "pre",
|
|
73
82
|
resolveId(id) {
|
|
74
83
|
if (id === "monaco-editor") {
|
|
75
|
-
return
|
|
84
|
+
return VIRTUAL_MODULE_MONACO_ID;
|
|
85
|
+
} else if (id === "shiki") {
|
|
86
|
+
return VIRTUAL_MODULE_SHIKI_ID;
|
|
76
87
|
}
|
|
77
88
|
},
|
|
78
89
|
load(id) {
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
var _a, _b;
|
|
91
|
+
if (id === VIRTUAL_MODULE_MONACO_ID) {
|
|
92
|
+
const languagesDict = Object.fromEntries(
|
|
93
|
+
metadata_js.languages.map((lang) => [lang.label, lang])
|
|
94
|
+
);
|
|
95
|
+
const featuresDict = Object.fromEntries(
|
|
96
|
+
metadata_js.features.map((feat) => [feat.label, feat])
|
|
97
|
+
);
|
|
98
|
+
const featuresIds = resolveFeatures(
|
|
99
|
+
options == null ? void 0 : options.features,
|
|
100
|
+
Object.keys(featuresDict)
|
|
101
|
+
);
|
|
102
|
+
const featureImports = featuresIds.flatMap((featureId) => {
|
|
103
|
+
const feature = featuresDict[featureId];
|
|
104
|
+
if (!(feature == null ? void 0 : feature.entry)) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
return generateImports(feature.entry);
|
|
108
|
+
});
|
|
109
|
+
const languageIds = (options == null ? void 0 : options.languages) || Object.keys(languagesDict);
|
|
110
|
+
const languageImports = languageIds.flatMap((langId) => {
|
|
111
|
+
const lang = languagesDict[langId];
|
|
112
|
+
if (!(lang == null ? void 0 : lang.entry)) {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
return generateImports(lang.entry);
|
|
116
|
+
});
|
|
117
|
+
const customLanguageImports = ((options == null ? void 0 : options.customLanguages) || []).map(
|
|
118
|
+
({ entry }) => `import '${entry}'`
|
|
119
|
+
);
|
|
120
|
+
const workerCode = generateWorkerCode(
|
|
121
|
+
languageIds,
|
|
122
|
+
languagesDict,
|
|
123
|
+
options == null ? void 0 : options.customLanguages
|
|
124
|
+
);
|
|
125
|
+
return [
|
|
126
|
+
"import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'",
|
|
127
|
+
...featureImports,
|
|
128
|
+
...languageImports,
|
|
129
|
+
...customLanguageImports,
|
|
130
|
+
...workerCode,
|
|
131
|
+
"export * from 'monaco-editor/esm/vs/editor/editor.api'",
|
|
132
|
+
"export default monaco"
|
|
133
|
+
].join("\n");
|
|
134
|
+
} else if (id === VIRTUAL_MODULE_SHIKI_ID) {
|
|
135
|
+
const languageIds = ((_a = options == null ? void 0 : options.shiki) == null ? void 0 : _a.langs) || ((options == null ? void 0 : options.languages) || metadata_js.languages.map((lang) => lang.label)).filter((lang) => lang in shiki.bundledLanguages);
|
|
136
|
+
return shikiCodegen.codegen({
|
|
137
|
+
themes: ((_b = options == null ? void 0 : options.shiki) == null ? void 0 : _b.themes) || ["catppuccin-latte", "catppuccin-mocha"],
|
|
138
|
+
engine: "javascript",
|
|
139
|
+
langs: languageIds,
|
|
140
|
+
typescript: false
|
|
141
|
+
});
|
|
81
142
|
}
|
|
82
|
-
const languagesDict = Object.fromEntries(
|
|
83
|
-
metadata_js.languages.map((lang) => [lang.label, lang])
|
|
84
|
-
);
|
|
85
|
-
const featuresDict = Object.fromEntries(
|
|
86
|
-
metadata_js.features.map((feat) => [feat.label, feat])
|
|
87
|
-
);
|
|
88
|
-
const featuresIds = resolveFeatures(
|
|
89
|
-
options == null ? void 0 : options.features,
|
|
90
|
-
Object.keys(featuresDict)
|
|
91
|
-
);
|
|
92
|
-
const featureImports = featuresIds.flatMap((featureId) => {
|
|
93
|
-
const feature = featuresDict[featureId];
|
|
94
|
-
if (!(feature == null ? void 0 : feature.entry)) {
|
|
95
|
-
return [];
|
|
96
|
-
}
|
|
97
|
-
return generateImports(feature.entry);
|
|
98
|
-
});
|
|
99
|
-
const languageIds = (options == null ? void 0 : options.languages) || Object.keys(languagesDict);
|
|
100
|
-
const languageImports = languageIds.flatMap((langId) => {
|
|
101
|
-
const lang = languagesDict[langId];
|
|
102
|
-
if (!(lang == null ? void 0 : lang.entry)) {
|
|
103
|
-
return [];
|
|
104
|
-
}
|
|
105
|
-
return generateImports(lang.entry);
|
|
106
|
-
});
|
|
107
|
-
const customLanguageImports = ((options == null ? void 0 : options.customLanguages) || []).map(
|
|
108
|
-
({ entry }) => `import '${entry}'`
|
|
109
|
-
);
|
|
110
|
-
const workerCode = generateWorkerCode(
|
|
111
|
-
languageIds,
|
|
112
|
-
languagesDict,
|
|
113
|
-
options == null ? void 0 : options.customLanguages
|
|
114
|
-
);
|
|
115
|
-
return [
|
|
116
|
-
"import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'",
|
|
117
|
-
...featureImports,
|
|
118
|
-
...languageImports,
|
|
119
|
-
...customLanguageImports,
|
|
120
|
-
...workerCode,
|
|
121
|
-
"export * from 'monaco-editor/esm/vs/editor/editor.api'",
|
|
122
|
-
"export default monaco"
|
|
123
|
-
].join("\n");
|
|
124
143
|
}
|
|
125
144
|
};
|
|
126
145
|
}
|
|
127
|
-
module.exports =
|
|
146
|
+
module.exports = plugin;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { languages, features } from "monaco-editor/esm/metadata.js";
|
|
2
|
+
import { codegen } from "shiki-codegen";
|
|
3
|
+
import { bundledLanguages } from "shiki";
|
|
2
4
|
const WORKER_ALIASES = {
|
|
3
5
|
javascript: "typescript",
|
|
4
6
|
less: "css",
|
|
@@ -6,10 +8,17 @@ const WORKER_ALIASES = {
|
|
|
6
8
|
handlebars: "html",
|
|
7
9
|
razor: "html"
|
|
8
10
|
};
|
|
9
|
-
const
|
|
11
|
+
const VIRTUAL_MODULE_MONACO_ID = "\0virtual:monaco-editor";
|
|
12
|
+
const VIRTUAL_MODULE_SHIKI_ID = "\0virtual:shiki";
|
|
10
13
|
function generateImports(entries) {
|
|
11
14
|
const entryArray = Array.isArray(entries) ? entries : [entries];
|
|
12
|
-
return entryArray.map((entry) =>
|
|
15
|
+
return entryArray.map((entry) => {
|
|
16
|
+
if (entry.endsWith("monaco.contribution")) {
|
|
17
|
+
const lang = entry.split("/").at(-2);
|
|
18
|
+
return `export * as ${lang} from 'monaco-editor/esm/${entry}'`;
|
|
19
|
+
}
|
|
20
|
+
return `import 'monaco-editor/esm/${entry}'`;
|
|
21
|
+
});
|
|
13
22
|
}
|
|
14
23
|
function resolveFeatures(requestedFeatures, allFeatureIds) {
|
|
15
24
|
if (!requestedFeatures) {
|
|
@@ -65,64 +74,74 @@ function generateWorkerCode(languageIds, languagesDict, customLanguages) {
|
|
|
65
74
|
"}"
|
|
66
75
|
];
|
|
67
76
|
}
|
|
68
|
-
function
|
|
77
|
+
function plugin(options) {
|
|
69
78
|
return {
|
|
70
79
|
name: "vite-plugin-monaco",
|
|
71
80
|
enforce: "pre",
|
|
72
81
|
resolveId(id) {
|
|
73
82
|
if (id === "monaco-editor") {
|
|
74
|
-
return
|
|
83
|
+
return VIRTUAL_MODULE_MONACO_ID;
|
|
84
|
+
} else if (id === "shiki") {
|
|
85
|
+
return VIRTUAL_MODULE_SHIKI_ID;
|
|
75
86
|
}
|
|
76
87
|
},
|
|
77
88
|
load(id) {
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
var _a, _b;
|
|
90
|
+
if (id === VIRTUAL_MODULE_MONACO_ID) {
|
|
91
|
+
const languagesDict = Object.fromEntries(
|
|
92
|
+
languages.map((lang) => [lang.label, lang])
|
|
93
|
+
);
|
|
94
|
+
const featuresDict = Object.fromEntries(
|
|
95
|
+
features.map((feat) => [feat.label, feat])
|
|
96
|
+
);
|
|
97
|
+
const featuresIds = resolveFeatures(
|
|
98
|
+
options == null ? void 0 : options.features,
|
|
99
|
+
Object.keys(featuresDict)
|
|
100
|
+
);
|
|
101
|
+
const featureImports = featuresIds.flatMap((featureId) => {
|
|
102
|
+
const feature = featuresDict[featureId];
|
|
103
|
+
if (!(feature == null ? void 0 : feature.entry)) {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
return generateImports(feature.entry);
|
|
107
|
+
});
|
|
108
|
+
const languageIds = (options == null ? void 0 : options.languages) || Object.keys(languagesDict);
|
|
109
|
+
const languageImports = languageIds.flatMap((langId) => {
|
|
110
|
+
const lang = languagesDict[langId];
|
|
111
|
+
if (!(lang == null ? void 0 : lang.entry)) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
return generateImports(lang.entry);
|
|
115
|
+
});
|
|
116
|
+
const customLanguageImports = ((options == null ? void 0 : options.customLanguages) || []).map(
|
|
117
|
+
({ entry }) => `import '${entry}'`
|
|
118
|
+
);
|
|
119
|
+
const workerCode = generateWorkerCode(
|
|
120
|
+
languageIds,
|
|
121
|
+
languagesDict,
|
|
122
|
+
options == null ? void 0 : options.customLanguages
|
|
123
|
+
);
|
|
124
|
+
return [
|
|
125
|
+
"import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'",
|
|
126
|
+
...featureImports,
|
|
127
|
+
...languageImports,
|
|
128
|
+
...customLanguageImports,
|
|
129
|
+
...workerCode,
|
|
130
|
+
"export * from 'monaco-editor/esm/vs/editor/editor.api'",
|
|
131
|
+
"export default monaco"
|
|
132
|
+
].join("\n");
|
|
133
|
+
} else if (id === VIRTUAL_MODULE_SHIKI_ID) {
|
|
134
|
+
const languageIds = ((_a = options == null ? void 0 : options.shiki) == null ? void 0 : _a.langs) || ((options == null ? void 0 : options.languages) || languages.map((lang) => lang.label)).filter((lang) => lang in bundledLanguages);
|
|
135
|
+
return codegen({
|
|
136
|
+
themes: ((_b = options == null ? void 0 : options.shiki) == null ? void 0 : _b.themes) || ["catppuccin-latte", "catppuccin-mocha"],
|
|
137
|
+
engine: "javascript",
|
|
138
|
+
langs: languageIds,
|
|
139
|
+
typescript: false
|
|
140
|
+
});
|
|
80
141
|
}
|
|
81
|
-
const languagesDict = Object.fromEntries(
|
|
82
|
-
languages.map((lang) => [lang.label, lang])
|
|
83
|
-
);
|
|
84
|
-
const featuresDict = Object.fromEntries(
|
|
85
|
-
features.map((feat) => [feat.label, feat])
|
|
86
|
-
);
|
|
87
|
-
const featuresIds = resolveFeatures(
|
|
88
|
-
options == null ? void 0 : options.features,
|
|
89
|
-
Object.keys(featuresDict)
|
|
90
|
-
);
|
|
91
|
-
const featureImports = featuresIds.flatMap((featureId) => {
|
|
92
|
-
const feature = featuresDict[featureId];
|
|
93
|
-
if (!(feature == null ? void 0 : feature.entry)) {
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
return generateImports(feature.entry);
|
|
97
|
-
});
|
|
98
|
-
const languageIds = (options == null ? void 0 : options.languages) || Object.keys(languagesDict);
|
|
99
|
-
const languageImports = languageIds.flatMap((langId) => {
|
|
100
|
-
const lang = languagesDict[langId];
|
|
101
|
-
if (!(lang == null ? void 0 : lang.entry)) {
|
|
102
|
-
return [];
|
|
103
|
-
}
|
|
104
|
-
return generateImports(lang.entry);
|
|
105
|
-
});
|
|
106
|
-
const customLanguageImports = ((options == null ? void 0 : options.customLanguages) || []).map(
|
|
107
|
-
({ entry }) => `import '${entry}'`
|
|
108
|
-
);
|
|
109
|
-
const workerCode = generateWorkerCode(
|
|
110
|
-
languageIds,
|
|
111
|
-
languagesDict,
|
|
112
|
-
options == null ? void 0 : options.customLanguages
|
|
113
|
-
);
|
|
114
|
-
return [
|
|
115
|
-
"import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'",
|
|
116
|
-
...featureImports,
|
|
117
|
-
...languageImports,
|
|
118
|
-
...customLanguageImports,
|
|
119
|
-
...workerCode,
|
|
120
|
-
"export * from 'monaco-editor/esm/vs/editor/editor.api'",
|
|
121
|
-
"export default monaco"
|
|
122
|
-
].join("\n");
|
|
123
142
|
}
|
|
124
143
|
};
|
|
125
144
|
}
|
|
126
145
|
export {
|
|
127
|
-
|
|
146
|
+
plugin as default
|
|
128
147
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kong-ui-public/monaco-editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/runtime/monaco-editor.umd.js",
|
|
6
6
|
"module": "./dist/runtime/monaco-editor.es.js",
|
|
@@ -46,20 +46,24 @@
|
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@kong/icons": "^1.41.0",
|
|
48
48
|
"@kong/kongponents": ">=9.42.0 <10.0.0",
|
|
49
|
-
"monaco-editor": ">=0.
|
|
49
|
+
"monaco-editor": ">=0.52.0 <1.0.0",
|
|
50
|
+
"shiki": ">=3.0.0 <4.0.0",
|
|
50
51
|
"vue": "^3.5.26",
|
|
51
52
|
"@kong-ui-public/i18n": "^2.4.5"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"@kong/design-tokens": "1.18.2",
|
|
55
56
|
"@kong/icons": "^1.41.0",
|
|
56
|
-
"@kong/kongponents": "9.48.
|
|
57
|
+
"@kong/kongponents": "9.48.8",
|
|
57
58
|
"monaco-editor": "^0.55.1",
|
|
59
|
+
"shiki": "^3.20.0",
|
|
58
60
|
"vue": "^3.5.26",
|
|
59
61
|
"@kong-ui-public/i18n": "^2.4.5"
|
|
60
62
|
},
|
|
61
63
|
"dependencies": {
|
|
62
|
-
"@
|
|
64
|
+
"@shikijs/monaco": "^3.20.0",
|
|
65
|
+
"@vueuse/core": "^14.1.0",
|
|
66
|
+
"shiki-codegen": "^3.20.0"
|
|
63
67
|
},
|
|
64
68
|
"scripts": {
|
|
65
69
|
"dev": "cross-env USE_SANDBOX=true vite",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/singletons/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { editor as Editor, IDisposable } from 'monaco-editor';
|
|
2
|
-
type Scope = {
|
|
3
|
-
type: 'editor';
|
|
4
|
-
source: Editor.ICodeEditor;
|
|
5
|
-
} | {
|
|
6
|
-
type: 'model';
|
|
7
|
-
source: Editor.ITextModel;
|
|
8
|
-
};
|
|
9
|
-
type ScopeSource = Editor.ICodeEditor | Editor.ITextModel;
|
|
10
|
-
/**
|
|
11
|
-
* Track a disposable in the global scope.
|
|
12
|
-
*
|
|
13
|
-
* @param disposable The disposable to track
|
|
14
|
-
*/
|
|
15
|
-
declare function track(disposable: IDisposable, scope?: Scope): IDisposable;
|
|
16
|
-
declare function trackForEditor(editor: Editor.ICodeEditor, disposable: IDisposable): IDisposable;
|
|
17
|
-
declare function trackForModel(model: Editor.ITextModel, disposable: IDisposable): IDisposable;
|
|
18
|
-
declare function disposeScoped(source: ScopeSource): void;
|
|
19
|
-
/**
|
|
20
|
-
* Dispose all tracked disposables.
|
|
21
|
-
*/
|
|
22
|
-
declare function disposeAll(): void;
|
|
23
|
-
export declare const lifecycle: {
|
|
24
|
-
readonly track: typeof track;
|
|
25
|
-
readonly trackForEditor: typeof trackForEditor;
|
|
26
|
-
readonly trackForModel: typeof trackForModel;
|
|
27
|
-
readonly disposeScoped: typeof disposeScoped;
|
|
28
|
-
readonly disposeAll: typeof disposeAll;
|
|
29
|
-
};
|
|
30
|
-
export {};
|
|
31
|
-
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../../../src/singletons/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,MAAM,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAElE,KAAK,KAAK,GACN;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAA;CAAE,CAAA;AAChD,KAAK,WAAW,GAAG,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAA;AAKzD;;;;GAIG;AACH,iBAAS,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,WAAW,CA+ClE;AAED,iBAAS,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE,WAAW,GAAG,WAAW,CAExF;AAED,iBAAS,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,GAAG,WAAW,CAErF;AAED,iBAAS,aAAa,CAAC,MAAM,EAAE,WAAW,QAMzC;AAED;;GAEG;AACH,iBAAS,UAAU,SAIlB;AAED,eAAO,MAAM,SAAS;;;;;;CAMZ,CAAA"}
|