@kong-ui-public/monaco-editor 0.8.0 → 0.8.1-pr.2799.4a7245eab.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.
Potentially problematic release.
This version of @kong-ui-public/monaco-editor might be problematic. Click here for more details.
- package/dist/runtime/monaco-editor.es.js +153 -239
- package/dist/runtime/monaco-editor.umd.js +1 -1
- package/dist/types/src/composables/useMonacoEditor.d.ts.map +1 -1
- package/dist/types/src/singletons/lifecycle.d.ts +25 -19
- package/dist/types/src/singletons/lifecycle.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { toValue as
|
|
2
|
-
import { ProgressIcon as
|
|
3
|
-
import * as
|
|
4
|
-
import { shikiToMonaco as
|
|
5
|
-
import { getSingletonHighlighter as
|
|
6
|
-
import { createI18n as
|
|
7
|
-
const
|
|
1
|
+
import { toValue as b, ref as A, shallowRef as K, reactive as H, watch as I, onMounted as $, onActivated as z, onBeforeUnmount as G, onWatcherCleanup as q, defineComponent as D, resolveComponent as J, createBlock as M, openBlock as C, createSlots as Q, withCtx as x, resolveDynamicComponent as Y, mergeModels as F, useModel as Z, useTemplateRef as X, computed as T, createElementBlock as ee, normalizeClass as te, createElementVNode as oe, renderSlot as R, createVNode as w, Transition as L, createCommentVNode as W, unref as h } from "vue";
|
|
2
|
+
import { ProgressIcon as ae, CodeblockIcon as ne } from "@kong/icons";
|
|
3
|
+
import * as g from "monaco-editor";
|
|
4
|
+
import { shikiToMonaco as re } from "@shikijs/monaco";
|
|
5
|
+
import { getSingletonHighlighter as se, bundledLanguages as ie, bundledThemes as le } from "shiki";
|
|
6
|
+
import { createI18n as ce, i18nTComponent as ue } from "@kong-ui-public/i18n";
|
|
7
|
+
const de = "'JetBrains Mono', Consolas, monospace", me = "12px", ge = "500", fe = "20px", ve = Object.freeze({
|
|
8
8
|
autoClosingQuotes: "always",
|
|
9
9
|
automaticLayout: !0,
|
|
10
10
|
// Auto resize layout
|
|
@@ -13,10 +13,10 @@ const be = "'JetBrains Mono', Consolas, monospace", Ce = "12px", Ee = "500", Me
|
|
|
13
13
|
},
|
|
14
14
|
hideCursorInOverviewRuler: !0,
|
|
15
15
|
// hide the cursor position in the minimap TODO: maybe hide it on first line or change it colour
|
|
16
|
-
fontFamily:
|
|
17
|
-
fontSize: Number(
|
|
18
|
-
fontWeight:
|
|
19
|
-
lineHeight: Number(
|
|
16
|
+
fontFamily: de,
|
|
17
|
+
fontSize: Number(me.replace("px", "")),
|
|
18
|
+
fontWeight: ge,
|
|
19
|
+
lineHeight: Number(fe.replace("px", "")),
|
|
20
20
|
formatOnPaste: !0,
|
|
21
21
|
formatOnType: !0,
|
|
22
22
|
// Add to enable automatic formatting as the user types.
|
|
@@ -59,227 +59,141 @@ const be = "'JetBrains Mono', Consolas, monospace", Ce = "12px", Ee = "500", Me
|
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
62
|
-
const
|
|
62
|
+
const N = () => {
|
|
63
63
|
};
|
|
64
|
-
function
|
|
64
|
+
function he(o, t) {
|
|
65
65
|
function e(...a) {
|
|
66
|
-
return new Promise((
|
|
66
|
+
return new Promise((r, s) => {
|
|
67
67
|
Promise.resolve(o(() => t.apply(this, a), {
|
|
68
68
|
fn: t,
|
|
69
69
|
thisArg: this,
|
|
70
70
|
args: a
|
|
71
|
-
})).then(
|
|
71
|
+
})).then(r).catch(s);
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
return e;
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
let e, a,
|
|
78
|
-
const
|
|
79
|
-
clearTimeout(
|
|
76
|
+
function pe(o, t = {}) {
|
|
77
|
+
let e, a, r = N;
|
|
78
|
+
const s = (d) => {
|
|
79
|
+
clearTimeout(d), r(), r = N;
|
|
80
80
|
};
|
|
81
|
-
let
|
|
82
|
-
return (
|
|
83
|
-
const
|
|
84
|
-
return e &&
|
|
85
|
-
|
|
86
|
-
e &&
|
|
87
|
-
},
|
|
88
|
-
a &&
|
|
89
|
-
},
|
|
81
|
+
let i;
|
|
82
|
+
return (d) => {
|
|
83
|
+
const f = b(o), m = b(t.maxWait);
|
|
84
|
+
return e && s(e), f <= 0 || m !== void 0 && m <= 0 ? (a && (s(a), a = void 0), Promise.resolve(d())) : new Promise((l, v) => {
|
|
85
|
+
r = t.rejectOnCancel ? v : l, i = d, m && !a && (a = setTimeout(() => {
|
|
86
|
+
e && s(e), a = void 0, l(i());
|
|
87
|
+
}, m)), e = setTimeout(() => {
|
|
88
|
+
a && s(a), a = void 0, l(d());
|
|
89
|
+
}, f);
|
|
90
90
|
});
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
// @__NO_SIDE_EFFECTS__
|
|
94
|
-
function
|
|
95
|
-
return
|
|
94
|
+
function ye(o, t = 200, e = {}) {
|
|
95
|
+
return he(pe(t, e), o);
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function U(o) {
|
|
98
98
|
var t;
|
|
99
|
-
const e =
|
|
99
|
+
const e = b(o);
|
|
100
100
|
return (t = e == null ? void 0 : e.$el) !== null && t !== void 0 ? t : e;
|
|
101
101
|
}
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
let e;
|
|
107
|
-
switch (o.type) {
|
|
108
|
-
case "editor":
|
|
109
|
-
e = o.source.onDidDispose(() => K(o.source));
|
|
110
|
-
break;
|
|
111
|
-
case "model":
|
|
112
|
-
e = o.source.onWillDispose(() => K(o.source));
|
|
113
|
-
break;
|
|
114
|
-
default:
|
|
115
|
-
throw new Error(`${F} Unknown scope: ${o}`);
|
|
116
|
-
}
|
|
117
|
-
t = {
|
|
118
|
-
disposables: /* @__PURE__ */ new Set(),
|
|
119
|
-
scopeListener: e
|
|
120
|
-
}, y.set(o.source, t);
|
|
121
|
-
}
|
|
122
|
-
return t;
|
|
123
|
-
}
|
|
124
|
-
function G(o) {
|
|
125
|
-
const t = y.get(o);
|
|
126
|
-
t && (t.scopeListener.dispose(), y.delete(o));
|
|
127
|
-
}
|
|
128
|
-
function A(o, t) {
|
|
129
|
-
Te(t).disposables.add(o);
|
|
130
|
-
}
|
|
131
|
-
function j(o, t) {
|
|
132
|
-
const e = y.get(t.source);
|
|
133
|
-
e && (e.disposables.delete(o), e.disposables.size === 0 && G(t.source));
|
|
134
|
-
}
|
|
135
|
-
function Ie(o) {
|
|
136
|
-
const t = [];
|
|
137
|
-
if (o.forEach((e) => {
|
|
138
|
-
try {
|
|
139
|
-
e.dispose();
|
|
140
|
-
} catch (a) {
|
|
141
|
-
t.push(a);
|
|
142
|
-
}
|
|
143
|
-
}), t.length)
|
|
144
|
-
throw new AggregateError(
|
|
145
|
-
t,
|
|
146
|
-
`${F} One or more disposables threw while being disposed.`
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
function xe(o, t) {
|
|
150
|
-
var l, f;
|
|
151
|
-
let e = o, a = S.get(e);
|
|
152
|
-
if (!a) {
|
|
153
|
-
const s = I.get(o);
|
|
154
|
-
s && (e = s, a = S.get(s));
|
|
155
|
-
}
|
|
156
|
-
if (a)
|
|
157
|
-
return ((l = a.scope) == null ? void 0 : l.type) === (t == null ? void 0 : t.type) && ((f = a.scope) == null ? void 0 : f.source) === (t == null ? void 0 : t.source) || (a.scope && j(a.decorated, a.scope), t ? (A(a.decorated, t), a.scope = t) : a.scope = void 0), a.decorated;
|
|
158
|
-
const i = e.dispose, r = {
|
|
159
|
-
dispose: () => {
|
|
160
|
-
const s = S.get(e);
|
|
161
|
-
if (s)
|
|
162
|
-
return s.scope && j(r, s.scope), S.delete(e), I.delete(r), i.call(e);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
return S.set(e, { decorated: r, scope: t }), I.set(r, e), t && A(r, t), r;
|
|
166
|
-
}
|
|
167
|
-
function V(o, t) {
|
|
168
|
-
return xe(t, { type: "editor", source: o });
|
|
169
|
-
}
|
|
170
|
-
function K(o) {
|
|
171
|
-
const t = y.get(o);
|
|
172
|
-
if (!t) return;
|
|
173
|
-
const e = Array.from(t.disposables);
|
|
174
|
-
try {
|
|
175
|
-
Ie(e);
|
|
176
|
-
} catch (a) {
|
|
177
|
-
console.warn(`${F} Encountered errors while disposing scoped disposables:`, a, ", Source:", o);
|
|
178
|
-
}
|
|
179
|
-
G(o);
|
|
180
|
-
}
|
|
181
|
-
const q = X(!1);
|
|
182
|
-
let b = null;
|
|
183
|
-
async function De() {
|
|
184
|
-
return b || (b = (async () => {
|
|
102
|
+
const P = A(!1);
|
|
103
|
+
let y = null;
|
|
104
|
+
async function Ce() {
|
|
105
|
+
return y || (y = (async () => {
|
|
185
106
|
var o, t;
|
|
186
107
|
try {
|
|
187
|
-
const e = ((o =
|
|
108
|
+
const e = ((o = g.json) == null ? void 0 : o.jsonDefaults) || ((t = g.languages.json) == null ? void 0 : t.jsonDefaults);
|
|
188
109
|
e == null || e.setModeConfiguration({ tokens: !1 });
|
|
189
|
-
const a = await
|
|
110
|
+
const a = await se(
|
|
190
111
|
{
|
|
191
|
-
themes: Object.values(
|
|
192
|
-
langs: Object.values(
|
|
112
|
+
themes: Object.values(le),
|
|
113
|
+
langs: Object.values(ie)
|
|
193
114
|
}
|
|
194
115
|
);
|
|
195
|
-
a.getLoadedLanguages().forEach((
|
|
196
|
-
|
|
197
|
-
}),
|
|
116
|
+
a.getLoadedLanguages().forEach((r) => {
|
|
117
|
+
g.languages.register({ id: r });
|
|
118
|
+
}), re(a, g), P.value = !0;
|
|
198
119
|
} catch (e) {
|
|
199
|
-
throw
|
|
120
|
+
throw y = null, e;
|
|
200
121
|
}
|
|
201
|
-
})(),
|
|
122
|
+
})(), y);
|
|
202
123
|
}
|
|
203
|
-
function
|
|
204
|
-
const e =
|
|
205
|
-
let a,
|
|
206
|
-
const
|
|
124
|
+
function Se(o, t) {
|
|
125
|
+
const e = K();
|
|
126
|
+
let a, r = !1, s = !1;
|
|
127
|
+
const i = H({
|
|
207
128
|
editorStatus: "loading",
|
|
208
129
|
searchBoxIsRevealed: !1,
|
|
209
130
|
hasContent: !1,
|
|
210
131
|
theme: t.theme || "light"
|
|
211
|
-
}),
|
|
212
|
-
!
|
|
213
|
-
},
|
|
214
|
-
var
|
|
215
|
-
return (
|
|
216
|
-
},
|
|
132
|
+
}), p = (n) => {
|
|
133
|
+
!r || !e.value || e.value.setValue(n);
|
|
134
|
+
}, d = (n) => {
|
|
135
|
+
var c;
|
|
136
|
+
return (c = e.value) == null ? void 0 : c.updateOptions({ readOnly: n });
|
|
137
|
+
}, f = () => {
|
|
217
138
|
var n;
|
|
218
139
|
return (n = e.value) == null ? void 0 : n.focus();
|
|
219
|
-
},
|
|
220
|
-
var
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
},
|
|
140
|
+
}, m = (n) => {
|
|
141
|
+
var E;
|
|
142
|
+
const c = (E = e.value) == null ? void 0 : E.getModel();
|
|
143
|
+
c && g.editor.setModelLanguage(c, n);
|
|
144
|
+
}, l = (n) => {
|
|
224
145
|
try {
|
|
225
146
|
if (!e.value || !n) return;
|
|
226
147
|
e.value.focus(), e.value.trigger("keyboard", n, null);
|
|
227
|
-
} catch (
|
|
228
|
-
console.error(`useMonacoEditor: Failed to trigger command: ${n}`,
|
|
148
|
+
} catch (c) {
|
|
149
|
+
console.error(`useMonacoEditor: Failed to trigger command: ${n}`, c);
|
|
229
150
|
}
|
|
230
|
-
},
|
|
151
|
+
}, v = () => {
|
|
231
152
|
var n;
|
|
232
153
|
try {
|
|
233
154
|
if (!e.value) return;
|
|
234
|
-
if (
|
|
155
|
+
if (i.searchBoxIsRevealed)
|
|
235
156
|
return (n = e.value.getContribution("editor.contrib.findController")) == null ? void 0 : n.closeFindWidget();
|
|
236
|
-
|
|
237
|
-
} catch (
|
|
238
|
-
console.error("useMonacoEditor: Failed to close findController.",
|
|
157
|
+
l("actions.find");
|
|
158
|
+
} catch (c) {
|
|
159
|
+
console.error("useMonacoEditor: Failed to close findController.", c);
|
|
239
160
|
}
|
|
240
|
-
},
|
|
161
|
+
}, S = /* @__PURE__ */ ye(() => g.editor.remeasureFonts(), 200);
|
|
241
162
|
return (() => {
|
|
242
|
-
|
|
243
|
-
var
|
|
244
|
-
const
|
|
245
|
-
if (!(
|
|
246
|
-
|
|
163
|
+
Ce(), I([P, () => b(o)], ([n, c], [, E]) => {
|
|
164
|
+
var k;
|
|
165
|
+
const O = U(c), V = U(E);
|
|
166
|
+
if (!(O instanceof HTMLElement) || !n) {
|
|
167
|
+
r = !1;
|
|
247
168
|
return;
|
|
248
169
|
}
|
|
249
|
-
if (!(
|
|
170
|
+
if (!(r && V === O)) {
|
|
250
171
|
if (!a) {
|
|
251
|
-
const u =
|
|
252
|
-
a =
|
|
172
|
+
const u = g.Uri.parse(`inmemory://model/${t.language}-${crypto.randomUUID()}`);
|
|
173
|
+
a = g.editor.createModel(t.code.value, t.language, u);
|
|
253
174
|
}
|
|
254
|
-
e.value =
|
|
255
|
-
...
|
|
175
|
+
e.value = g.editor.create(O, {
|
|
176
|
+
...ve,
|
|
256
177
|
readOnly: t.readOnly || !1,
|
|
257
178
|
language: t.language,
|
|
258
|
-
theme:
|
|
179
|
+
theme: i.theme === "light" ? "catppuccin-latte" : "catppuccin-mocha",
|
|
259
180
|
model: a,
|
|
260
181
|
editContext: !1,
|
|
261
182
|
...t.monacoOptions
|
|
262
|
-
}),
|
|
263
|
-
|
|
264
|
-
e.value.
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
l.hasContent = !!u.length, t.code.value = u;
|
|
268
|
-
})
|
|
269
|
-
), (L = t.onReady) == null || L.call(t, e.value), E();
|
|
183
|
+
}), r = !0, i.editorStatus = "ready", i.hasContent = !!t.code.value, e.value.onDidChangeModelContent(() => {
|
|
184
|
+
if (s) return;
|
|
185
|
+
const u = e.value.getValue();
|
|
186
|
+
i.hasContent = !!u.length, t.code.value = u;
|
|
187
|
+
}), (k = t.onReady) == null || k.call(t, e.value), S();
|
|
270
188
|
try {
|
|
271
189
|
const u = e.value.getContribution("editor.contrib.findController"), _ = u == null ? void 0 : u.getState();
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
l.searchBoxIsRevealed = _.isRevealed;
|
|
276
|
-
})
|
|
277
|
-
// This returns a disposable
|
|
278
|
-
);
|
|
190
|
+
_ == null || _.onFindReplaceStateChange(() => {
|
|
191
|
+
i.searchBoxIsRevealed = _.isRevealed;
|
|
192
|
+
});
|
|
279
193
|
} catch (u) {
|
|
280
194
|
console.error("useMonacoEditor: Failed to get the state of findController", u);
|
|
281
195
|
}
|
|
282
|
-
|
|
196
|
+
q(() => {
|
|
283
197
|
var u;
|
|
284
198
|
(u = e.value) == null || u.dispose();
|
|
285
199
|
});
|
|
@@ -288,50 +202,50 @@ function Fe(o, t) {
|
|
|
288
202
|
immediate: !0,
|
|
289
203
|
flush: "post"
|
|
290
204
|
});
|
|
291
|
-
})(),
|
|
292
|
-
if (!e.value || !a || !
|
|
293
|
-
const
|
|
294
|
-
n !==
|
|
205
|
+
})(), I(t.code, (n) => {
|
|
206
|
+
if (!e.value || !a || !r) return;
|
|
207
|
+
const c = a.getValue();
|
|
208
|
+
n !== c && (s = !0, e.value.executeEdits("external", [
|
|
295
209
|
{
|
|
296
210
|
range: a.getFullModelRange(),
|
|
297
211
|
text: n
|
|
298
212
|
}
|
|
299
|
-
]), e.value.pushUndoStop(),
|
|
300
|
-
}),
|
|
213
|
+
]), e.value.pushUndoStop(), i.hasContent = !!n.length, s = !1);
|
|
214
|
+
}), $(S), z(S), G(() => {
|
|
301
215
|
if (!e.value) return;
|
|
302
216
|
const n = e.value.getModel();
|
|
303
217
|
e.value.dispose(), n && n.dispose();
|
|
304
218
|
}), {
|
|
305
219
|
editor: e,
|
|
306
|
-
editorStates:
|
|
307
|
-
setContent:
|
|
308
|
-
setReadOnly:
|
|
309
|
-
focus:
|
|
310
|
-
setLanguage:
|
|
311
|
-
remeasureFonts:
|
|
312
|
-
toggleSearchWidget:
|
|
313
|
-
triggerKeyboardCommand:
|
|
220
|
+
editorStates: i,
|
|
221
|
+
setContent: p,
|
|
222
|
+
setReadOnly: d,
|
|
223
|
+
focus: f,
|
|
224
|
+
setLanguage: m,
|
|
225
|
+
remeasureFonts: S,
|
|
226
|
+
toggleSearchWidget: v,
|
|
227
|
+
triggerKeyboardCommand: l
|
|
314
228
|
};
|
|
315
229
|
}
|
|
316
|
-
const
|
|
230
|
+
const Ee = {
|
|
317
231
|
messages: {
|
|
318
232
|
empty_message: "The editor is currently empty. Start typing to add content.",
|
|
319
233
|
empty_title: "No content available",
|
|
320
234
|
loading_message: "Please wait while the {type} content is loaded.",
|
|
321
235
|
loading_title: "{type} editor"
|
|
322
236
|
}
|
|
323
|
-
},
|
|
324
|
-
editor:
|
|
237
|
+
}, _e = {
|
|
238
|
+
editor: Ee
|
|
325
239
|
};
|
|
326
|
-
function
|
|
327
|
-
const o =
|
|
240
|
+
function be() {
|
|
241
|
+
const o = ce("en-us", _e);
|
|
328
242
|
return {
|
|
329
243
|
i18n: o,
|
|
330
|
-
i18nT:
|
|
244
|
+
i18nT: ue(o)
|
|
331
245
|
// Translation component <i18n-t>
|
|
332
246
|
};
|
|
333
247
|
}
|
|
334
|
-
const
|
|
248
|
+
const Me = /* @__PURE__ */ D({
|
|
335
249
|
__name: "MonacoEditorStatusOverlay",
|
|
336
250
|
props: {
|
|
337
251
|
title: {},
|
|
@@ -340,30 +254,30 @@ const Ne = /* @__PURE__ */ H({
|
|
|
340
254
|
},
|
|
341
255
|
setup(o) {
|
|
342
256
|
return (t, e) => {
|
|
343
|
-
const a =
|
|
344
|
-
return C(),
|
|
257
|
+
const a = J("KEmptyState");
|
|
258
|
+
return C(), M(a, {
|
|
345
259
|
class: "monaco-editor-status-overlay",
|
|
346
260
|
message: o.message,
|
|
347
261
|
title: o.title
|
|
348
|
-
},
|
|
262
|
+
}, Q({ _: 2 }, [
|
|
349
263
|
o.icon ? {
|
|
350
264
|
name: "icon",
|
|
351
|
-
fn:
|
|
352
|
-
(C(),
|
|
265
|
+
fn: x(() => [
|
|
266
|
+
(C(), M(Y(o.icon), { decorative: "" }))
|
|
353
267
|
]),
|
|
354
268
|
key: "0"
|
|
355
269
|
} : void 0
|
|
356
270
|
]), 1032, ["message", "title"]);
|
|
357
271
|
};
|
|
358
272
|
}
|
|
359
|
-
}),
|
|
273
|
+
}), j = (o, t) => {
|
|
360
274
|
const e = o.__vccOpts || o;
|
|
361
|
-
for (const [a,
|
|
362
|
-
e[a] =
|
|
275
|
+
for (const [a, r] of t)
|
|
276
|
+
e[a] = r;
|
|
363
277
|
return e;
|
|
364
|
-
},
|
|
278
|
+
}, B = /* @__PURE__ */ j(Me, [["__scopeId", "data-v-062eadb5"]]), Oe = /* @__PURE__ */ D({
|
|
365
279
|
__name: "MonacoEditor",
|
|
366
|
-
props: /* @__PURE__ */
|
|
280
|
+
props: /* @__PURE__ */ F({
|
|
367
281
|
theme: { default: "light" },
|
|
368
282
|
language: { default: "markdown" },
|
|
369
283
|
loading: { type: Boolean, default: !1 },
|
|
@@ -376,66 +290,66 @@ const Ne = /* @__PURE__ */ H({
|
|
|
376
290
|
},
|
|
377
291
|
modelModifiers: {}
|
|
378
292
|
}),
|
|
379
|
-
emits: /* @__PURE__ */
|
|
293
|
+
emits: /* @__PURE__ */ F(["ready"], ["update:modelValue"]),
|
|
380
294
|
setup(o, { expose: t, emit: e }) {
|
|
381
|
-
const a = e,
|
|
295
|
+
const a = e, r = Z(o, "modelValue"), { i18n: s } = be(), i = X("editorRef"), p = T(() => o.theme === "dark" ? "dark" : "light"), d = T(() => m.editorStates.editorStatus === "loading" || o.loading), f = T(() => m.editorStates.editorStatus === "ready" && !m.editorStates.hasContent), m = Se(i, {
|
|
382
296
|
language: o.language,
|
|
383
|
-
code:
|
|
384
|
-
theme:
|
|
297
|
+
code: r,
|
|
298
|
+
theme: p.value,
|
|
385
299
|
monacoOptions: o.options,
|
|
386
|
-
onReady: (
|
|
387
|
-
a("ready",
|
|
300
|
+
onReady: (l) => {
|
|
301
|
+
a("ready", l);
|
|
388
302
|
}
|
|
389
303
|
});
|
|
390
304
|
return t({
|
|
391
|
-
monacoEditor:
|
|
392
|
-
}),
|
|
393
|
-
|
|
394
|
-
}), (
|
|
395
|
-
class:
|
|
396
|
-
|
|
397
|
-
{ loading:
|
|
305
|
+
monacoEditor: m
|
|
306
|
+
}), I(() => o.language, (l, v) => {
|
|
307
|
+
l !== v && m.setLanguage(l);
|
|
308
|
+
}), (l, v) => (C(), ee("div", {
|
|
309
|
+
class: te(["monaco-editor-container", [
|
|
310
|
+
p.value,
|
|
311
|
+
{ loading: d.value }
|
|
398
312
|
]]),
|
|
399
313
|
"data-testid": "monaco-editor-container"
|
|
400
314
|
}, [
|
|
401
|
-
|
|
315
|
+
oe("div", {
|
|
402
316
|
ref_key: "editorRef",
|
|
403
|
-
ref:
|
|
317
|
+
ref: i,
|
|
404
318
|
class: "monaco-editor-target",
|
|
405
319
|
"data-testid": "monaco-editor-target"
|
|
406
320
|
}, null, 512),
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
default:
|
|
410
|
-
|
|
321
|
+
R(l.$slots, "state-loading", { isLoading: d.value }, () => [
|
|
322
|
+
w(L, { name: "fade" }, {
|
|
323
|
+
default: x(() => [
|
|
324
|
+
d.value ? (C(), M(B, {
|
|
411
325
|
key: 0,
|
|
412
326
|
"data-testid": "monaco-editor-status-overlay-loading",
|
|
413
|
-
icon:
|
|
414
|
-
message:
|
|
415
|
-
title:
|
|
416
|
-
}, null, 8, ["icon", "message", "title"])) :
|
|
327
|
+
icon: h(ae),
|
|
328
|
+
message: h(s).t("editor.messages.loading_message", { type: o.language }),
|
|
329
|
+
title: h(s).t("editor.messages.loading_title", { type: o.language })
|
|
330
|
+
}, null, 8, ["icon", "message", "title"])) : W("", !0)
|
|
417
331
|
]),
|
|
418
332
|
_: 1
|
|
419
333
|
})
|
|
420
334
|
], !0),
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
default:
|
|
424
|
-
|
|
335
|
+
R(l.$slots, "state-empty", { isEmpty: f.value }, () => [
|
|
336
|
+
w(L, { name: "fade" }, {
|
|
337
|
+
default: x(() => [
|
|
338
|
+
f.value && !d.value ? (C(), M(B, {
|
|
425
339
|
key: 0,
|
|
426
340
|
"data-testid": "monaco-editor-status-overlay-empty",
|
|
427
|
-
icon:
|
|
428
|
-
message:
|
|
429
|
-
title:
|
|
430
|
-
}, null, 8, ["icon", "message", "title"])) :
|
|
341
|
+
icon: h(ne),
|
|
342
|
+
message: h(s).t("editor.messages.empty_message"),
|
|
343
|
+
title: h(s).t("editor.messages.empty_title")
|
|
344
|
+
}, null, 8, ["icon", "message", "title"])) : W("", !0)
|
|
431
345
|
]),
|
|
432
346
|
_: 1
|
|
433
347
|
})
|
|
434
348
|
], !0)
|
|
435
349
|
], 2));
|
|
436
350
|
}
|
|
437
|
-
}),
|
|
351
|
+
}), we = /* @__PURE__ */ j(Oe, [["__scopeId", "data-v-e2083635"]]);
|
|
438
352
|
export {
|
|
439
|
-
|
|
440
|
-
|
|
353
|
+
we as MonacoEditor,
|
|
354
|
+
Se as useMonacoEditor
|
|
441
355
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(d,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):(d=typeof globalThis<"u"?globalThis:d||self,e(d["kong-ui-public-monaco-editor"]={},d.Vue,d.KongIcons,d.monaco,d.monaco$1,d.shiki,d["kong-ui-public-i18n"]))})(this,function(d,e,k,L,R,O,I){"use strict";function U(o){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(n,t,a.get?a:{enumerable:!0,get:()=>o[t]})}}return n.default=o,Object.freeze(n)}const p=U(L),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 T=()=>{};function W(o,n){function t(...a){return new Promise((i,s)=>{Promise.resolve(o(()=>n.apply(this,a),{fn:n,thisArg:this,args:a})).then(i).catch(s)})}return t}function D(o,n={}){let t,a,i=T;const s=g=>{clearTimeout(g),i(),i=T};let l;return g=>{const h=e.toValue(o),f=e.toValue(n.maxWait);return t&&s(t),h<=0||f!==void 0&&f<=0?(a&&(s(a),a=void 0),Promise.resolve(g())):new Promise((c,y)=>{i=n.rejectOnCancel?y:c,l=g,f&&!a&&(a=setTimeout(()=>{t&&s(t),a=void 0,c(l())},f)),t=setTimeout(()=>{a&&s(a),a=void 0,c(g())},h)})}}function V(o,n=200,t={}){return W(D(n,t),o)}function x(o){var n;const t=e.toValue(o);return(n=t==null?void 0:t.$el)!==null&&n!==void 0?n:t}const v=e.ref(!1);let _=null;async function P(){return _||(_=(async()=>{var o,n;try{const t=((o=p.json)==null?void 0:o.jsonDefaults)||((n=p.languages.json)==null?void 0:n.jsonDefaults);t==null||t.setModeConfiguration({tokens:!1});const a=await O.getSingletonHighlighter({themes:Object.values(O.bundledThemes),langs:Object.values(O.bundledLanguages)});a.getLoadedLanguages().forEach(i=>{p.languages.register({id:i})}),R.shikiToMonaco(a,p),v.value=!0}catch(t){throw _=null,t}})(),_)}function w(o,n){const t=e.shallowRef();let a,i=!1,s=!1;const l=e.reactive({editorStatus:"loading",searchBoxIsRevealed:!1,hasContent:!1,theme:n.theme||"light"}),C=r=>{!i||!t.value||t.value.setValue(r)},g=r=>{var u;return(u=t.value)==null?void 0:u.updateOptions({readOnly:r})},h=()=>{var r;return(r=t.value)==null?void 0:r.focus()},f=r=>{var E;const u=(E=t.value)==null?void 0:E.getModel();u&&p.editor.setModelLanguage(u,r)},c=r=>{try{if(!t.value||!r)return;t.value.focus(),t.value.trigger("keyboard",r,null)}catch(u){console.error(`useMonacoEditor: Failed to trigger command: ${r}`,u)}},y=()=>{var r;try{if(!t.value)return;if(l.searchBoxIsRevealed)return(r=t.value.getContribution("editor.contrib.findController"))==null?void 0:r.closeFindWidget();c("actions.find")}catch(u){console.error("useMonacoEditor: Failed to close findController.",u)}},S=V(()=>p.editor.remeasureFonts(),200);return(()=>{P(),e.watch([v,()=>e.toValue(o)],([r,u],[,E])=>{var B;const b=x(u),$=x(E);if(!(b instanceof HTMLElement)||!r){i=!1;return}if(!(i&&$===b)){if(!a){const m=p.Uri.parse(`inmemory://model/${n.language}-${crypto.randomUUID()}`);a=p.editor.createModel(n.code.value,n.language,m)}t.value=p.editor.create(b,{...j,readOnly:n.readOnly||!1,language:n.language,theme:l.theme==="light"?"catppuccin-latte":"catppuccin-mocha",model:a,editContext:!1,...n.monacoOptions}),i=!0,l.editorStatus="ready",l.hasContent=!!n.code.value,t.value.onDidChangeModelContent(()=>{if(s)return;const m=t.value.getValue();l.hasContent=!!m.length,n.code.value=m}),(B=n.onReady)==null||B.call(n,t.value),S();try{const m=t.value.getContribution("editor.contrib.findController"),M=m==null?void 0:m.getState();M==null||M.onFindReplaceStateChange(()=>{l.searchBoxIsRevealed=M.isRevealed})}catch(m){console.error("useMonacoEditor: Failed to get the state of findController",m)}e.onWatcherCleanup(()=>{var m;(m=t.value)==null||m.dispose()})}},{immediate:!0,flush:"post"})})(),e.watch(n.code,r=>{if(!t.value||!a||!i)return;const u=a.getValue();r!==u&&(s=!0,t.value.executeEdits("external",[{range:a.getFullModelRange(),text:r}]),t.value.pushUndoStop(),l.hasContent=!!r.length,s=!1)}),e.onMounted(S),e.onActivated(S),e.onBeforeUnmount(()=>{if(!t.value)return;const r=t.value.getModel();t.value.dispose(),r&&r.dispose()}),{editor:t,editorStates:l,setContent:C,setReadOnly:g,focus:h,setLanguage:f,remeasureFonts:S,toggleSearchWidget:y,triggerKeyboardCommand:c}}const K={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 H(){const o=I.createI18n("en-us",K);return{i18n:o,i18nT:I.i18nTComponent(o)}}const q=e.defineComponent({__name:"MonacoEditorStatusOverlay",props:{title:{},message:{},icon:{}},setup(o){return(n,t)=>{const a=e.resolveComponent("KEmptyState");return e.openBlock(),e.createBlock(a,{class:"monaco-editor-status-overlay",message:o.message,title:o.title},e.createSlots({_:2},[o.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.icon),{decorative:""}))]),key:"0"}:void 0]),1032,["message","title"])}}}),F=(o,n)=>{const t=o.__vccOpts||o;for(const[a,i]of n)t[a]=i;return t},N=F(q,[["__scopeId","data-v-062eadb5"]]),A=F(e.defineComponent({__name:"MonacoEditor",props:e.mergeModels({theme:{default:"light"},language:{default:"markdown"},loading:{type:Boolean,default:!1},options:{default:()=>{}}},{modelValue:{type:String,required:!0},modelModifiers:{}}),emits:e.mergeModels(["ready"],["update:modelValue"]),setup(o,{expose:n,emit:t}){const a=t,i=e.useModel(o,"modelValue"),{i18n:s}=H(),l=e.useTemplateRef("editorRef"),C=e.computed(()=>o.theme==="dark"?"dark":"light"),g=e.computed(()=>f.editorStates.editorStatus==="loading"||o.loading),h=e.computed(()=>f.editorStates.editorStatus==="ready"&&!f.editorStates.hasContent),f=w(l,{language:o.language,code:i,theme:C.value,monacoOptions:o.options,onReady:c=>{a("ready",c)}});return n({monacoEditor:f}),e.watch(()=>o.language,(c,y)=>{c!==y&&f.setLanguage(c)}),(c,y)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["monaco-editor-container",[C.value,{loading:g.value}]]),"data-testid":"monaco-editor-container"},[e.createElementVNode("div",{ref_key:"editorRef",ref:l,class:"monaco-editor-target","data-testid":"monaco-editor-target"},null,512),e.renderSlot(c.$slots,"state-loading",{isLoading:g.value},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[g.value?(e.openBlock(),e.createBlock(N,{key:0,"data-testid":"monaco-editor-status-overlay-loading",icon:e.unref(k.ProgressIcon),message:e.unref(s).t("editor.messages.loading_message",{type:o.language}),title:e.unref(s).t("editor.messages.loading_title",{type:o.language})},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0),e.renderSlot(c.$slots,"state-empty",{isEmpty:h.value},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[h.value&&!g.value?(e.openBlock(),e.createBlock(N,{key:0,"data-testid":"monaco-editor-status-overlay-empty",icon:e.unref(k.CodeblockIcon),message:e.unref(s).t("editor.messages.empty_message"),title:e.unref(s).t("editor.messages.empty_title")},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0)],2))}}),[["__scopeId","data-v-e2083635"]]);d.MonacoEditor=A,d.useMonacoEditor=w,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMonacoEditor.d.ts","sourceRoot":"","sources":["../../../../src/composables/useMonacoEditor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;
|
|
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;AAyC1E;;;;;EAKE;AACF,wBAAgB,eAAe,CAAC,CAAC,SAAS,YAAY,EACpD,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,EAClC,OAAO,EAAE,sBAAsB;;;;;;;;0BA2BF,MAAM,KAAG,IAAI;4BAOX,OAAO,KAAG,IAAI;iBAG3B,IAAI;4BAES,MAAM,KAAG,IAAI;;8BAuBb,IAAI;iCAXC,MAAM,KAAG,IAAI;EAyKlD"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Lifecycle tracker for {@link IDisposable disposables} in Monaco Editor.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Although it's usually okay to register listeners on a model/editor without manually
|
|
5
|
+
* calling `.dispose()` before or after disposing the model/editor itself, which may
|
|
6
|
+
* also apply to other disposables, as long as the scope they are attached to correctly
|
|
7
|
+
* disposes them (though such bugs once existed in Monaco Editor), it's still a good
|
|
8
|
+
* practice to dispose when a resource is no longer needed.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* > Many Monaco related objects often implement the `.dispose()` method. This method
|
|
11
|
+
* > is intended to perform cleanups when a resource is no longer needed. For example,
|
|
12
|
+
* > calling `model.dispose()` will unregister it, freeing up the URI for a new model.
|
|
13
|
+
* > Editors should be disposed to free up resources and remove their model listeners.
|
|
14
|
+
* > (from https://github.com/microsoft/monaco-editor/blob/de983bf5d7efbd36622f44bc0e44097a0531a58c/README.md#disposables)
|
|
12
15
|
*
|
|
13
|
-
* This tracker is designed to be a singleton to track disposables in
|
|
14
|
-
* mentioned above.
|
|
16
|
+
* This tracker is designed to be a singleton to track disposables in different scopes.
|
|
15
17
|
*/
|
|
16
|
-
import {
|
|
18
|
+
import type { editor as Editor, IDisposable } from 'monaco-editor';
|
|
17
19
|
/**
|
|
18
20
|
* A type friendly representation of a scope.
|
|
19
21
|
*/
|
|
@@ -31,8 +33,8 @@ type ScopeSource = Editor.ICodeEditor | Editor.ITextModel;
|
|
|
31
33
|
/**
|
|
32
34
|
* Track a disposable in an optional scope.
|
|
33
35
|
*
|
|
34
|
-
* **
|
|
35
|
-
*
|
|
36
|
+
* **NOTE**: It's not recommended to call {@link IDisposable.dispose dispose} on the
|
|
37
|
+
* original disposable being passed in after being tracked.
|
|
36
38
|
*
|
|
37
39
|
* @param disposable - The disposable to track. When passing a decorated disposable,
|
|
38
40
|
* the **SAME** decorated disposable will be **UPDATED** (if scope changes)
|
|
@@ -42,38 +44,42 @@ type ScopeSource = Editor.ICodeEditor | Editor.ITextModel;
|
|
|
42
44
|
*
|
|
43
45
|
* @returns A decorated disposable to dispose the disposable and untrack it.
|
|
44
46
|
*/
|
|
45
|
-
export declare function
|
|
47
|
+
export declare function trackDisposable(disposable: IDisposable, scope?: Scope): IDisposable;
|
|
46
48
|
/**
|
|
47
49
|
* Track a disposable for an {@link Editor.ICodeEditor editor}.
|
|
48
50
|
*
|
|
49
51
|
* The tracker uses {@link Editor.ICodeEditor.onDidDispose onDidDispose} to dispose
|
|
50
|
-
* the tracked disposable.
|
|
52
|
+
* the tracked disposable automatically upon editor disposal.
|
|
51
53
|
*
|
|
52
54
|
* @param editor - The editor to track
|
|
53
55
|
* @param disposable - The disposable to track
|
|
54
56
|
* @returns A decorated disposable to dispose the disposable and untrack it.
|
|
55
57
|
*/
|
|
56
|
-
export declare function
|
|
58
|
+
export declare function trackDisposableForEditor(editor: Editor.ICodeEditor, disposable: IDisposable): IDisposable;
|
|
57
59
|
/**
|
|
58
60
|
* Track a disposable for a {@link Editor.ITextModel text model}.
|
|
59
61
|
*
|
|
60
62
|
* The tracker uses {@link Editor.ITextModel.onWillDispose onWillDispose} to dispose
|
|
61
|
-
* the tracked disposable.
|
|
63
|
+
* the tracked disposable automatically upon model disposal.
|
|
62
64
|
*
|
|
63
65
|
* @param model - The text model to track
|
|
64
66
|
* @param disposable - The disposable to track
|
|
65
67
|
* @returns A decorated disposable to dispose the disposable and untrack it.
|
|
66
68
|
*/
|
|
67
|
-
export declare function
|
|
69
|
+
export declare function trackDisposableForModel(model: Editor.ITextModel, disposable: IDisposable): IDisposable;
|
|
68
70
|
/**
|
|
69
71
|
* Dispose all tracked disposables in a scope.
|
|
70
72
|
*
|
|
71
73
|
* @param source - The scope source whose tracked disposables to dispose.
|
|
72
74
|
*/
|
|
73
|
-
export declare function
|
|
75
|
+
export declare function disposeScopedDisposables(source: ScopeSource): void;
|
|
76
|
+
/**
|
|
77
|
+
* Dispose all globally tracked disposables.
|
|
78
|
+
*/
|
|
79
|
+
export declare function disposeGlobalDisposables(): void;
|
|
74
80
|
/**
|
|
75
81
|
* Dispose all tracked disposables.
|
|
76
82
|
*/
|
|
77
|
-
export declare function
|
|
83
|
+
export declare function disposeAllDisposables(): void;
|
|
78
84
|
export {};
|
|
79
85
|
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../../../src/singletons/lifecycle.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../../../src/singletons/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,MAAM,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAIlE;;GAEG;AACH,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;AAEhD;;GAEG;AACH,KAAK,WAAW,GAAG,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAA;AAuHzD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,WAAW,CAgEnF;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE,WAAW,GAAG,WAAW,CAEzG;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,GAAG,WAAW,CAEtG;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,CAUlE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAU/C;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAW5C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kong-ui-public/monaco-editor",
|
|
3
|
-
"version": "0.8.0",
|
|
3
|
+
"version": "0.8.1-pr.2799.4a7245eab.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A kong UI Monaco Editor wrapper for Vue 3 with syntax highlighting powered by Shiki.",
|
|
6
6
|
"main": "./dist/runtime/monaco-editor.umd.js",
|