@kong-ui-public/monaco-editor 0.4.11-pr.2769.31aadbf56.0 → 0.4.11
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 +144 -209
- package/dist/runtime/monaco-editor.umd.js +1 -1
- package/dist/types/src/composables/useMonacoEditor.d.ts +1 -1
- package/dist/types/src/composables/useMonacoEditor.d.ts.map +1 -1
- package/package.json +2 -2
- 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,8 @@
|
|
|
1
|
-
import { toValue as
|
|
2
|
-
import { ProgressIcon as
|
|
3
|
-
import * as
|
|
4
|
-
import { createI18n as
|
|
5
|
-
|
|
6
|
-
const R = () => {
|
|
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 C, reactive as U, onMounted as D, onActivated as P, onBeforeUnmount as V, watch as K, defineComponent as N, resolveComponent as A, createBlock as S, openBlock as y, createSlots as $, withCtx as E, resolveDynamicComponent as z, mergeModels as H, useModel as G, useTemplateRef as j, computed as M, createElementBlock as q, normalizeClass as J, unref as c, createElementVNode as Q, renderSlot as I, createVNode as T, Transition as k, createCommentVNode as w } from "vue";
|
|
2
|
+
import { ProgressIcon as Y, CodeblockIcon as Z } from "@kong/icons";
|
|
3
|
+
import * as _ from "monaco-editor";
|
|
4
|
+
import { createI18n as X, i18nTComponent as ee } from "@kong-ui-public/i18n";
|
|
5
|
+
const te = "'JetBrains Mono', Consolas, monospace", oe = "12px", ne = "500", ae = "20px", re = Object.freeze({
|
|
47
6
|
autoClosingQuotes: "always",
|
|
48
7
|
automaticLayout: !0,
|
|
49
8
|
// Auto resize layout
|
|
@@ -52,10 +11,10 @@ const ue = "'JetBrains Mono', Consolas, monospace", me = "12px", fe = "500", ge
|
|
|
52
11
|
},
|
|
53
12
|
hideCursorInOverviewRuler: !0,
|
|
54
13
|
// 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(
|
|
14
|
+
fontFamily: te,
|
|
15
|
+
fontSize: Number(oe.replace("px", "")),
|
|
16
|
+
fontWeight: ne,
|
|
17
|
+
lineHeight: Number(ae.replace("px", "")),
|
|
59
18
|
formatOnPaste: !0,
|
|
60
19
|
formatOnType: !0,
|
|
61
20
|
// Add to enable automatic formatting as the user types.
|
|
@@ -97,176 +56,152 @@ const ue = "'JetBrains Mono', Consolas, monospace", me = "12px", fe = "500", ge
|
|
|
97
56
|
// we need this set to false to get the correct absolute position, otherwise when the search box opens the content shifts
|
|
98
57
|
}
|
|
99
58
|
});
|
|
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
|
-
}
|
|
59
|
+
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
60
|
+
const x = () => {
|
|
61
|
+
};
|
|
62
|
+
function ie(o, t) {
|
|
63
|
+
function e(...n) {
|
|
64
|
+
return new Promise((r, i) => {
|
|
65
|
+
Promise.resolve(o(() => t.apply(this, n), {
|
|
66
|
+
fn: t,
|
|
67
|
+
thisArg: this,
|
|
68
|
+
args: n
|
|
69
|
+
})).then(r).catch(i);
|
|
70
|
+
});
|
|
128
71
|
}
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
function pe(o, t) {
|
|
132
|
-
return O(t, { type: "editor", source: o });
|
|
72
|
+
return e;
|
|
133
73
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
74
|
+
function se(o, t = {}) {
|
|
75
|
+
let e, n, r = x;
|
|
76
|
+
const i = (l) => {
|
|
77
|
+
clearTimeout(l), r(), r = x;
|
|
78
|
+
};
|
|
79
|
+
let s;
|
|
80
|
+
return (l) => {
|
|
81
|
+
const p = C(o), d = C(t.maxWait);
|
|
82
|
+
return e && i(e), p <= 0 || d !== void 0 && d <= 0 ? (n && (i(n), n = void 0), Promise.resolve(l())) : new Promise((v, a) => {
|
|
83
|
+
r = t.rejectOnCancel ? a : v, s = l, d && !n && (n = setTimeout(() => {
|
|
84
|
+
e && i(e), n = void 0, v(s());
|
|
85
|
+
}, d)), e = setTimeout(() => {
|
|
86
|
+
n && i(n), n = void 0, v(l());
|
|
87
|
+
}, p);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
136
90
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
91
|
+
// @__NO_SIDE_EFFECTS__
|
|
92
|
+
function le(o, t = 200, e = {}) {
|
|
93
|
+
return ie(se(t, e), o);
|
|
140
94
|
}
|
|
141
|
-
function
|
|
142
|
-
|
|
95
|
+
function de(o) {
|
|
96
|
+
var t;
|
|
97
|
+
const e = C(o);
|
|
98
|
+
return (t = e == null ? void 0 : e.$el) !== null && t !== void 0 ? t : e;
|
|
143
99
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
disposeScoped: b,
|
|
149
|
-
disposeAll: ye
|
|
150
|
-
};
|
|
151
|
-
let v;
|
|
152
|
-
const B = /* @__PURE__ */ new Map();
|
|
153
|
-
function Ce(o) {
|
|
154
|
-
return v || (v = M), o && !B.get(o) && (B.set(o, !0), M.languages.getLanguages().some((t) => t.id === o) || M.languages.register({ id: o })), v;
|
|
100
|
+
let g;
|
|
101
|
+
const F = /* @__PURE__ */ new Map();
|
|
102
|
+
function ce(o) {
|
|
103
|
+
return g || (g = _), o && !F.get(o) && (F.set(o, !0), _.languages.getLanguages().some((t) => t.id === o) || _.languages.register({ id: o })), g;
|
|
155
104
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const n = z({
|
|
105
|
+
function ue(o, t) {
|
|
106
|
+
let e, n = !1;
|
|
107
|
+
const r = U({
|
|
160
108
|
editorStatus: "loading",
|
|
161
109
|
searchBoxIsRevealed: !1,
|
|
162
110
|
hasContent: !1,
|
|
163
111
|
theme: t.theme || "light"
|
|
164
112
|
}), i = (a) => {
|
|
165
|
-
!
|
|
166
|
-
}, s = (a) => {
|
|
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) => {
|
|
113
|
+
!n || !e || e.setValue(a);
|
|
114
|
+
}, s = (a) => e == null ? void 0 : e.updateOptions({ readOnly: a }), u = () => e == null ? void 0 : e.focus(), l = (a) => {
|
|
173
115
|
try {
|
|
174
|
-
if (!e
|
|
175
|
-
e.
|
|
176
|
-
} catch (
|
|
177
|
-
console.error(`useMonacoEditor: Failed to trigger command: ${a}`,
|
|
116
|
+
if (!e || !a) return;
|
|
117
|
+
e.focus(), e.trigger("keyboard", a, null);
|
|
118
|
+
} catch (f) {
|
|
119
|
+
console.error(`useMonacoEditor: Failed to trigger command: ${a}`, f);
|
|
178
120
|
}
|
|
179
|
-
},
|
|
121
|
+
}, p = () => {
|
|
180
122
|
var a;
|
|
181
123
|
try {
|
|
182
|
-
if (!e
|
|
183
|
-
if (
|
|
184
|
-
return (a = e.
|
|
124
|
+
if (!e) return;
|
|
125
|
+
if (r.searchBoxIsRevealed)
|
|
126
|
+
return (a = e.getContribution("editor.contrib.findController")) == null ? void 0 : a.closeFindWidget();
|
|
185
127
|
l("actions.find");
|
|
186
|
-
} catch (
|
|
187
|
-
console.error("useMonacoEditor: Failed to close findController.",
|
|
128
|
+
} catch (f) {
|
|
129
|
+
console.error("useMonacoEditor: Failed to close findController.", f);
|
|
188
130
|
}
|
|
189
|
-
},
|
|
131
|
+
}, d = /* @__PURE__ */ le(() => g == null ? void 0 : g.editor.remeasureFonts(), 200);
|
|
190
132
|
return (() => {
|
|
191
|
-
const a =
|
|
192
|
-
|
|
193
|
-
var
|
|
194
|
-
const
|
|
195
|
-
if (!(
|
|
196
|
-
|
|
133
|
+
const a = ce(t.language), f = a.Uri.parse(`inmemory://model/${t.language}-${crypto.randomUUID()}`), B = a.editor.createModel(t.code.value, t.language, f);
|
|
134
|
+
K(() => C(o), (L) => {
|
|
135
|
+
var O;
|
|
136
|
+
const b = de(L);
|
|
137
|
+
if (!(b instanceof HTMLElement)) {
|
|
138
|
+
n = !1;
|
|
197
139
|
return;
|
|
198
140
|
}
|
|
199
|
-
if (!
|
|
200
|
-
e
|
|
201
|
-
...
|
|
141
|
+
if (!n) {
|
|
142
|
+
e = a.editor.create(b, {
|
|
143
|
+
...re,
|
|
202
144
|
readOnly: t.readOnly || !1,
|
|
203
145
|
language: t.language,
|
|
204
|
-
theme:
|
|
205
|
-
model:
|
|
146
|
+
theme: r.theme,
|
|
147
|
+
model: B,
|
|
206
148
|
editContext: !1,
|
|
207
149
|
...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();
|
|
150
|
+
}), n = !0, r.editorStatus = "ready", r.hasContent = !!t.code.value, e.onDidChangeModelContent(() => {
|
|
151
|
+
var h;
|
|
152
|
+
const m = e.getValue();
|
|
153
|
+
r.hasContent = !!m.length, (h = t.onChanged) == null || h.call(t, m);
|
|
154
|
+
}), (O = t.onCreated) == null || O.call(t), d();
|
|
216
155
|
try {
|
|
217
|
-
const
|
|
218
|
-
if (
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
n.searchBoxIsRevealed = p.isRevealed;
|
|
224
|
-
})
|
|
225
|
-
// This returns a disposable
|
|
226
|
-
);
|
|
156
|
+
const m = e.getContribution("editor.contrib.findController");
|
|
157
|
+
if (m) {
|
|
158
|
+
const h = m.getState();
|
|
159
|
+
h.onFindReplaceStateChange(() => {
|
|
160
|
+
r.searchBoxIsRevealed = h.isRevealed;
|
|
161
|
+
});
|
|
227
162
|
}
|
|
228
|
-
} catch (
|
|
229
|
-
console.error("useMonacoEditor: Failed to get the state of findController",
|
|
163
|
+
} catch (m) {
|
|
164
|
+
console.error("useMonacoEditor: Failed to get the state of findController", m);
|
|
230
165
|
}
|
|
231
166
|
}
|
|
232
167
|
}, {
|
|
233
168
|
immediate: !0,
|
|
234
169
|
flush: "post"
|
|
235
170
|
});
|
|
236
|
-
})(),
|
|
237
|
-
if (!e
|
|
238
|
-
const a = e.
|
|
239
|
-
e.
|
|
171
|
+
})(), D(d), P(d), V(() => {
|
|
172
|
+
if (!e) return;
|
|
173
|
+
const a = e.getModel();
|
|
174
|
+
e.dispose(), a && a.dispose();
|
|
240
175
|
}), {
|
|
241
176
|
editor: e,
|
|
242
|
-
editorStates:
|
|
177
|
+
editorStates: r,
|
|
243
178
|
setContent: i,
|
|
244
179
|
setReadOnly: s,
|
|
245
|
-
focus:
|
|
246
|
-
remeasureFonts:
|
|
247
|
-
toggleSearchWidget:
|
|
180
|
+
focus: u,
|
|
181
|
+
remeasureFonts: d,
|
|
182
|
+
toggleSearchWidget: p,
|
|
248
183
|
triggerKeyboardCommand: l
|
|
249
184
|
};
|
|
250
185
|
}
|
|
251
|
-
const
|
|
186
|
+
const me = {
|
|
252
187
|
messages: {
|
|
253
188
|
empty_message: "The editor is currently empty. Start typing to add content.",
|
|
254
189
|
empty_title: "No content available",
|
|
255
190
|
loading_message: "Please wait while the {type} content is loaded.",
|
|
256
191
|
loading_title: "{type} editor"
|
|
257
192
|
}
|
|
258
|
-
},
|
|
259
|
-
editor:
|
|
193
|
+
}, ge = {
|
|
194
|
+
editor: me
|
|
260
195
|
};
|
|
261
|
-
function
|
|
262
|
-
const o =
|
|
196
|
+
function fe() {
|
|
197
|
+
const o = X("en-us", ge);
|
|
263
198
|
return {
|
|
264
199
|
i18n: o,
|
|
265
|
-
i18nT:
|
|
200
|
+
i18nT: ee(o)
|
|
266
201
|
// Translation component <i18n-t>
|
|
267
202
|
};
|
|
268
203
|
}
|
|
269
|
-
const
|
|
204
|
+
const he = /* @__PURE__ */ N({
|
|
270
205
|
__name: "MonacoEditorStatusOverlay",
|
|
271
206
|
props: {
|
|
272
207
|
title: {},
|
|
@@ -275,30 +210,30 @@ const ke = /* @__PURE__ */ U({
|
|
|
275
210
|
},
|
|
276
211
|
setup(o) {
|
|
277
212
|
return (t, e) => {
|
|
278
|
-
const
|
|
279
|
-
return
|
|
213
|
+
const n = A("KEmptyState");
|
|
214
|
+
return y(), S(n, {
|
|
280
215
|
class: "monaco-editor-status-overlay",
|
|
281
216
|
message: o.message,
|
|
282
217
|
title: o.title
|
|
283
|
-
},
|
|
218
|
+
}, $({ _: 2 }, [
|
|
284
219
|
o.icon ? {
|
|
285
220
|
name: "icon",
|
|
286
|
-
fn:
|
|
287
|
-
(
|
|
221
|
+
fn: E(() => [
|
|
222
|
+
(y(), S(z(o.icon), { decorative: "" }))
|
|
288
223
|
]),
|
|
289
224
|
key: "0"
|
|
290
225
|
} : void 0
|
|
291
226
|
]), 1032, ["message", "title"]);
|
|
292
227
|
};
|
|
293
228
|
}
|
|
294
|
-
}),
|
|
229
|
+
}), R = (o, t) => {
|
|
295
230
|
const e = o.__vccOpts || o;
|
|
296
|
-
for (const [
|
|
297
|
-
e[
|
|
231
|
+
for (const [n, r] of t)
|
|
232
|
+
e[n] = r;
|
|
298
233
|
return e;
|
|
299
|
-
},
|
|
234
|
+
}, W = /* @__PURE__ */ R(he, [["__scopeId", "data-v-062eadb5"]]), ye = /* @__PURE__ */ N({
|
|
300
235
|
__name: "MonacoEditor",
|
|
301
|
-
props: /* @__PURE__ */
|
|
236
|
+
props: /* @__PURE__ */ H({
|
|
302
237
|
theme: { default: "light" },
|
|
303
238
|
language: { default: "markdown" },
|
|
304
239
|
options: { default: () => {
|
|
@@ -312,62 +247,62 @@ const ke = /* @__PURE__ */ U({
|
|
|
312
247
|
}),
|
|
313
248
|
emits: ["update:modelValue"],
|
|
314
249
|
setup(o) {
|
|
315
|
-
const t =
|
|
250
|
+
const t = G(o, "modelValue"), { i18n: e } = fe(), n = j("editorRef"), r = M(() => o.theme === "dark" ? "dark" : "light"), i = M(() => s.editorStates.editorStatus === "ready" && !s.editorStates.hasContent), s = ue(n, {
|
|
316
251
|
language: o.language,
|
|
317
252
|
code: t,
|
|
318
|
-
theme:
|
|
253
|
+
theme: r.value,
|
|
319
254
|
monacoOptions: o.options,
|
|
320
|
-
onChanged: (
|
|
321
|
-
t.value =
|
|
255
|
+
onChanged: (u) => {
|
|
256
|
+
t.value = u;
|
|
322
257
|
}
|
|
323
258
|
});
|
|
324
|
-
return (
|
|
325
|
-
class:
|
|
326
|
-
|
|
327
|
-
{ loading:
|
|
259
|
+
return (u, l) => (y(), q("div", {
|
|
260
|
+
class: J(["monaco-editor-container", [
|
|
261
|
+
r.value,
|
|
262
|
+
{ loading: c(s).editorStates.editorStatus === "loading" }
|
|
328
263
|
]]),
|
|
329
264
|
"data-testid": "monaco-editor-container"
|
|
330
265
|
}, [
|
|
331
|
-
|
|
266
|
+
Q("div", {
|
|
332
267
|
ref_key: "editorRef",
|
|
333
|
-
ref:
|
|
268
|
+
ref: n,
|
|
334
269
|
class: "monaco-editor-target",
|
|
335
270
|
"data-testid": "monaco-editor-target"
|
|
336
271
|
}, null, 512),
|
|
337
|
-
|
|
338
|
-
isLoading:
|
|
272
|
+
I(u.$slots, "state-loading", {
|
|
273
|
+
isLoading: c(s).editorStates.editorStatus === "loading"
|
|
339
274
|
}, () => [
|
|
340
|
-
|
|
341
|
-
default:
|
|
342
|
-
|
|
275
|
+
T(k, { name: "fade" }, {
|
|
276
|
+
default: E(() => [
|
|
277
|
+
c(s).editorStates.editorStatus === "loading" ? (y(), S(W, {
|
|
343
278
|
key: 0,
|
|
344
279
|
"data-testid": "monaco-editor-status-overlay-loading",
|
|
345
|
-
icon:
|
|
346
|
-
message:
|
|
347
|
-
title:
|
|
348
|
-
}, null, 8, ["icon", "message", "title"])) :
|
|
280
|
+
icon: c(Y),
|
|
281
|
+
message: c(e).t("editor.messages.loading_message", { type: o.language }),
|
|
282
|
+
title: c(e).t("editor.messages.loading_title", { type: o.language })
|
|
283
|
+
}, null, 8, ["icon", "message", "title"])) : w("", !0)
|
|
349
284
|
]),
|
|
350
285
|
_: 1
|
|
351
286
|
})
|
|
352
287
|
], !0),
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
default:
|
|
356
|
-
i.value ? (
|
|
288
|
+
I(u.$slots, "state-empty", { isEmpty: i.value }, () => [
|
|
289
|
+
T(k, { name: "fade" }, {
|
|
290
|
+
default: E(() => [
|
|
291
|
+
i.value ? (y(), S(W, {
|
|
357
292
|
key: 0,
|
|
358
293
|
"data-testid": "monaco-editor-status-overlay-empty",
|
|
359
|
-
icon:
|
|
360
|
-
message:
|
|
361
|
-
title:
|
|
362
|
-
}, null, 8, ["icon", "message", "title"])) :
|
|
294
|
+
icon: c(Z),
|
|
295
|
+
message: c(e).t("editor.messages.empty_message"),
|
|
296
|
+
title: c(e).t("editor.messages.empty_title")
|
|
297
|
+
}, null, 8, ["icon", "message", "title"])) : w("", !0)
|
|
363
298
|
]),
|
|
364
299
|
_: 1
|
|
365
300
|
})
|
|
366
301
|
], !0)
|
|
367
302
|
], 2));
|
|
368
303
|
}
|
|
369
|
-
}),
|
|
304
|
+
}), Se = /* @__PURE__ */ R(ye, [["__scopeId", "data-v-c8f35a88"]]);
|
|
370
305
|
export {
|
|
371
|
-
|
|
372
|
-
|
|
306
|
+
Se as MonacoEditor,
|
|
307
|
+
ue as useMonacoEditor
|
|
373
308
|
};
|
|
@@ -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("@kong-ui-public/i18n")):typeof define=="function"&&define.amd?define(["exports","vue","@kong/icons","monaco-editor","@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["kong-ui-public-i18n"]))})(this,function(s,e,S,F,O){"use strict";function N(o){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>o[t]})}}return n.default=o,Object.freeze(n)}const C=N(F),x=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 b=()=>{};function B(o,n){function t(...r){return new Promise((i,c)=>{Promise.resolve(o(()=>n.apply(this,r),{fn:n,thisArg:this,args:r})).then(i).catch(c)})}return t}function U(o,n={}){let t,r,i=b;const c=d=>{clearTimeout(d),i(),i=b};let l;return d=>{const y=e.toValue(o),u=e.toValue(n.maxWait);return t&&c(t),y<=0||u!==void 0&&u<=0?(r&&(c(r),r=void 0),Promise.resolve(d())):new Promise((_,a)=>{i=n.rejectOnCancel?a:_,l=d,u&&!r&&(r=setTimeout(()=>{t&&c(t),r=void 0,_(l())},u)),t=setTimeout(()=>{r&&c(r),r=void 0,_(d())},y)})}}function V(o,n=200,t={}){return B(U(n,t),o)}function W(o){var n;const t=e.toValue(o);return(n=t==null?void 0:t.$el)!==null&&n!==void 0?n:t}let g;const E=new Map;function D(o){return g||(g=C),o&&!E.get(o)&&(E.set(o,!0),C.languages.getLanguages().some(n=>n.id===o)||C.languages.register({id:o})),g}function I(o,n){let t,r=!1;const i=e.reactive({editorStatus:"loading",searchBoxIsRevealed:!1,hasContent:!1,theme:n.theme||"light"}),c=a=>{!r||!t||t.setValue(a)},l=a=>t==null?void 0:t.updateOptions({readOnly:a}),m=()=>t==null?void 0:t.focus(),d=a=>{try{if(!t||!a)return;t.focus(),t.trigger("keyboard",a,null)}catch(p){console.error(`useMonacoEditor: Failed to trigger command: ${a}`,p)}},y=()=>{var a;try{if(!t)return;if(i.searchBoxIsRevealed)return(a=t.getContribution("editor.contrib.findController"))==null?void 0:a.closeFindWidget();d("actions.find")}catch(p){console.error("useMonacoEditor: Failed to close findController.",p)}},u=V(()=>g==null?void 0:g.editor.remeasureFonts(),200);return(()=>{const a=D(n.language),p=a.Uri.parse(`inmemory://model/${n.language}-${crypto.randomUUID()}`),j=a.editor.createModel(n.code.value,n.language,p);e.watch(()=>e.toValue(o),H=>{var w;const M=W(H);if(!(M instanceof HTMLElement)){r=!1;return}if(!r){t=a.editor.create(M,{...x,readOnly:n.readOnly||!1,language:n.language,theme:i.theme,model:j,editContext:!1,...n.monacoOptions}),r=!0,i.editorStatus="ready",i.hasContent=!!n.code.value,t.onDidChangeModelContent(()=>{var h;const f=t.getValue();i.hasContent=!!f.length,(h=n.onChanged)==null||h.call(n,f)}),(w=n.onCreated)==null||w.call(n),u();try{const f=t.getContribution("editor.contrib.findController");if(f){const h=f.getState();h.onFindReplaceStateChange(()=>{i.searchBoxIsRevealed=h.isRevealed})}}catch(f){console.error("useMonacoEditor: Failed to get the state of findController",f)}}},{immediate:!0,flush:"post"})})(),e.onMounted(u),e.onActivated(u),e.onBeforeUnmount(()=>{if(!t)return;const a=t.getModel();t.dispose(),a&&a.dispose()}),{editor:t,editorStates:i,setContent:c,setReadOnly:l,focus:m,remeasureFonts:u,toggleSearchWidget:y,triggerKeyboardCommand:d}}const R={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 K(){const o=O.createI18n("en-us",R);return{i18n:o,i18nT:O.i18nTComponent(o)}}const L=e.defineComponent({__name:"MonacoEditorStatusOverlay",props:{title:{},message:{},icon:{}},setup(o){return(n,t)=>{const r=e.resolveComponent("KEmptyState");return e.openBlock(),e.createBlock(r,{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"])}}}),T=(o,n)=>{const t=o.__vccOpts||o;for(const[r,i]of n)t[r]=i;return t},k=T(L,[["__scopeId","data-v-062eadb5"]]),P=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(o){const n=e.useModel(o,"modelValue"),{i18n:t}=K(),r=e.useTemplateRef("editorRef"),i=e.computed(()=>o.theme==="dark"?"dark":"light"),c=e.computed(()=>l.editorStates.editorStatus==="ready"&&!l.editorStates.hasContent),l=I(r,{language:o.language,code:n,theme:i.value,monacoOptions:o.options,onChanged:m=>{n.value=m}});return(m,d)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["monaco-editor-container",[i.value,{loading:e.unref(l).editorStates.editorStatus==="loading"}]]),"data-testid":"monaco-editor-container"},[e.createElementVNode("div",{ref_key:"editorRef",ref:r,class:"monaco-editor-target","data-testid":"monaco-editor-target"},null,512),e.renderSlot(m.$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(k,{key:0,"data-testid":"monaco-editor-status-overlay-loading",icon:e.unref(S.ProgressIcon),message:e.unref(t).t("editor.messages.loading_message",{type:o.language}),title:e.unref(t).t("editor.messages.loading_title",{type:o.language})},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0),e.renderSlot(m.$slots,"state-empty",{isEmpty:c.value},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[c.value?(e.openBlock(),e.createBlock(k,{key:0,"data-testid":"monaco-editor-status-overlay-empty",icon:e.unref(S.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=P,s.useMonacoEditor=I,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -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;
|
|
@@ -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;AA+B1E;;;;;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;EAoIlD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kong-ui-public/monaco-editor",
|
|
3
|
-
"version": "0.4.11
|
|
3
|
+
"version": "0.4.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/runtime/monaco-editor.umd.js",
|
|
6
6
|
"module": "./dist/runtime/monaco-editor.es.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@kong/design-tokens": "1.18.2",
|
|
55
55
|
"@kong/icons": "^1.41.0",
|
|
56
|
-
"@kong/kongponents": "9.48.
|
|
56
|
+
"@kong/kongponents": "9.48.8",
|
|
57
57
|
"monaco-editor": "^0.55.1",
|
|
58
58
|
"vue": "^3.5.26",
|
|
59
59
|
"@kong-ui-public/i18n": "^2.4.5"
|
|
@@ -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"}
|