@kong-ui-public/monaco-editor 0.4.11-pr.2769.31aadbf56.0 → 0.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,49 +1,8 @@
1
- import { toValue as _, shallowRef as K, reactive as z, onMounted as $, onActivated as H, onBeforeUnmount as G, watch as j, defineComponent as U, resolveComponent as q, createBlock as E, openBlock as h, createSlots as J, withCtx as k, resolveDynamicComponent as Q, mergeModels as Y, useModel as Z, useTemplateRef as X, computed as T, createElementBlock as ee, normalizeClass as te, unref as d, createElementVNode as oe, renderSlot as F, createVNode as W, Transition as x, createCommentVNode as D } from "vue";
2
- import { ProgressIcon as re, CodeblockIcon as ae } from "@kong/icons";
3
- import * as M from "monaco-editor";
4
- import { createI18n as ne, i18nTComponent as ie } from "@kong-ui-public/i18n";
5
- typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
6
- const R = () => {
7
- };
8
- function se(o, t) {
9
- function e(...r) {
10
- return new Promise((n, i) => {
11
- Promise.resolve(o(() => t.apply(this, r), {
12
- fn: t,
13
- thisArg: this,
14
- args: r
15
- })).then(n).catch(i);
16
- });
17
- }
18
- return e;
19
- }
20
- function le(o, t = {}) {
21
- let e, r, n = R;
22
- const i = (l) => {
23
- clearTimeout(l), n(), n = R;
24
- };
25
- let s;
26
- return (l) => {
27
- const C = _(o), c = _(t.maxWait);
28
- return e && i(e), C <= 0 || c !== void 0 && c <= 0 ? (r && (i(r), r = void 0), Promise.resolve(l())) : new Promise((S, a) => {
29
- n = t.rejectOnCancel ? a : S, s = l, c && !r && (r = setTimeout(() => {
30
- e && i(e), r = void 0, S(s());
31
- }, c)), e = setTimeout(() => {
32
- r && i(r), r = void 0, S(l());
33
- }, C);
34
- });
35
- };
36
- }
37
- // @__NO_SIDE_EFFECTS__
38
- function ce(o, t = 200, e = {}) {
39
- return se(le(t, e), o);
40
- }
41
- function de(o) {
42
- var t;
43
- const e = _(o);
44
- return (t = e == null ? void 0 : e.$el) !== null && t !== void 0 ? t : e;
45
- }
46
- const ue = "'JetBrains Mono', Consolas, monospace", me = "12px", fe = "500", ge = "20px", ve = Object.freeze({
1
+ import { toValue as C, reactive as U, onMounted as D, onActivated as P, onBeforeUnmount as V, watch as K, defineComponent as N, resolveComponent as A, createBlock as S, openBlock as y, createSlots as $, withCtx as E, resolveDynamicComponent as z, mergeModels as H, useModel as G, useTemplateRef as j, computed as M, createElementBlock as q, normalizeClass as J, unref as c, createElementVNode as Q, renderSlot as I, createVNode as T, Transition as k, createCommentVNode as w } from "vue";
2
+ import { ProgressIcon as Y, CodeblockIcon as Z } from "@kong/icons";
3
+ import * as _ from "monaco-editor";
4
+ import { createI18n as X, i18nTComponent as ee } from "@kong-ui-public/i18n";
5
+ const te = "'JetBrains Mono', Consolas, monospace", oe = "12px", ne = "500", ae = "20px", re = Object.freeze({
47
6
  autoClosingQuotes: "always",
48
7
  automaticLayout: !0,
49
8
  // Auto resize layout
@@ -52,10 +11,10 @@ const ue = "'JetBrains Mono', Consolas, monospace", me = "12px", fe = "500", ge
52
11
  },
53
12
  hideCursorInOverviewRuler: !0,
54
13
  // hide the cursor position in the minimap TODO: maybe hide it on first line or change it colour
55
- fontFamily: ue,
56
- fontSize: Number(me.replace("px", "")),
57
- fontWeight: fe,
58
- lineHeight: Number(ge.replace("px", "")),
14
+ fontFamily: te,
15
+ fontSize: Number(oe.replace("px", "")),
16
+ fontWeight: ne,
17
+ lineHeight: Number(ae.replace("px", "")),
59
18
  formatOnPaste: !0,
60
19
  formatOnType: !0,
61
20
  // Add to enable automatic formatting as the user types.
@@ -97,176 +56,152 @@ const ue = "'JetBrains Mono', Consolas, monospace", me = "12px", fe = "500", ge
97
56
  // we need this set to false to get the correct absolute position, otherwise when the search box opens the content shifts
98
57
  }
99
58
  });
