@kong-ui-public/monaco-editor 0.8.1-pr.2793.a36bf7dcd.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 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";
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
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({
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 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: 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.
@@ -73,14 +73,14 @@ function we(o, t) {
73
73
  }
74
74
  return e;
75
75
  }
76
- function Oe(o, t = {}) {
76
+ function _e(o, t = {}) {
77
77
  let e, a, i = P;
78
78
  const r = (s) => {
79
79
  clearTimeout(s), i(), i = P;
80
80
  };
81
81
  let l;
82
82
  return (s) => {
83
- const p = w(o), g = w(t.maxWait);
83
+ const p = C(o), g = C(t.maxWait);
84
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
85
  i = t.rejectOnCancel ? h : c, l = s, g && !a && (a = setTimeout(() => {
86
86
  e && r(e), a = void 0, c(l());
@@ -91,25 +91,20 @@ function Oe(o, t = {}) {
91
91
  };
92
92
  }
93
93
  // @__NO_SIDE_EFFECTS__
94
- function ke(o, t = 200, e = {}) {
95
- return we(Oe(t, e), o);
96
- }
97
- function $(o) {
98
- var t;
99
- const e = w(o);
100
- return (t = e == null ? void 0 : e.$el) !== null && t !== void 0 ? t : e;
94
+ function Oe(o, t = 200, e = {}) {
95
+ return we(_e(t, e), o);
101
96
  }
102
97
  const F = "[monaco-editor] [lifecycle]", y = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new WeakMap();
103
- function Te(o) {
98
+ function ke(o) {
104
99
  let t = y.get(o.source);
105
100
  if (!t) {
106
101
  let e;
107
102
  switch (o.type) {
108
103
  case "editor":
109
- e = o.source.onDidDispose(() => K(o.source));
104
+ e = o.source.onDidDispose(() => $(o.source));
110
105
  break;
111
106
  case "model":
112
- e = o.source.onWillDispose(() => K(o.source));
107
+ e = o.source.onWillDispose(() => $(o.source));
113
108
  break;
114
109
  default:
115
110
  throw new Error(`${F} Unknown scope: ${o}`);
@@ -121,18 +116,18 @@ function Te(o) {
121
116
  }
122
117
  return t;
123
118
  }
124
- function G(o) {
119
+ function H(o) {
125
120
  const t = y.get(o);
126
121
  t && (t.scopeListener.dispose(), y.delete(o));
127
122
  }
128
123
  function A(o, t) {
129
- Te(t).disposables.add(o);
124
+ ke(t).disposables.add(o);
130
125
  }
131
126
  function j(o, t) {
132
127
  const e = y.get(t.source);
133
- e && (e.disposables.delete(o), e.disposables.size === 0 && G(t.source));
128
+ e && (e.disposables.delete(o), e.disposables.size === 0 && H(t.source));
134
129
  }
135
- function Ie(o) {
130
+ function Te(o) {
136
131
  const t = [];
137
132
  if (o.forEach((e) => {
138
133
  try {
@@ -146,7 +141,7 @@ function Ie(o) {
146
141
  `${F} One or more disposables threw while being disposed.`
147
142
  );
148
143
  }
149
- function xe(o, t) {
144
+ function Ie(o, t) {
150
145
  var l, f;
151
146
  let e = o, a = S.get(e);
152
147
  if (!a) {
@@ -165,45 +160,45 @@ function xe(o, t) {
165
160
  return S.set(e, { decorated: r, scope: t }), I.set(r, e), t && A(r, t), r;
166
161
  }
167
162
  function V(o, t) {
168
- return xe(t, { type: "editor", source: o });
163
+ return Ie(t, { type: "editor", source: o });
169
164
  }
170
- function K(o) {
165
+ function $(o) {
171
166
  const t = y.get(o);
172
167
  if (!t) return;
173
168
  const e = Array.from(t.disposables);
174
169
  try {
175
- Ie(e);
170
+ Te(e);
176
171
  } catch (a) {
177
172
  console.warn(`${F} Encountered errors while disposing scoped disposables:`, a, ", Source:", o);
178
173
  }
179
- G(o);
174
+ H(o);
180
175
  }
181
- const q = X(!1);
176
+ const G = Q(!1);
182
177
  let b = null;
183
- async function De() {
178
+ async function xe() {
184
179
  return b || (b = (async () => {
185
180
  var o, t;
186
181
  try {
187
182
  const e = ((o = m.json) == null ? void 0 : o.jsonDefaults) || ((t = m.languages.json) == null ? void 0 : t.jsonDefaults);
188
183
  e == null || e.setModeConfiguration({ tokens: !1 });
189
- const a = await pe(
184
+ const a = await fe(
190
185
  {
191
- themes: Object.values(ve),
192
- langs: Object.values(he)
186
+ themes: Object.values(he),
187
+ langs: Object.values(pe)
193
188
  }
194
189
  );
195
190
  a.getLoadedLanguages().forEach((i) => {
196
191
  m.languages.register({ id: i });
197
- }), fe(a, m), q.value = !0;
192
+ }), me(a, m), G.value = !0;
198
193
  } catch (e) {
199
194
  throw b = null, e;
200
195
  }
201
196
  })(), b);
202
197
  }
203
- function Fe(o, t) {
204
- const e = Y();
198
+ function De(o, t) {
199
+ const e = X();
205
200
  let a, i = !1, r = !1;
206
- const l = Z({
201
+ const l = Y({
207
202
  editorStatus: "loading",
208
203
  searchBoxIsRevealed: !1,
209
204
  hasContent: !1,
@@ -217,8 +212,8 @@ function Fe(o, t) {
217
212
  var n;
218
213
  return (n = e.value) == null ? void 0 : n.focus();
219
214
  }, g = (n) => {
220
- var M;
221
- const d = (M = e.value) == null ? void 0 : M.getModel();
215
+ var w;
216
+ const d = (w = e.value) == null ? void 0 : w.getModel();
222
217
  d && m.editor.setModelLanguage(d, n);
223
218
  }, c = (n) => {
224
219
  try {
@@ -237,22 +232,22 @@ function Fe(o, t) {
237
232
  } catch (d) {
238
233
  console.error("useMonacoEditor: Failed to close findController.", d);
239
234
  }
240
- }, E = /* @__PURE__ */ ke(() => m.editor.remeasureFonts(), 200);
235
+ }, M = /* @__PURE__ */ Oe(() => m.editor.remeasureFonts(), 200);
241
236
  return (() => {
242
- De(), x([q, () => w(o)], ([n, d], [, M]) => {
237
+ xe(), x([G, () => C(o)], ([n, d], [, w]) => {
243
238
  var L;
244
- const k = $(d), Q = $(M);
239
+ const k = C(d), J = C(w);
245
240
  if (!(k instanceof HTMLElement) || !n) {
246
241
  i = !1;
247
242
  return;
248
243
  }
249
- if (!(i && Q === k)) {
244
+ if (!(i && J === k)) {
250
245
  if (!a) {
251
246
  const u = m.Uri.parse(`inmemory://model/${t.language}-${crypto.randomUUID()}`);
252
247
  a = m.editor.createModel(t.code.value, t.language, u);
253
248
  }
254
249
  e.value = m.editor.create(k, {
255
- ..._e,
250
+ ...Me,
256
251
  readOnly: t.readOnly || !1,
257
252
  language: t.language,
258
253
  theme: l.theme === "light" ? "catppuccin-latte" : "catppuccin-mocha",
@@ -266,7 +261,7 @@ function Fe(o, t) {
266
261
  const u = e.value.getValue();
267
262
  l.hasContent = !!u.length, t.code.value = u;
268
263
  })
269
- ), (L = t.onReady) == null || L.call(t, e.value), E();
264
+ ), (L = t.onReady) == null || L.call(t, e.value), M();
270
265
  try {
271
266
  const u = e.value.getContribution("editor.contrib.findController"), _ = u == null ? void 0 : u.getState();
272
267
  V(
@@ -279,7 +274,7 @@ function Fe(o, t) {
279
274
  } catch (u) {
280
275
  console.error("useMonacoEditor: Failed to get the state of findController", u);
281
276
  }
282
- ae(() => {
277
+ oe(() => {
283
278
  var u;
284
279
  (u = e.value) == null || u.dispose();
285
280
  });
@@ -297,7 +292,7 @@ function Fe(o, t) {
297
292
  text: n
298
293
  }
299
294
  ]), e.value.pushUndoStop(), l.hasContent = !!n.length, r = !1);
300
- }), ee(E), te(E), oe(() => {
295
+ }), Z(M), ee(M), te(() => {
301
296
  if (!e.value) return;
302
297
  const n = e.value.getModel();
303
298
  e.value.dispose(), n && n.dispose();
@@ -308,30 +303,30 @@ function Fe(o, t) {
308
303
  setReadOnly: s,
309
304
  focus: p,
310
305
  setLanguage: g,
311
- remeasureFonts: E,
306
+ remeasureFonts: M,
312
307
  toggleSearchWidget: h,
313
308
  triggerKeyboardCommand: c
314
309
  };
315
310
  }
316
- const Le = {
311
+ const Fe = {
317
312
  messages: {
318
313
  empty_message: "The editor is currently empty. Start typing to add content.",
319
314
  empty_title: "No content available",
320
315
  loading_message: "Please wait while the {type} content is loaded.",
321
316
  loading_title: "{type} editor"
322
317
  }
323
- }, Re = {
324
- editor: Le
318
+ }, Le = {
319
+ editor: Fe
325
320
  };
326
- function We() {
327
- const o = ye("en-us", Re);
321
+ function Re() {
322
+ const o = ve("en-us", Le);
328
323
  return {
329
324
  i18n: o,
330
- i18nT: Se(o)
325
+ i18nT: ye(o)
331
326
  // Translation component <i18n-t>
332
327
  };
333
328
  }
334
- const Ne = /* @__PURE__ */ H({
329
+ const We = /* @__PURE__ */ z({
335
330
  __name: "MonacoEditorStatusOverlay",
336
331
  props: {
337
332
  title: {},
@@ -340,28 +335,28 @@ const Ne = /* @__PURE__ */ H({
340
335
  },
341
336
  setup(o) {
342
337
  return (t, e) => {
343
- const a = ne("KEmptyState");
344
- return C(), O(a, {
338
+ const a = ae("KEmptyState");
339
+ return E(), O(a, {
345
340
  class: "monaco-editor-status-overlay",
346
341
  message: o.message,
347
342
  title: o.title
348
- }, re({ _: 2 }, [
343
+ }, ne({ _: 2 }, [
349
344
  o.icon ? {
350
345
  name: "icon",
351
346
  fn: D(() => [
352
- (C(), O(se(o.icon), { decorative: "" }))
347
+ (E(), O(re(o.icon), { decorative: "" }))
353
348
  ]),
354
349
  key: "0"
355
350
  } : void 0
356
351
  ]), 1032, ["message", "title"]);
357
352
  };
358
353
  }
359
- }), J = (o, t) => {
354
+ }), q = (o, t) => {
360
355
  const e = o.__vccOpts || o;
361
356
  for (const [a, i] of t)
362
357
  e[a] = i;
363
358
  return e;
364
- }, z = /* @__PURE__ */ J(Ne, [["__scopeId", "data-v-062eadb5"]]), Ue = /* @__PURE__ */ H({
359
+ }, K = /* @__PURE__ */ q(We, [["__scopeId", "data-v-062eadb5"]]), Ne = /* @__PURE__ */ z({
365
360
  __name: "MonacoEditor",
366
361
  props: /* @__PURE__ */ R({
367
362
  theme: { default: "light" },
@@ -378,7 +373,7 @@ const Ne = /* @__PURE__ */ H({
378
373
  }),
379
374
  emits: /* @__PURE__ */ R(["ready"], ["update:modelValue"]),
380
375
  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, {
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, {
382
377
  language: o.language,
383
378
  code: i,
384
379
  theme: f.value,
@@ -391,14 +386,14 @@ const Ne = /* @__PURE__ */ H({
391
386
  monacoEditor: g
392
387
  }), x(() => o.language, (c, h) => {
393
388
  c !== h && g.setLanguage(c);
394
- }), (c, h) => (C(), ce("div", {
395
- class: de(["monaco-editor-container", [
389
+ }), (c, h) => (E(), le("div", {
390
+ class: ce(["monaco-editor-container", [
396
391
  f.value,
397
392
  { loading: s.value }
398
393
  ]]),
399
394
  "data-testid": "monaco-editor-container"
400
395
  }, [
401
- ue("div", {
396
+ de("div", {
402
397
  ref_key: "editorRef",
403
398
  ref: l,
404
399
  class: "monaco-editor-target",
@@ -407,10 +402,10 @@ const Ne = /* @__PURE__ */ H({
407
402
  W(c.$slots, "state-loading", { isLoading: s.value }, () => [
408
403
  N(U, { name: "fade" }, {
409
404
  default: D(() => [
410
- s.value ? (C(), O(z, {
405
+ s.value ? (E(), O(K, {
411
406
  key: 0,
412
407
  "data-testid": "monaco-editor-status-overlay-loading",
413
- icon: v(ge),
408
+ icon: v(ue),
414
409
  message: v(r).t("editor.messages.loading_message", { type: o.language }),
415
410
  title: v(r).t("editor.messages.loading_title", { type: o.language })
416
411
  }, null, 8, ["icon", "message", "title"])) : B("", !0)
@@ -421,10 +416,10 @@ const Ne = /* @__PURE__ */ H({
421
416
  W(c.$slots, "state-empty", { isEmpty: p.value }, () => [
422
417
  N(U, { name: "fade" }, {
423
418
  default: D(() => [
424
- p.value && !s.value ? (C(), O(z, {
419
+ p.value && !s.value ? (E(), O(K, {
425
420
  key: 0,
426
421
  "data-testid": "monaco-editor-status-overlay-empty",
427
- icon: v(me),
422
+ icon: v(ge),
428
423
  message: v(r).t("editor.messages.empty_message"),
429
424
  title: v(r).t("editor.messages.empty_title")
430
425
  }, null, 8, ["icon", "message", "title"])) : B("", !0)
@@ -434,8 +429,8 @@ const Ne = /* @__PURE__ */ H({
434
429
  ], !0)
435
430
  ], 2));
436
431
  }
437
- }), Ke = /* @__PURE__ */ J(Ue, [["__scopeId", "data-v-e2083635"]]);
432
+ }), $e = /* @__PURE__ */ q(Ne, [["__scopeId", "data-v-e2083635"]]);
438
433
  export {
439
- Ke as MonacoEditor,
440
- Fe as useMonacoEditor
434
+ $e as MonacoEditor,
435
+ De as useMonacoEditor
441
436
  };
@@ -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(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;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;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kong-ui-public/monaco-editor",
3
- "version": "0.8.1-pr.2793.a36bf7dcd.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",