@kong-ui-public/monaco-editor 0.8.1-pr.2799.4a7245eab.0 → 0.8.1-pr.2802.7ee435206.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.

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