100
- let g = /* @__PURE__ */ new WeakMap();
101
- const y = /* @__PURE__ */ new Map();
102
- function O(o, t) {
103
- let e = y.get(o);
104
- if (e)
105
- return console.warn("[monaco-editor] [lifecycle] Disposable is already tracked:", o), e;
106
- const r = o.dispose;
107
- if (e = {
108
- ...o,
109
- dispose: () => (y.delete(o), r.call(o))
110
- }, t) {
111
- const n = e.dispose;
112
- e.dispose = () => {
113
- const s = g.get(t.source);
114
- return s && (s.delete(e), s.size === 0 && g.delete(t.source)), n();
115
- };
116
- const i = g.get(t.source);
117
- if (i)
118
- i.add(e);
119
- else
120
- switch (g.set(t.source, /* @__PURE__ */ new Set([e])), t.type) {
121
- case "editor":
122
- t.source.onDidDispose(() => b(t.source));
123
- break;
124
- case "model":
125
- t.source.onWillDispose(() => b(t.source));
126
- break;
127
- }
59
+ typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
60
+ const x = () => {
61
+ };
62
+ function ie(o, t) {
63
+ function e(...n) {
64
+ return new Promise((r, i) => {
65
+ Promise.resolve(o(() => t.apply(this, n), {
66
+ fn: t,
67
+ thisArg: this,
68
+ args: n
69
+ })).then(r).catch(i);
70
+ });
128
71
  }
129
- return y.set(o, e), e;
130
- }
131
- function pe(o, t) {
132
- return O(t, { type: "editor", source: o });
72
+ return e;
133
73
  }
134
- function he(o, t) {
135
- return O(t, { type: "model", source: o });
74
+ function se(o, t = {}) {
75
+ let e, n, r = x;
76
+ const i = (l) => {
77
+ clearTimeout(l), r(), r = x;
78
+ };
79
+ let s;
80
+ return (l) => {
81
+ const p = C(o), d = C(t.maxWait);
82
+ return e && i(e), p <= 0 || d !== void 0 && d <= 0 ? (n && (i(n), n = void 0), Promise.resolve(l())) : new Promise((v, a) => {
83
+ r = t.rejectOnCancel ? a : v, s = l, d && !n && (n = setTimeout(() => {
84
+ e && i(e), n = void 0, v(s());
85
+ }, d)), e = setTimeout(() => {
86
+ n && i(n), n = void 0, v(l());
87
+ }, p);
88
+ });
89
+ };
136
90
  }
137
- function b(o) {
138
- const t = g.get(o);
139
- t && (t.forEach((e) => e.dispose()), g.delete(o));
91
+ // @__NO_SIDE_EFFECTS__
92
+ function le(o, t = 200, e = {}) {
93
+ return ie(se(t, e), o);
140
94
  }
141
- function ye() {
142
- y.forEach((o) => o.dispose()), y.clear(), g = /* @__PURE__ */ new WeakMap();
95
+ function de(o) {
96
+ var t;
97
+ const e = C(o);
98
+ return (t = e == null ? void 0 : e.$el) !== null && t !== void 0 ? t : e;
143
99
  }
144
- const N = {
145
- track: O,
146
- trackForEditor: pe,
147
- trackForModel: he,
148
- disposeScoped: b,
149
- disposeAll: ye
150
- };
151
- let v;
152
- const B = /* @__PURE__ */ new Map();
153
- function Ce(o) {
154
- return v || (v = M), o && !B.get(o) && (B.set(o, !0), M.languages.getLanguages().some((t) => t.id === o) || M.languages.register({ id: o })), v;
100
+ let g;
101
+ const F = /* @__PURE__ */ new Map();
102
+ function ce(o) {
103
+ return g || (g = _), o && !F.get(o) && (F.set(o, !0), _.languages.getLanguages().some((t) => t.id === o) || _.languages.register({ id: o })), g;
155
104
  }
156
- function Se(o, t) {
157
- const e = K();
158
- let r = !1;
159
- const n = z({
105
+ function ue(o, t) {
106
+ let e, n = !1;
107
+ const r = U({
160
108
  editorStatus: "loading",
161
109
  searchBoxIsRevealed: !1,
162
110
  hasContent: !1,
163
111
  theme: t.theme || "light"
164
112
  }), i = (a) => {
165
- !r || !e.value || e.value.setValue(a);
166
- }, s = (a) => {
167
- var u;
168
- return (u = e.value) == null ? void 0 : u.updateOptions({ readOnly: a });
169
- }, m = () => {
170
- var a;
171
- return (a = e.value) == null ? void 0 : a.focus();
172
- }, l = (a) => {
113
+ !n || !e || e.setValue(a);
114
+ }, s = (a) => e == null ? void 0 : e.updateOptions({ readOnly: a }), u = () => e == null ? void 0 : e.focus(), l = (a) => {
173
115
  try {
174
- if (!e.value || !a) return;
175
- e.value.focus(), e.value.trigger("keyboard", a, null);
176
- } catch (u) {
177
- console.error(`useMonacoEditor: Failed to trigger command: ${a}`, u);
116
+ if (!e || !a) return;
117
+ e.focus(), e.trigger("keyboard", a, null);
118
+ } catch (f) {
119
+ console.error(`useMonacoEditor: Failed to trigger command: ${a}`, f);
178
120
  }
179
- }, C = () => {
121
+ }, p = () => {
180
122
  var a;
181
123
  try {
182
- if (!e.value) return;
183
- if (n.searchBoxIsRevealed)
184
- return (a = e.value.getContribution("editor.contrib.findController")) == null ? void 0 : a.closeFindWidget();
124
+ if (!e) return;
125
+ if (r.searchBoxIsRevealed)
126
+ return (a = e.getContribution("editor.contrib.findController")) == null ? void 0 : a.closeFindWidget();
185
127
  l("actions.find");
186
- } catch (u) {
187
- console.error("useMonacoEditor: Failed to close findController.", u);
128
+ } catch (f) {
129
+ console.error("useMonacoEditor: Failed to close findController.", f);
188
130
  }
189
- }, c = /* @__PURE__ */ ce(() => v == null ? void 0 : v.editor.remeasureFonts(), 200);
131
+ }, d = /* @__PURE__ */ le(() => g == null ? void 0 : g.editor.remeasureFonts(), 200);
190
132
  return (() => {
191
- const a = Ce(t.language), u = a.Uri.parse(`inmemory://model/${t.language}-${crypto.randomUUID()}`), V = a.editor.createModel(t.code.value, t.language, u);
192
- j(() => _(o), (A) => {
193
- var I;
194
- const w = de(A);
195
- if (!(w instanceof HTMLElement)) {
196
- r = !1;
133
+ const a = ce(t.language), f = a.Uri.parse(`inmemory://model/${t.language}-${crypto.randomUUID()}`), B = a.editor.createModel(t.code.value, t.language, f);
134
+ K(() => C(o), (L) => {
135
+ var O;
136
+ const b = de(L);
137
+ if (!(b instanceof HTMLElement)) {
138
+ n = !1;
197
139
  return;
198
140
  }
199
- if (!r) {
200
- e.value = a.editor.create(w, {
201
- ...ve,
141
+ if (!n) {
142
+ e = a.editor.create(b, {
143
+ ...re,
202
144
  readOnly: t.readOnly || !1,
203
145
  language: t.language,
204
- theme: n.theme,
205
- model: V,
146
+ theme: r.theme,
147
+ model: B,
206
148
  editContext: !1,
207
149
  ...t.monacoOptions
208
- }), r = !0, n.editorStatus = "ready", n.hasContent = !!t.code.value, N.trackForEditor(
209
- e.value,
210
- e.value.onDidChangeModelContent(() => {
211
- var p;
212
- const f = e.value.getValue();
213
- n.hasContent = !!f.length, (p = t.onChanged) == null || p.call(t, f);
214
- })
215
- ), (I = t.onCreated) == null || I.call(t), c();
150
+ }), n = !0, r.editorStatus = "ready", r.hasContent = !!t.code.value, e.onDidChangeModelContent(() => {
151
+ var h;
152
+ const m = e.getValue();
153
+ r.hasContent = !!m.length, (h = t.onChanged) == null || h.call(t, m);
154
+ }), (O = t.onCreated) == null || O.call(t), d();
216
155
  try {
217
- const f = e.value.getContribution("editor.contrib.findController");
218
- if (f) {
219
- const p = f.getState();
220
- N.trackForEditor(
221
- e.value,
222
- p.onFindReplaceStateChange(() => {
223
- n.searchBoxIsRevealed = p.isRevealed;
224
- })
225
- // This returns a disposable
226
- );
156
+ const m = e.getContribution("editor.contrib.findController");
157
+ if (m) {
158
+ const h = m.getState();
159
+ h.onFindReplaceStateChange(() => {
160
+ r.searchBoxIsRevealed = h.isRevealed;
161
+ });
227
162
  }
228
- } catch (f) {
229
- console.error("useMonacoEditor: Failed to get the state of findController", f);
163
+ } catch (m) {
164
+ console.error("useMonacoEditor: Failed to get the state of findController", m);
230
165
  }
231
166
  }
232
167
  }, {
233
168
  immediate: !0,
234
169
  flush: "post"
235
170
  });
236
- })(), $(c), H(c), G(() => {
237
- if (!e.value) return;
238
- const a = e.value.getModel();
239
- e.value.dispose(), a && a.dispose();
171
+ })(), D(d), P(d), V(() => {
172
+ if (!e) return;
173
+ const a = e.getModel();
174
+ e.dispose(), a && a.dispose();
240
175
  }), {
241
176
  editor: e,
242
- editorStates: n,
177
+ editorStates: r,
243
178
  setContent: i,
244
179
  setReadOnly: s,
245
- focus: m,
246
- remeasureFonts: c,
247
- toggleSearchWidget: C,
180
+ focus: u,
181
+ remeasureFonts: d,
182
+ toggleSearchWidget: p,
248
183
  triggerKeyboardCommand: l
249
184
  };
250
185
  }
251
- const _e = {
186
+ const me = {
252
187
  messages: {
253
188
  empty_message: "The editor is currently empty. Start typing to add content.",
254
189
  empty_title: "No content available",
255
190
  loading_message: "Please wait while the {type} content is loaded.",
256
191
  loading_title: "{type} editor"
257
192
  }
258
- }, Ee = {
259
- editor: _e
193
+ }, ge = {
194
+ editor: me
260
195
  };
261
- function Me() {
262
- const o = ne("en-us", Ee);
196
+ function fe() {
197
+ const o = X("en-us", ge);
263
198
  return {
264
199
  i18n: o,
265
- i18nT: ie(o)
200
+ i18nT: ee(o)
266
201
  // Translation component <i18n-t>
267
202
  };
268
203
  }
269
- const ke = /* @__PURE__ */ U({
204
+ const he = /* @__PURE__ */ N({
270
205
  __name: "MonacoEditorStatusOverlay",
271
206
  props: {
272
207
  title: {},
@@ -275,30 +210,30 @@ const ke = /* @__PURE__ */ U({
275
210
  },
276
211
  setup(o) {
277
212
  return (t, e) => {
278
- const r = q("KEmptyState");
279
- return h(), E(r, {
213
+ const n = A("KEmptyState");
214
+ return y(), S(n, {
280
215
  class: "monaco-editor-status-overlay",
281
216
  message: o.message,
282
217
  title: o.title
283
- }, J({ _: 2 }, [
218
+ }, $({ _: 2 }, [
284
219
  o.icon ? {
285
220
  name: "icon",
286
- fn: k(() => [
287
- (h(), E(Q(o.icon), { decorative: "" }))
221
+ fn: E(() => [
222
+ (y(), S(z(o.icon), { decorative: "" }))
288
223
  ]),
289
224
  key: "0"
290
225
  } : void 0
291
226
  ]), 1032, ["message", "title"]);
292
227
  };
293
228
  }
294
- }), P = (o, t) => {
229
+ }), R = (o, t) => {
295
230
  const e = o.__vccOpts || o;
296
- for (const [r, n] of t)
297
- e[r] = n;
231
+ for (const [n, r] of t)
232
+ e[n] = r;
298
233
  return e;
299
- }, L = /* @__PURE__ */ P(ke, [["__scopeId", "data-v-062eadb5"]]), be = /* @__PURE__ */ U({
234
+ }, W = /* @__PURE__ */ R(he, [["__scopeId", "data-v-062eadb5"]]), ye = /* @__PURE__ */ N({
300
235
  __name: "MonacoEditor",
301
- props: /* @__PURE__ */ Y({
236
+ props: /* @__PURE__ */ H({
302
237
  theme: { default: "light" },
303
238
  language: { default: "markdown" },
304
239
  options: { default: () => {
@@ -312,62 +247,62 @@ const ke = /* @__PURE__ */ U({
312
247
  }),
313
248
  emits: ["update:modelValue"],
314
249
  setup(o) {
315
- const t = Z(o, "modelValue"), { i18n: e } = Me(), r = X("editorRef"), n = T(() => o.theme === "dark" ? "dark" : "light"), i = T(() => s.editorStates.editorStatus === "ready" && !s.editorStates.hasContent), s = Se(r, {
250
+ const t = G(o, "modelValue"), { i18n: e } = fe(), n = j("editorRef"), r = M(() => o.theme === "dark" ? "dark" : "light"), i = M(() => s.editorStates.editorStatus === "ready" && !s.editorStates.hasContent), s = ue(n, {
316
251
  language: o.language,
317
252
  code: t,
318
- theme: n.value,
253
+ theme: r.value,
319
254
  monacoOptions: o.options,
320
- onChanged: (m) => {
321
- t.value = m;
255
+ onChanged: (u) => {
256
+ t.value = u;
322
257
  }
323
258
  });
324
- return (m, l) => (h(), ee("div", {
325
- class: te(["monaco-editor-container", [
326
- n.value,
327
- { loading: d(s).editorStates.editorStatus === "loading" }
259
+ return (u, l) => (y(), q("div", {
260
+ class: J(["monaco-editor-container", [
261
+ r.value,
262
+ { loading: c(s).editorStates.editorStatus === "loading" }
328
263
  ]]),
329
264
  "data-testid": "monaco-editor-container"
330
265
  }, [
331
- oe("div", {
266
+ Q("div", {
332
267
  ref_key: "editorRef",
333
- ref: r,
268
+ ref: n,
334
269
  class: "monaco-editor-target",
335
270
  "data-testid": "monaco-editor-target"
336
271
  }, null, 512),
337
- F(m.$slots, "state-loading", {
338
- isLoading: d(s).editorStates.editorStatus === "loading"
272
+ I(u.$slots, "state-loading", {
273
+ isLoading: c(s).editorStates.editorStatus === "loading"
339
274
  }, () => [
340
- W(x, { name: "fade" }, {
341
- default: k(() => [
342
- d(s).editorStates.editorStatus === "loading" ? (h(), E(L, {
275
+ T(k, { name: "fade" }, {
276
+ default: E(() => [
277
+ c(s).editorStates.editorStatus === "loading" ? (y(), S(W, {
343
278
  key: 0,
344
279
  "data-testid": "monaco-editor-status-overlay-loading",
345
- icon: d(re),
346
- message: d(e).t("editor.messages.loading_message", { type: o.language }),
347
- title: d(e).t("editor.messages.loading_title", { type: o.language })
348
- }, null, 8, ["icon", "message", "title"])) : D("", !0)
280
+ icon: c(Y),
281
+ message: c(e).t("editor.messages.loading_message", { type: o.language }),
282
+ title: c(e).t("editor.messages.loading_title", { type: o.language })
283
+ }, null, 8, ["icon", "message", "title"])) : w("", !0)
349
284
  ]),
350
285
  _: 1
351
286
  })
352
287
  ], !0),
353
- F(m.$slots, "state-empty", { isEmpty: i.value }, () => [
354
- W(x, { name: "fade" }, {
355
- default: k(() => [
356
- i.value ? (h(), E(L, {
288
+ I(u.$slots, "state-empty", { isEmpty: i.value }, () => [
289
+ T(k, { name: "fade" }, {
290
+ default: E(() => [
291
+ i.value ? (y(), S(W, {
357
292
  key: 0,
358
293
  "data-testid": "monaco-editor-status-overlay-empty",
359
- icon: d(ae),
360
- message: d(e).t("editor.messages.empty_message"),
361
- title: d(e).t("editor.messages.empty_title")
362
- }, null, 8, ["icon", "message", "title"])) : D("", !0)
294
+ icon: c(Z),
295
+ message: c(e).t("editor.messages.empty_message"),
296
+ title: c(e).t("editor.messages.empty_title")
297
+ }, null, 8, ["icon", "message", "title"])) : w("", !0)
363
298
  ]),
364
299
  _: 1
365
300
  })
366
301
  ], !0)
367
302
  ], 2));
368
303
  }
369
- }), Te = /* @__PURE__ */ P(be, [["__scopeId", "data-v-c8f35a88"]]);
304
+ }), Se = /* @__PURE__ */ R(ye, [["__scopeId", "data-v-c8f35a88"]]);
370
305
  export {
371
- Te as MonacoEditor,
372
- Se as useMonacoEditor
306
+ Se as MonacoEditor,
307
+ ue as useMonacoEditor
373
308
  };
@@ -1 +1 @@
1
- (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue"),require("@kong/icons"),require("monaco-editor"),require("@kong-ui-public/i18n")):typeof define=="function"&&define.amd?define(["exports","vue","@kong/icons","monaco-editor","@kong-ui-public/i18n"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c["kong-ui-public-monaco-editor"]={},c.Vue,c.KongIcons,c.monaco,c["kong-ui-public-i18n"]))})(this,function(c,o,O,B,b){"use strict";function U(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const r=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const k=U(B);typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const I=()=>{};function V(n,t){function e(...r){return new Promise((i,s)=>{Promise.resolve(n(()=>t.apply(this,r),{fn:t,thisArg:this,args:r})).then(i).catch(s)})}return e}function v(n,t={}){let e,r,i=I;const s=d=>{clearTimeout(d),i(),i=I};let l;return d=>{const S=o.toValue(n),u=o.toValue(t.maxWait);return e&&s(e),S<=0||u!==void 0&&u<=0?(r&&(s(r),r=void 0),Promise.resolve(d())):new Promise((C,a)=>{i=t.rejectOnCancel?a:C,l=d,u&&!r&&(r=setTimeout(()=>{e&&s(e),r=void 0,C(l())},u)),e=setTimeout(()=>{r&&s(r),r=void 0,C(d())},S)})}}function R(n,t=200,e={}){return V(v(t,e),n)}function K(n){var t;const e=o.toValue(n);return(t=e==null?void 0:e.$el)!==null&&t!==void 0?t:e}const L=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}});let m=new WeakMap;const h=new Map;function E(n,t){let e=h.get(n);if(e)return console.warn("[monaco-editor] [lifecycle] Disposable is already tracked:",n),e;const r=n.dispose;if(e={...n,dispose:()=>(h.delete(n),r.call(n))},t){const i=e.dispose;e.dispose=()=>{const l=m.get(t.source);return l&&(l.delete(e),l.size===0&&m.delete(t.source)),i()};const s=m.get(t.source);if(s)s.add(e);else switch(m.set(t.source,new Set([e])),t.type){case"editor":t.source.onDidDispose(()=>M(t.source));break;case"model":t.source.onWillDispose(()=>M(t.source));break}}return h.set(n,e),e}function P(n,t){return E(t,{type:"editor",source:n})}function j(n,t){return E(t,{type:"model",source:n})}function M(n){const t=m.get(n);t&&(t.forEach(e=>e.dispose()),m.delete(n))}function A(){h.forEach(n=>n.dispose()),h.clear(),m=new WeakMap}const T={track:E,trackForEditor:P,trackForModel:j,disposeScoped:M,disposeAll:A};let y;const w=new Map;function H(n){return y||(y=k),n&&!w.get(n)&&(w.set(n,!0),k.languages.getLanguages().some(t=>t.id===n)||k.languages.register({id:n})),y}function F(n,t){const e=o.shallowRef();let r=!1;const i=o.reactive({editorStatus:"loading",searchBoxIsRevealed:!1,hasContent:!1,theme:t.theme||"light"}),s=a=>{!r||!e.value||e.value.setValue(a)},l=a=>{var f;return(f=e.value)==null?void 0:f.updateOptions({readOnly:a})},g=()=>{var a;return(a=e.value)==null?void 0:a.focus()},d=a=>{try{if(!e.value||!a)return;e.value.focus(),e.value.trigger("keyboard",a,null)}catch(f){console.error(`useMonacoEditor: Failed to trigger command: ${a}`,f)}},S=()=>{var a;try{if(!e.value)return;if(i.searchBoxIsRevealed)return(a=e.value.getContribution("editor.contrib.findController"))==null?void 0:a.closeFindWidget();d("actions.find")}catch(f){console.error("useMonacoEditor: Failed to close findController.",f)}},u=R(()=>y==null?void 0:y.editor.remeasureFonts(),200);return(()=>{const a=H(t.language),f=a.Uri.parse(`inmemory://model/${t.language}-${crypto.randomUUID()}`),Y=a.editor.createModel(t.code.value,t.language,f);o.watch(()=>o.toValue(n),Z=>{var W;const x=K(Z);if(!(x instanceof HTMLElement)){r=!1;return}if(!r){e.value=a.editor.create(x,{...L,readOnly:t.readOnly||!1,language:t.language,theme:i.theme,model:Y,editContext:!1,...t.monacoOptions}),r=!0,i.editorStatus="ready",i.hasContent=!!t.code.value,T.trackForEditor(e.value,e.value.onDidChangeModelContent(()=>{var _;const p=e.value.getValue();i.hasContent=!!p.length,(_=t.onChanged)==null||_.call(t,p)})),(W=t.onCreated)==null||W.call(t),u();try{const p=e.value.getContribution("editor.contrib.findController");if(p){const _=p.getState();T.trackForEditor(e.value,_.onFindReplaceStateChange(()=>{i.searchBoxIsRevealed=_.isRevealed}))}}catch(p){console.error("useMonacoEditor: Failed to get the state of findController",p)}}},{immediate:!0,flush:"post"})})(),o.onMounted(u),o.onActivated(u),o.onBeforeUnmount(()=>{if(!e.value)return;const a=e.value.getModel();e.value.dispose(),a&&a.dispose()}),{editor:e,editorStates:i,setContent:s,setReadOnly:l,focus:g,remeasureFonts:u,toggleSearchWidget:S,triggerKeyboardCommand:d}}const z={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 $(){const n=b.createI18n("en-us",z);return{i18n:n,i18nT:b.i18nTComponent(n)}}const q=o.defineComponent({__name:"MonacoEditorStatusOverlay",props:{title:{},message:{},icon:{}},setup(n){return(t,e)=>{const r=o.resolveComponent("KEmptyState");return o.openBlock(),o.createBlock(r,{class:"monaco-editor-status-overlay",message:n.message,title:n.title},o.createSlots({_:2},[n.icon?{name:"icon",fn:o.withCtx(()=>[(o.openBlock(),o.createBlock(o.resolveDynamicComponent(n.icon),{decorative:""}))]),key:"0"}:void 0]),1032,["message","title"])}}}),D=(n,t)=>{const e=n.__vccOpts||n;for(const[r,i]of t)e[r]=i;return e},N=D(q,[["__scopeId","data-v-062eadb5"]]),G=D(o.defineComponent({__name:"MonacoEditor",props:o.mergeModels({theme:{default:"light"},language:{default:"markdown"},options:{default:()=>{}}},{modelValue:{type:String,required:!0},modelModifiers:{}}),emits:["update:modelValue"],setup(n){const t=o.useModel(n,"modelValue"),{i18n:e}=$(),r=o.useTemplateRef("editorRef"),i=o.computed(()=>n.theme==="dark"?"dark":"light"),s=o.computed(()=>l.editorStates.editorStatus==="ready"&&!l.editorStates.hasContent),l=F(r,{language:n.language,code:t,theme:i.value,monacoOptions:n.options,onChanged:g=>{t.value=g}});return(g,d)=>(o.openBlock(),o.createElementBlock("div",{class:o.normalizeClass(["monaco-editor-container",[i.value,{loading:o.unref(l).editorStates.editorStatus==="loading"}]]),"data-testid":"monaco-editor-container"},[o.createElementVNode("div",{ref_key:"editorRef",ref:r,class:"monaco-editor-target","data-testid":"monaco-editor-target"},null,512),o.renderSlot(g.$slots,"state-loading",{isLoading:o.unref(l).editorStates.editorStatus==="loading"},()=>[o.createVNode(o.Transition,{name:"fade"},{default:o.withCtx(()=>[o.unref(l).editorStates.editorStatus==="loading"?(o.openBlock(),o.createBlock(N,{key:0,"data-testid":"monaco-editor-status-overlay-loading",icon:o.unref(O.ProgressIcon),message:o.unref(e).t("editor.messages.loading_message",{type:n.language}),title:o.unref(e).t("editor.messages.loading_title",{type:n.language})},null,8,["icon","message","title"])):o.createCommentVNode("",!0)]),_:1})],!0),o.renderSlot(g.$slots,"state-empty",{isEmpty:s.value},()=>[o.createVNode(o.Transition,{name:"fade"},{default:o.withCtx(()=>[s.value?(o.openBlock(),o.createBlock(N,{key:0,"data-testid":"monaco-editor-status-overlay-empty",icon:o.unref(O.CodeblockIcon),message:o.unref(e).t("editor.messages.empty_message"),title:o.unref(e).t("editor.messages.empty_title")},null,8,["icon","message","title"])):o.createCommentVNode("",!0)]),_:1})],!0)],2))}}),[["__scopeId","data-v-c8f35a88"]]);c.MonacoEditor=G,c.useMonacoEditor=F,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@kong/icons"),require("monaco-editor"),require("@kong-ui-public/i18n")):typeof define=="function"&&define.amd?define(["exports","vue","@kong/icons","monaco-editor","@kong-ui-public/i18n"],e):(s=typeof globalThis<"u"?globalThis:s||self,e(s["kong-ui-public-monaco-editor"]={},s.Vue,s.KongIcons,s.monaco,s["kong-ui-public-i18n"]))})(this,function(s,e,S,F,O){"use strict";function N(o){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>o[t]})}}return n.default=o,Object.freeze(n)}const C=N(F),x=Object.freeze({autoClosingQuotes:"always",automaticLayout:!0,bracketPairColorization:{enabled:!0},hideCursorInOverviewRuler:!0,fontFamily:"'JetBrains Mono', Consolas, monospace",fontSize:Number("12px".replace("px","")),fontWeight:"500",lineHeight:Number("20px".replace("px","")),formatOnPaste:!0,formatOnType:!0,lineNumbersMinChars:3,minimap:{enabled:!1},stickyScroll:{enabled:!0},suggest:{showWords:!1},quickSuggestions:!0,suggestOnTriggerCharacters:!0,wordBasedSuggestions:"off",overviewRulerLanes:0,renderWhitespace:"boundary",scrollBeyondLastLine:!1,roundedSelection:!1,wordWrapColumn:120,colorDecorators:!0,folding:!0,fixedOverflowWidgets:!0,tabSize:2,detectIndentation:!1,insertSpaces:!0,trimAutoWhitespace:!0,wordWrap:"bounded",find:{addExtraSpaceOnTop:!1}});typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const b=()=>{};function B(o,n){function t(...r){return new Promise((i,c)=>{Promise.resolve(o(()=>n.apply(this,r),{fn:n,thisArg:this,args:r})).then(i).catch(c)})}return t}function U(o,n={}){let t,r,i=b;const c=d=>{clearTimeout(d),i(),i=b};let l;return d=>{const y=e.toValue(o),u=e.toValue(n.maxWait);return t&&c(t),y<=0||u!==void 0&&u<=0?(r&&(c(r),r=void 0),Promise.resolve(d())):new Promise((_,a)=>{i=n.rejectOnCancel?a:_,l=d,u&&!r&&(r=setTimeout(()=>{t&&c(t),r=void 0,_(l())},u)),t=setTimeout(()=>{r&&c(r),r=void 0,_(d())},y)})}}function V(o,n=200,t={}){return B(U(n,t),o)}function W(o){var n;const t=e.toValue(o);return(n=t==null?void 0:t.$el)!==null&&n!==void 0?n:t}let g;const E=new Map;function D(o){return g||(g=C),o&&!E.get(o)&&(E.set(o,!0),C.languages.getLanguages().some(n=>n.id===o)||C.languages.register({id:o})),g}function I(o,n){let t,r=!1;const i=e.reactive({editorStatus:"loading",searchBoxIsRevealed:!1,hasContent:!1,theme:n.theme||"light"}),c=a=>{!r||!t||t.setValue(a)},l=a=>t==null?void 0:t.updateOptions({readOnly:a}),m=()=>t==null?void 0:t.focus(),d=a=>{try{if(!t||!a)return;t.focus(),t.trigger("keyboard",a,null)}catch(p){console.error(`useMonacoEditor: Failed to trigger command: ${a}`,p)}},y=()=>{var a;try{if(!t)return;if(i.searchBoxIsRevealed)return(a=t.getContribution("editor.contrib.findController"))==null?void 0:a.closeFindWidget();d("actions.find")}catch(p){console.error("useMonacoEditor: Failed to close findController.",p)}},u=V(()=>g==null?void 0:g.editor.remeasureFonts(),200);return(()=>{const a=D(n.language),p=a.Uri.parse(`inmemory://model/${n.language}-${crypto.randomUUID()}`),j=a.editor.createModel(n.code.value,n.language,p);e.watch(()=>e.toValue(o),H=>{var w;const M=W(H);if(!(M instanceof HTMLElement)){r=!1;return}if(!r){t=a.editor.create(M,{...x,readOnly:n.readOnly||!1,language:n.language,theme:i.theme,model:j,editContext:!1,...n.monacoOptions}),r=!0,i.editorStatus="ready",i.hasContent=!!n.code.value,t.onDidChangeModelContent(()=>{var h;const f=t.getValue();i.hasContent=!!f.length,(h=n.onChanged)==null||h.call(n,f)}),(w=n.onCreated)==null||w.call(n),u();try{const f=t.getContribution("editor.contrib.findController");if(f){const h=f.getState();h.onFindReplaceStateChange(()=>{i.searchBoxIsRevealed=h.isRevealed})}}catch(f){console.error("useMonacoEditor: Failed to get the state of findController",f)}}},{immediate:!0,flush:"post"})})(),e.onMounted(u),e.onActivated(u),e.onBeforeUnmount(()=>{if(!t)return;const a=t.getModel();t.dispose(),a&&a.dispose()}),{editor:t,editorStates:i,setContent:c,setReadOnly:l,focus:m,remeasureFonts:u,toggleSearchWidget:y,triggerKeyboardCommand:d}}const R={editor:{messages:{empty_message:"The editor is currently empty. Start typing to add content.",empty_title:"No content available",loading_message:"Please wait while the {type} content is loaded.",loading_title:"{type} editor"}}};function K(){const o=O.createI18n("en-us",R);return{i18n:o,i18nT:O.i18nTComponent(o)}}const L=e.defineComponent({__name:"MonacoEditorStatusOverlay",props:{title:{},message:{},icon:{}},setup(o){return(n,t)=>{const r=e.resolveComponent("KEmptyState");return e.openBlock(),e.createBlock(r,{class:"monaco-editor-status-overlay",message:o.message,title:o.title},e.createSlots({_:2},[o.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.icon),{decorative:""}))]),key:"0"}:void 0]),1032,["message","title"])}}}),T=(o,n)=>{const t=o.__vccOpts||o;for(const[r,i]of n)t[r]=i;return t},k=T(L,[["__scopeId","data-v-062eadb5"]]),P=T(e.defineComponent({__name:"MonacoEditor",props:e.mergeModels({theme:{default:"light"},language:{default:"markdown"},options:{default:()=>{}}},{modelValue:{type:String,required:!0},modelModifiers:{}}),emits:["update:modelValue"],setup(o){const n=e.useModel(o,"modelValue"),{i18n:t}=K(),r=e.useTemplateRef("editorRef"),i=e.computed(()=>o.theme==="dark"?"dark":"light"),c=e.computed(()=>l.editorStates.editorStatus==="ready"&&!l.editorStates.hasContent),l=I(r,{language:o.language,code:n,theme:i.value,monacoOptions:o.options,onChanged:m=>{n.value=m}});return(m,d)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["monaco-editor-container",[i.value,{loading:e.unref(l).editorStates.editorStatus==="loading"}]]),"data-testid":"monaco-editor-container"},[e.createElementVNode("div",{ref_key:"editorRef",ref:r,class:"monaco-editor-target","data-testid":"monaco-editor-target"},null,512),e.renderSlot(m.$slots,"state-loading",{isLoading:e.unref(l).editorStates.editorStatus==="loading"},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[e.unref(l).editorStates.editorStatus==="loading"?(e.openBlock(),e.createBlock(k,{key:0,"data-testid":"monaco-editor-status-overlay-loading",icon:e.unref(S.ProgressIcon),message:e.unref(t).t("editor.messages.loading_message",{type:o.language}),title:e.unref(t).t("editor.messages.loading_title",{type:o.language})},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0),e.renderSlot(m.$slots,"state-empty",{isEmpty:c.value},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[c.value?(e.openBlock(),e.createBlock(k,{key:0,"data-testid":"monaco-editor-status-overlay-empty",icon:e.unref(S.CodeblockIcon),message:e.unref(t).t("editor.messages.empty_message"),title:e.unref(t).t("editor.messages.empty_title")},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0)],2))}}),[["__scopeId","data-v-c8f35a88"]]);s.MonacoEditor=P,s.useMonacoEditor=I,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
@@ -8,7 +8,7 @@ import type { UseMonacoEditorOptions } from '../types';
8
8
  * @returns {object} An object containing the editor instance and utility methods.
9
9
  */
10
10
  export declare function useMonacoEditor<T extends MaybeElement>(target: MaybeComputedElementRef<T>, options: UseMonacoEditorOptions): {
11
- editor: import("vue").ShallowRef<monaco.editor.IStandaloneCodeEditor | undefined, monaco.editor.IStandaloneCodeEditor | undefined>;
11
+ editor: monaco.editor.IStandaloneCodeEditor | undefined;
12
12
  editorStates: {
13
13
  editorStatus: import("..").EditorStatus;
14
14
  searchBoxIsRevealed: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"useMonacoEditor.d.ts","sourceRoot":"","sources":["../../../../src/composables/useMonacoEditor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AASvC,OAAO,KAAK,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,KAAK,EAAsB,sBAAsB,EAAE,MAAM,UAAU,CAAA;AA+B1E;;;;;EAKE;AACF,wBAAgB,eAAe,CAAC,CAAC,SAAS,YAAY,EACpD,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,EAClC,OAAO,EAAE,sBAAsB;;;;;;;;0BAoBF,MAAM,KAAG,IAAI;4BAOX,OAAO,KAAG,IAAI;iBAG3B,IAAI;;8BAkBS,IAAI;iCAXC,MAAM,KAAG,IAAI;EAwIlD"}
1
+ {"version":3,"file":"useMonacoEditor.d.ts","sourceRoot":"","sources":["../../../../src/composables/useMonacoEditor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC,OAAO,KAAK,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,KAAK,EAAsB,sBAAsB,EAAE,MAAM,UAAU,CAAA;AA+B1E;;;;;EAKE;AACF,wBAAgB,eAAe,CAAC,CAAC,SAAS,YAAY,EACpD,MAAM,EAAE,uBAAuB,CAAC,CAAC,CAAC,EAClC,OAAO,EAAE,sBAAsB;;;;;;;;0BAqBF,MAAM,KAAG,IAAI;4BAOX,OAAO,KAAG,IAAI;iBAG3B,IAAI;;8BAkBS,IAAI;iCAXC,MAAM,KAAG,IAAI;EAoIlD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kong-ui-public/monaco-editor",
3
- "version": "0.4.11-pr.2769.31aadbf56.0",
3
+ "version": "0.4.11",
4
4
  "type": "module",
5
5
  "main": "./dist/runtime/monaco-editor.umd.js",
6
6
  "module": "./dist/runtime/monaco-editor.es.js",
@@ -53,7 +53,7 @@
53
53
  "devDependencies": {
54
54
  "@kong/design-tokens": "1.18.2",
55
55
  "@kong/icons": "^1.41.0",
56
- "@kong/kongponents": "9.48.7",
56
+ "@kong/kongponents": "9.48.8",
57
57
  "monaco-editor": "^0.55.1",
58
58
  "vue": "^3.5.26",
59
59
  "@kong-ui-public/i18n": "^2.4.5"
@@ -1,2 +0,0 @@
1
- export * from './lifecycle';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/singletons/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
@@ -1,31 +0,0 @@
1
- import type { editor as Editor, IDisposable } from 'monaco-editor';
2
- type Scope = {
3
- type: 'editor';
4
- source: Editor.ICodeEditor;
5
- } | {
6
- type: 'model';
7
- source: Editor.ITextModel;
8
- };
9
- type ScopeSource = Editor.ICodeEditor | Editor.ITextModel;
10
- /**
11
- * Track a disposable in the global scope.
12
- *
13
- * @param disposable The disposable to track
14
- */
15
- declare function track(disposable: IDisposable, scope?: Scope): IDisposable;
16
- declare function trackForEditor(editor: Editor.ICodeEditor, disposable: IDisposable): IDisposable;
17
- declare function trackForModel(model: Editor.ITextModel, disposable: IDisposable): IDisposable;
18
- declare function disposeScoped(source: ScopeSource): void;
19
- /**
20
- * Dispose all tracked disposables.
21
- */
22
- declare function disposeAll(): void;
23
- export declare const lifecycle: {
24
- readonly track: typeof track;
25
- readonly trackForEditor: typeof trackForEditor;
26
- readonly trackForModel: typeof trackForModel;
27
- readonly disposeScoped: typeof disposeScoped;
28
- readonly disposeAll: typeof disposeAll;
29
- };
30
- export {};
31
- //# sourceMappingURL=lifecycle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../../../src/singletons/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,MAAM,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAElE,KAAK,KAAK,GACN;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAA;CAAE,CAAA;AAChD,KAAK,WAAW,GAAG,MAAM,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAA;AAKzD;;;;GAIG;AACH,iBAAS,KAAK,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,WAAW,CA+ClE;AAED,iBAAS,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,EAAE,WAAW,GAAG,WAAW,CAExF;AAED,iBAAS,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,GAAG,WAAW,CAErF;AAED,iBAAS,aAAa,CAAC,MAAM,EAAE,WAAW,QAMzC;AAED;;GAEG;AACH,iBAAS,UAAU,SAIlB;AAED,eAAO,MAAM,SAAS;;;;;;CAMZ,CAAA"}