@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.

@@ -1,10 +1,10 @@
1
- import { toValue as w, ref as X, shallowRef as Y, reactive as Z, watch as x, onMounted as ee, onActivated as te, onBeforeUnmount as oe, onWatcherCleanup as ae, defineComponent as H, resolveComponent as ne, createBlock as O, openBlock as C, createSlots as re, withCtx as D, resolveDynamicComponent as se, mergeModels as R, useModel as ie, useTemplateRef as le, computed as T, createElementBlock as ce, normalizeClass as de, createElementVNode as ue, renderSlot as W, createVNode as N, Transition as U, createCommentVNode as B, unref as v } from "vue";
2
- import { ProgressIcon as ge, CodeblockIcon as me } from "@kong/icons";
3
- import * as m from "monaco-editor";
4
- import { shikiToMonaco as fe } from "@shikijs/monaco";
5
- import { getSingletonHighlighter as pe, bundledLanguages as he, bundledThemes as ve } from "shiki";
6
- import { createI18n as ye, i18nTComponent as Se } from "@kong-ui-public/i18n";
7
- const be = "'JetBrains Mono', Consolas, monospace", Ce = "12px", Ee = "500", Me = "20px", _e = Object.freeze({
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: be,
17
- fontSize: Number(Ce.replace("px", "")),
18
- fontWeight: Ee,
19
- lineHeight: Number(Me.replace("px", "")),
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 P = () => {
62
+ const N = () => {
63
63
  };
64
- function we(o, t) {
64
+ function he(o, t) {
65
65
  function e(...a) {
66
- return new Promise((i, r) => {
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(i).catch(r);
71
+ })).then(r).catch(s);
72
72
  });
73
73
  }
74
74
  return e;
75
75
  }
76
- function Oe(o, t = {}) {
77
- let e, a, i = P;
78
- const r = (s) => {
79
- clearTimeout(s), i(), i = P;
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 l;
82
- return (s) => {
83
- const p = w(o), g = w(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);
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 ke(o, t = 200, e = {}) {
95
- return we(Oe(t, e), o);
94
+ function ye(o, t = 200, e = {}) {
95
+ return he(pe(t, e), o);
96
96
  }
97
- function $(o) {
97
+ function U(o) {
98
98
  var t;
99
- const e = w(o);
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 F = "[monaco-editor] [lifecycle]", y = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new WeakMap();
103
- function Te(o) {
104
- let t = y.get(o.source);
105
- if (!t) {
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 = m.json) == null ? void 0 : o.jsonDefaults) || ((t = m.languages.json) == null ? void 0 : t.jsonDefaults);
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 pe(
110
+ const a = await se(
190
111
  {
191
- themes: Object.values(ve),
192
- langs: Object.values(he)
112
+ themes: Object.values(le),
113
+ langs: Object.values(ie)
193
114
  }
194
115
  );
195
- a.getLoadedLanguages().forEach((i) => {
196
- m.languages.register({ id: i });
197
- }), fe(a, m), q.value = !0;
116
+ a.getLoadedLanguages().forEach((r) => {
117
+ g.languages.register({ id: r });
118
+ }), re(a, g), P.value = !0;
198
119
  } catch (e) {
199
- throw b = null, e;
120
+ throw y = null, e;
200
121
  }
201
- })(), b);
122
+ })(), y);
202
123
  }
203
- function Fe(o, t) {
204
- const e = Y();
205
- let a, i = !1, r = !1;
206
- const l = Z({
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
- }), f = (n) => {
212
- !i || !e.value || e.value.setValue(n);
213
- }, s = (n) => {
214
- var d;
215
- return (d = e.value) == null ? void 0 : d.updateOptions({ readOnly: n });
216
- }, p = () => {
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
- }, g = (n) => {
220
- var M;
221
- const d = (M = e.value) == null ? void 0 : M.getModel();
222
- d && m.editor.setModelLanguage(d, n);
223
- }, c = (n) => {
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 (d) {
228
- console.error(`useMonacoEditor: Failed to trigger command: ${n}`, d);
148
+ } catch (c) {
149
+ console.error(`useMonacoEditor: Failed to trigger command: ${n}`, c);
229
150
  }
230
- }, h = () => {
151
+ }, v = () => {
231
152
  var n;
232
153
  try {
233
154
  if (!e.value) return;
234
- if (l.searchBoxIsRevealed)
155
+ if (i.searchBoxIsRevealed)
235
156
  return (n = e.value.getContribution("editor.contrib.findController")) == null ? void 0 : n.closeFindWidget();
236
- c("actions.find");
237
- } catch (d) {
238
- console.error("useMonacoEditor: Failed to close findController.", d);
157
+ l("actions.find");
158
+ } catch (c) {
159
+ console.error("useMonacoEditor: Failed to close findController.", c);
239
160
  }
240
- }, E = /* @__PURE__ */ ke(() => m.editor.remeasureFonts(), 200);
161
+ }, S = /* @__PURE__ */ ye(() => g.editor.remeasureFonts(), 200);
241
162
  return (() => {
242
- De(), x([q, () => w(o)], ([n, d], [, M]) => {
243
- var L;
244
- const k = $(d), Q = $(M);
245
- if (!(k instanceof HTMLElement) || !n) {
246
- i = !1;
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 (!(i && Q === k)) {
170
+ if (!(r && V === O)) {
250
171
  if (!a) {
251
- const u = m.Uri.parse(`inmemory://model/${t.language}-${crypto.randomUUID()}`);
252
- a = m.editor.createModel(t.code.value, t.language, u);
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 = m.editor.create(k, {
255
- ..._e,
175
+ e.value = g.editor.create(O, {
176
+ ...ve,
256
177
  readOnly: t.readOnly || !1,
257
178
  language: t.language,
258
- theme: l.theme === "light" ? "catppuccin-latte" : "catppuccin-mocha",
179
+ theme: i.theme === "light" ? "catppuccin-latte" : "catppuccin-mocha",
259
180
  model: a,
260
181
  editContext: !1,
261
182
  ...t.monacoOptions
262
- }), i = !0, l.editorStatus = "ready", l.hasContent = !!t.code.value, V(
263
- e.value,
264
- e.value.onDidChangeModelContent(() => {
265
- if (r) return;
266
- const u = e.value.getValue();
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
- V(
273
- e.value,
274
- _ == null ? void 0 : _.onFindReplaceStateChange(() => {
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
- ae(() => {
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
- })(), x(t.code, (n) => {
292
- if (!e.value || !a || !i) return;
293
- const d = a.getValue();
294
- n !== d && (r = !0, e.value.executeEdits("external", [
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(), l.hasContent = !!n.length, r = !1);
300
- }), ee(E), te(E), oe(() => {
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: l,
307
- setContent: f,
308
- setReadOnly: s,
309
- focus: p,
310
- setLanguage: g,
311
- remeasureFonts: E,
312
- toggleSearchWidget: h,
313
- triggerKeyboardCommand: c
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 Le = {
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
- }, Re = {
324
- editor: Le
237
+ }, _e = {
238
+ editor: Ee
325
239
  };
326
- function We() {
327
- const o = ye("en-us", Re);
240
+ function be() {
241
+ const o = ce("en-us", _e);
328
242
  return {
329
243
  i18n: o,
330
- i18nT: Se(o)
244
+ i18nT: ue(o)
331
245
  // Translation component <i18n-t>
332
246
  };
333
247
  }
334
- const Ne = /* @__PURE__ */ H({
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 = ne("KEmptyState");
344
- return C(), O(a, {
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
- }, re({ _: 2 }, [
262
+ }, Q({ _: 2 }, [
349
263
  o.icon ? {
350
264
  name: "icon",
351
- fn: D(() => [
352
- (C(), O(se(o.icon), { decorative: "" }))
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
- }), J = (o, t) => {
273
+ }), j = (o, t) => {
360
274
  const e = o.__vccOpts || o;
361
- for (const [a, i] of t)
362
- e[a] = i;
275
+ for (const [a, r] of t)
276
+ e[a] = r;
363
277
  return e;
364
- }, z = /* @__PURE__ */ J(Ne, [["__scopeId", "data-v-062eadb5"]]), Ue = /* @__PURE__ */ H({
278
+ }, B = /* @__PURE__ */ j(Me, [["__scopeId", "data-v-062eadb5"]]), Oe = /* @__PURE__ */ D({
365
279
  __name: "MonacoEditor",
366
- props: /* @__PURE__ */ R({
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__ */ R(["ready"], ["update:modelValue"]),
293
+ emits: /* @__PURE__ */ F(["ready"], ["update:modelValue"]),
380
294
  setup(o, { expose: t, emit: e }) {
381
- const a = e, i = ie(o, "modelValue"), { i18n: r } = We(), l = le("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 = Fe(l, {
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: i,
384
- theme: f.value,
297
+ code: r,
298
+ theme: p.value,
385
299
  monacoOptions: o.options,
386
- onReady: (c) => {
387
- a("ready", c);
300
+ onReady: (l) => {
301
+ a("ready", l);
388
302
  }
389
303
  });
390
304
  return t({
391
- monacoEditor: g
392
- }), x(() => o.language, (c, h) => {
393
- c !== h && g.setLanguage(c);
394
- }), (c, h) => (C(), ce("div", {
395
- class: de(["monaco-editor-container", [
396
- f.value,
397
- { loading: s.value }
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
- ue("div", {
315
+ oe("div", {
402
316
  ref_key: "editorRef",
403
- ref: l,
317
+ ref: i,
404
318
  class: "monaco-editor-target",
405
319
  "data-testid": "monaco-editor-target"
406
320
  }, null, 512),
407
- W(c.$slots, "state-loading", { isLoading: s.value }, () => [
408
- N(U, { name: "fade" }, {
409
- default: D(() => [
410
- s.value ? (C(), O(z, {
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: v(ge),
414
- message: v(r).t("editor.messages.loading_message", { type: o.language }),
415
- title: v(r).t("editor.messages.loading_title", { type: o.language })
416
- }, null, 8, ["icon", "message", "title"])) : B("", !0)
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
- W(c.$slots, "state-empty", { isEmpty: p.value }, () => [
422
- N(U, { name: "fade" }, {
423
- default: D(() => [
424
- p.value && !s.value ? (C(), O(z, {
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: v(me),
428
- message: v(r).t("editor.messages.empty_message"),
429
- title: v(r).t("editor.messages.empty_title")
430
- }, null, 8, ["icon", "message", "title"])) : B("", !0)
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
- }), Ke = /* @__PURE__ */ J(Ue, [["__scopeId", "data-v-e2083635"]]);
351
+ }), we = /* @__PURE__ */ j(Oe, [["__scopeId", "data-v-e2083635"]]);
438
352
  export {
439
- Ke as MonacoEditor,
440
- Fe as useMonacoEditor
353
+ we as MonacoEditor,
354
+ Se as useMonacoEditor
441
355
  };
@@ -1 +1 @@
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,$,A,O,v){"use strict";function H(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=H($),q=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 x=()=>{};function z(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 G(o,t={}){let e,a,l=x;const i=s=>{clearTimeout(s),l(),l=x};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 Y(o,t=200,e={}){return z(G(t,e),o)}function F(o){var t;const e=n.toValue(o);return(t=e==null?void 0:e.$el)!==null&&t!==void 0?t:e}const I="[monaco-editor] [lifecycle]",b=new WeakMap,_=new Map,T=new WeakMap;function Z(o){let t=b.get(o.source);if(!t){let e;switch(o.type){case"editor":e=o.source.onDidDispose(()=>R(o.source));break;case"model":e=o.source.onWillDispose(()=>R(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 L(o){const t=b.get(o);t&&(t.scopeListener.dispose(),b.delete(o))}function N(o,t){Z(t).disposables.add(o)}function W(o,t){const e=b.get(t.source);e&&(e.disposables.delete(o),e.disposables.size===0&&L(t.source))}function J(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 Q(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&&W(a.decorated,a.scope),t?(N(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&&W(i,s.scope),_.delete(e),T.delete(i),l.call(e)}};return _.set(e,{decorated:i,scope:t}),T.set(i,e),t&&N(i,t),i}function B(o,t){return Q(t,{type:"editor",source:o})}function R(o){const t=b.get(o);if(!t)return;const e=Array.from(t.disposables);try{J(e)}catch(a){console.warn(`${I} Encountered errors while disposing scoped disposables:`,a,", Source:",o)}L(o)}const U=n.ref(!1);let k=null;async function X(){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),U.value=!0}catch(e){throw k=null,e}})(),k)}function j(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 f;return(f=e.value)==null?void 0:f.updateOptions({readOnly:r})},y=()=>{var r;return(r=e.value)==null?void 0:r.focus()},m=r=>{var M;const f=(M=e.value)==null?void 0:M.getModel();f&&p.editor.setModelLanguage(f,r)},d=r=>{try{if(!e.value||!r)return;e.value.focus(),e.value.trigger("keyboard",r,null)}catch(f){console.error(`useMonacoEditor: Failed to trigger command: ${r}`,f)}},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(f){console.error("useMonacoEditor: Failed to close findController.",f)}},E=Y(()=>p.editor.remeasureFonts(),200);return(()=>{X(),n.watch([U,()=>n.toValue(o)],([r,f],[,M])=>{var K;const w=F(f),ae=F(M);if(!(w instanceof HTMLElement)||!r){l=!1;return}if(!(l&&ae===w)){if(!a){const g=p.Uri.parse(`inmemory://model/${t.language}-${crypto.randomUUID()}`);a=p.editor.createModel(t.code.value,t.language,g)}e.value=p.editor.create(w,{...q,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,B(e.value,e.value.onDidChangeModelContent(()=>{if(i)return;const g=e.value.getValue();c.hasContent=!!g.length,t.code.value=g})),(K=t.onReady)==null||K.call(t,e.value),E();try{const g=e.value.getContribution("editor.contrib.findController"),C=g==null?void 0:g.getState();B(e.value,C==null?void 0:C.onFindReplaceStateChange(()=>{c.searchBoxIsRevealed=C.isRevealed}))}catch(g){console.error("useMonacoEditor: Failed to get the state of findController",g)}n.onWatcherCleanup(()=>{var g;(g=e.value)==null||g.dispose()})}},{immediate:!0,flush:"post"})})(),n.watch(t.code,r=>{if(!e.value||!a||!l)return;const f=a.getValue();r!==f&&(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 ee={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 te(){const o=v.createI18n("en-us",ee);return{i18n:o,i18nT:v.i18nTComponent(o)}}const oe=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"])}}}),P=(o,t)=>{const e=o.__vccOpts||o;for(const[a,l]of t)e[a]=l;return e},V=P(oe,[["__scopeId","data-v-062eadb5"]]),ne=P(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}=te(),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=j(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=ne,u.useMonacoEditor=j,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
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;AAKvC,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;EA6KlD"}
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
- * 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.
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
- * 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.
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 all the scopes
14
- * mentioned above.
16
+ * This tracker is designed to be a singleton to track disposables in different scopes.
15
17
  */
16
- import { type editor as Editor, type IDisposable } from 'monaco-editor';
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
- * **WARNING**: Should not call {@link IDisposable.dispose dispose} on the
35
- * disposable being passed in. Otherwise, the tracking will be broken.
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 track(disposable: IDisposable, scope?: Scope): IDisposable;
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 trackForEditor(editor: Editor.ICodeEditor, disposable: IDisposable): IDisposable;
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 trackForModel(model: Editor.ITextModel, disposable: IDisposable): IDisposable;
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 disposeScoped(source: ScopeSource): void;
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 disposeAll(): void;
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;;;;;;;;;;;;;;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"}
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",