@kong-ui-public/monaco-editor 0.4.11 → 0.5.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.
@@ -1,8 +1,10 @@
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";
1
+ import { toValue as S, ref as B, reactive as D, onMounted as P, onActivated as U, onBeforeUnmount as V, watch as j, defineComponent as W, resolveComponent as K, createBlock as _, openBlock as y, createSlots as A, withCtx as b, resolveDynamicComponent as H, mergeModels as $, useModel as z, useTemplateRef as G, computed as M, createElementBlock as q, normalizeClass as J, unref as u, createElementVNode as Q, renderSlot as T, createVNode as I, Transition as k, createCommentVNode as w } from "vue";
2
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({
3
+ import * as m from "monaco-editor";
4
+ import { shikiToMonaco as X } from "@shikijs/monaco";
5
+ import { getSingletonHighlighter as ee, bundledLanguages as te, bundledThemes as oe } from "shiki";
6
+ import { createI18n as ne, i18nTComponent as ae } from "@kong-ui-public/i18n";
7
+ const re = "'JetBrains Mono', Consolas, monospace", ie = "12px", se = "500", le = "20px", ce = Object.freeze({
6
8
  autoClosingQuotes: "always",
7
9
  automaticLayout: !0,
8
10
  // Auto resize layout
@@ -11,10 +13,10 @@ const te = "'JetBrains Mono', Consolas, monospace", oe = "12px", ne = "500", ae
11
13
  },
12
14
  hideCursorInOverviewRuler: !0,
13
15
  // hide the cursor position in the minimap TODO: maybe hide it on first line or change it colour
14
- fontFamily: te,
15
- fontSize: Number(oe.replace("px", "")),
16
- fontWeight: ne,
17
- lineHeight: Number(ae.replace("px", "")),
16
+ fontFamily: re,
17
+ fontSize: Number(ie.replace("px", "")),
18
+ fontWeight: se,
19
+ lineHeight: Number(le.replace("px", "")),
18
20
  formatOnPaste: !0,
19
21
  formatOnType: !0,
20
22
  // Add to enable automatic formatting as the user types.
@@ -59,149 +61,171 @@ const te = "'JetBrains Mono', Consolas, monospace", oe = "12px", ne = "500", ae
59
61
  typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
60
62
  const x = () => {
61
63
  };
62
- function ie(o, t) {
64
+ function de(o, t) {
63
65
  function e(...n) {
64
- return new Promise((r, i) => {
66
+ return new Promise((a, i) => {
65
67
  Promise.resolve(o(() => t.apply(this, n), {
66
68
  fn: t,
67
69
  thisArg: this,
68
70
  args: n
69
- })).then(r).catch(i);
71
+ })).then(a).catch(i);
70
72
  });
71
73
  }
72
74
  return e;
73
75
  }
74
- function se(o, t = {}) {
75
- let e, n, r = x;
76
+ function ue(o, t = {}) {
77
+ let e, n, a = x;
76
78
  const i = (l) => {
77
- clearTimeout(l), r(), r = x;
79
+ clearTimeout(l), a(), a = x;
78
80
  };
79
81
  let s;
80
82
  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);
83
+ const v = S(o), c = S(t.maxWait);
84
+ return e && i(e), v <= 0 || c !== void 0 && c <= 0 ? (n && (i(n), n = void 0), Promise.resolve(l())) : new Promise((C, r) => {
85
+ a = t.rejectOnCancel ? r : C, s = l, c && !n && (n = setTimeout(() => {
86
+ e && i(e), n = void 0, C(s());
87
+ }, c)), e = setTimeout(() => {
88
+ n && i(n), n = void 0, C(l());
89
+ }, v);
88
90
  });
89
91
  };
90
92
  }
91
93
  // @__NO_SIDE_EFFECTS__
92
- function le(o, t = 200, e = {}) {
93
- return ie(se(t, e), o);
94
+ function me(o, t = 200, e = {}) {
95
+ return de(ue(t, e), o);
94
96
  }
95
- function de(o) {
97
+ function ge(o) {
96
98
  var t;
97
- const e = C(o);
99
+ const e = S(o);
98
100
  return (t = e == null ? void 0 : e.$el) !== null && t !== void 0 ? t : e;
99
101
  }
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;
102
+ const L = B(!1);
103
+ let p = null;
104
+ async function fe() {
105
+ return p || (p = (async () => {
106
+ var o, t;
107
+ try {
108
+ const e = ((o = m.json) == null ? void 0 : o.jsonDefaults) || ((t = m.languages.json) == null ? void 0 : t.jsonDefaults);
109
+ e == null || e.setModeConfiguration({ tokens: !1 });
110
+ const n = await ee(
111
+ {
112
+ themes: Object.values(oe),
113
+ langs: Object.values(te)
114
+ }
115
+ );
116
+ n.getLoadedLanguages().forEach((a) => {
117
+ m.languages.register({ id: a });
118
+ }), X(n, m), L.value = !0;
119
+ } catch (e) {
120
+ throw p = null, e;
121
+ }
122
+ })(), p);
104
123
  }
105
- function ue(o, t) {
124
+ function he(o, t) {
106
125
  let e, n = !1;
107
- const r = U({
126
+ const a = D({
108
127
  editorStatus: "loading",
109
128
  searchBoxIsRevealed: !1,
110
129
  hasContent: !1,
111
130
  theme: t.theme || "light"
112
- }), i = (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) => {
131
+ }), i = (r) => {
132
+ !n || !e || e.setValue(r);
133
+ }, s = (r) => e == null ? void 0 : e.updateOptions({ readOnly: r }), g = () => e == null ? void 0 : e.focus(), l = (r) => {
115
134
  try {
116
- if (!e || !a) return;
117
- e.focus(), e.trigger("keyboard", a, null);
135
+ if (!e || !r) return;
136
+ e.focus(), e.trigger("keyboard", r, null);
118
137
  } catch (f) {
119
- console.error(`useMonacoEditor: Failed to trigger command: ${a}`, f);
138
+ console.error(`useMonacoEditor: Failed to trigger command: ${r}`, f);
120
139
  }
121
- }, p = () => {
122
- var a;
140
+ }, v = () => {
141
+ var r;
123
142
  try {
124
143
  if (!e) return;
125
- if (r.searchBoxIsRevealed)
126
- return (a = e.getContribution("editor.contrib.findController")) == null ? void 0 : a.closeFindWidget();
144
+ if (a.searchBoxIsRevealed)
145
+ return (r = e.getContribution("editor.contrib.findController")) == null ? void 0 : r.closeFindWidget();
127
146
  l("actions.find");
128
147
  } catch (f) {
129
148
  console.error("useMonacoEditor: Failed to close findController.", f);
130
149
  }
131
- }, d = /* @__PURE__ */ le(() => g == null ? void 0 : g.editor.remeasureFonts(), 200);
150
+ }, c = /* @__PURE__ */ me(() => m.editor.remeasureFonts(), 200);
132
151
  return (() => {
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) => {
152
+ fe();
153
+ let r;
154
+ j([L, () => S(o)], ([f, R]) => {
135
155
  var O;
136
- const b = de(L);
137
- if (!(b instanceof HTMLElement)) {
156
+ const E = ge(R);
157
+ if (!(E instanceof HTMLElement) || !f) {
138
158
  n = !1;
139
159
  return;
140
160
  }
141
161
  if (!n) {
142
- e = a.editor.create(b, {
143
- ...re,
162
+ if (!r) {
163
+ const d = m.Uri.parse(`inmemory://model/${t.language}-${crypto.randomUUID()}`);
164
+ r = m.editor.createModel(t.code.value, t.language, d);
165
+ }
166
+ e = m.editor.create(E, {
167
+ ...ce,
144
168
  readOnly: t.readOnly || !1,
145
169
  language: t.language,
146
- theme: r.theme,
147
- model: B,
170
+ theme: a.theme === "light" ? "catppuccin-latte" : "catppuccin-mocha",
171
+ model: r,
148
172
  editContext: !1,
149
173
  ...t.monacoOptions
150
- }), n = !0, r.editorStatus = "ready", r.hasContent = !!t.code.value, e.onDidChangeModelContent(() => {
174
+ }), n = !0, a.editorStatus = "ready", a.hasContent = !!t.code.value, e.onDidChangeModelContent(() => {
151
175
  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();
176
+ const d = e.getValue();
177
+ a.hasContent = !!d.length, (h = t.onChanged) == null || h.call(t, d);
178
+ }), (O = t.onCreated) == null || O.call(t), c();
155
179
  try {
156
- const m = e.getContribution("editor.contrib.findController");
157
- if (m) {
158
- const h = m.getState();
180
+ const d = e.getContribution("editor.contrib.findController");
181
+ if (d) {
182
+ const h = d.getState();
159
183
  h.onFindReplaceStateChange(() => {
160
- r.searchBoxIsRevealed = h.isRevealed;
184
+ a.searchBoxIsRevealed = h.isRevealed;
161
185
  });
162
186
  }
163
- } catch (m) {
164
- console.error("useMonacoEditor: Failed to get the state of findController", m);
187
+ } catch (d) {
188
+ console.error("useMonacoEditor: Failed to get the state of findController", d);
165
189
  }
166
190
  }
167
191
  }, {
168
192
  immediate: !0,
169
193
  flush: "post"
170
194
  });
171
- })(), D(d), P(d), V(() => {
195
+ })(), P(c), U(c), V(() => {
172
196
  if (!e) return;
173
- const a = e.getModel();
174
- e.dispose(), a && a.dispose();
197
+ const r = e.getModel();
198
+ e.dispose(), r && r.dispose();
175
199
  }), {
176
200
  editor: e,
177
- editorStates: r,
201
+ editorStates: a,
178
202
  setContent: i,
179
203
  setReadOnly: s,
180
- focus: u,
181
- remeasureFonts: d,
182
- toggleSearchWidget: p,
204
+ focus: g,
205
+ remeasureFonts: c,
206
+ toggleSearchWidget: v,
183
207
  triggerKeyboardCommand: l
184
208
  };
185
209
  }
186
- const me = {
210
+ const pe = {
187
211
  messages: {
188
212
  empty_message: "The editor is currently empty. Start typing to add content.",
189
213
  empty_title: "No content available",
190
214
  loading_message: "Please wait while the {type} content is loaded.",
191
215
  loading_title: "{type} editor"
192
216
  }
193
- }, ge = {
194
- editor: me
217
+ }, ye = {
218
+ editor: pe
195
219
  };
196
- function fe() {
197
- const o = X("en-us", ge);
220
+ function ve() {
221
+ const o = ne("en-us", ye);
198
222
  return {
199
223
  i18n: o,
200
- i18nT: ee(o)
224
+ i18nT: ae(o)
201
225
  // Translation component <i18n-t>
202
226
  };
203
227
  }
204
- const he = /* @__PURE__ */ N({
228
+ const Ce = /* @__PURE__ */ W({
205
229
  __name: "MonacoEditorStatusOverlay",
206
230
  props: {
207
231
  title: {},
@@ -210,30 +234,30 @@ const he = /* @__PURE__ */ N({
210
234
  },
211
235
  setup(o) {
212
236
  return (t, e) => {
213
- const n = A("KEmptyState");
214
- return y(), S(n, {
237
+ const n = K("KEmptyState");
238
+ return y(), _(n, {
215
239
  class: "monaco-editor-status-overlay",
216
240
  message: o.message,
217
241
  title: o.title
218
- }, $({ _: 2 }, [
242
+ }, A({ _: 2 }, [
219
243
  o.icon ? {
220
244
  name: "icon",
221
- fn: E(() => [
222
- (y(), S(z(o.icon), { decorative: "" }))
245
+ fn: b(() => [
246
+ (y(), _(H(o.icon), { decorative: "" }))
223
247
  ]),
224
248
  key: "0"
225
249
  } : void 0
226
250
  ]), 1032, ["message", "title"]);
227
251
  };
228
252
  }
229
- }), R = (o, t) => {
253
+ }), N = (o, t) => {
230
254
  const e = o.__vccOpts || o;
231
- for (const [n, r] of t)
232
- e[n] = r;
255
+ for (const [n, a] of t)
256
+ e[n] = a;
233
257
  return e;
234
- }, W = /* @__PURE__ */ R(he, [["__scopeId", "data-v-062eadb5"]]), ye = /* @__PURE__ */ N({
258
+ }, F = /* @__PURE__ */ N(Ce, [["__scopeId", "data-v-062eadb5"]]), Se = /* @__PURE__ */ W({
235
259
  __name: "MonacoEditor",
236
- props: /* @__PURE__ */ H({
260
+ props: /* @__PURE__ */ $({
237
261
  theme: { default: "light" },
238
262
  language: { default: "markdown" },
239
263
  options: { default: () => {
@@ -247,19 +271,19 @@ const he = /* @__PURE__ */ N({
247
271
  }),
248
272
  emits: ["update:modelValue"],
249
273
  setup(o) {
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, {
274
+ const t = z(o, "modelValue"), { i18n: e } = ve(), n = G("editorRef"), a = M(() => o.theme === "dark" ? "dark" : "light"), i = M(() => s.editorStates.editorStatus === "ready" && !s.editorStates.hasContent), s = he(n, {
251
275
  language: o.language,
252
276
  code: t,
253
- theme: r.value,
277
+ theme: a.value,
254
278
  monacoOptions: o.options,
255
- onChanged: (u) => {
256
- t.value = u;
279
+ onChanged: (g) => {
280
+ t.value = g;
257
281
  }
258
282
  });
259
- return (u, l) => (y(), q("div", {
283
+ return (g, l) => (y(), q("div", {
260
284
  class: J(["monaco-editor-container", [
261
- r.value,
262
- { loading: c(s).editorStates.editorStatus === "loading" }
285
+ a.value,
286
+ { loading: u(s).editorStates.editorStatus === "loading" }
263
287
  ]]),
264
288
  "data-testid": "monaco-editor-container"
265
289
  }, [
@@ -269,31 +293,31 @@ const he = /* @__PURE__ */ N({
269
293
  class: "monaco-editor-target",
270
294
  "data-testid": "monaco-editor-target"
271
295
  }, null, 512),
272
- I(u.$slots, "state-loading", {
273
- isLoading: c(s).editorStates.editorStatus === "loading"
296
+ T(g.$slots, "state-loading", {
297
+ isLoading: u(s).editorStates.editorStatus === "loading"
274
298
  }, () => [
275
- T(k, { name: "fade" }, {
276
- default: E(() => [
277
- c(s).editorStates.editorStatus === "loading" ? (y(), S(W, {
299
+ I(k, { name: "fade" }, {
300
+ default: b(() => [
301
+ u(s).editorStates.editorStatus === "loading" ? (y(), _(F, {
278
302
  key: 0,
279
303
  "data-testid": "monaco-editor-status-overlay-loading",
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 })
304
+ icon: u(Y),
305
+ message: u(e).t("editor.messages.loading_message", { type: o.language }),
306
+ title: u(e).t("editor.messages.loading_title", { type: o.language })
283
307
  }, null, 8, ["icon", "message", "title"])) : w("", !0)
284
308
  ]),
285
309
  _: 1
286
310
  })
287
311
  ], !0),
288
- I(u.$slots, "state-empty", { isEmpty: i.value }, () => [
289
- T(k, { name: "fade" }, {
290
- default: E(() => [
291
- i.value ? (y(), S(W, {
312
+ T(g.$slots, "state-empty", { isEmpty: i.value }, () => [
313
+ I(k, { name: "fade" }, {
314
+ default: b(() => [
315
+ i.value ? (y(), _(F, {
292
316
  key: 0,
293
317
  "data-testid": "monaco-editor-status-overlay-empty",
294
- icon: c(Z),
295
- message: c(e).t("editor.messages.empty_message"),
296
- title: c(e).t("editor.messages.empty_title")
318
+ icon: u(Z),
319
+ message: u(e).t("editor.messages.empty_message"),
320
+ title: u(e).t("editor.messages.empty_title")
297
321
  }, null, 8, ["icon", "message", "title"])) : w("", !0)
298
322
  ]),
299
323
  _: 1
@@ -301,8 +325,8 @@ const he = /* @__PURE__ */ N({
301
325
  ], !0)
302
326
  ], 2));
303
327
  }
304
- }), Se = /* @__PURE__ */ R(ye, [["__scopeId", "data-v-c8f35a88"]]);
328
+ }), Te = /* @__PURE__ */ N(Se, [["__scopeId", "data-v-c8f35a88"]]);
305
329
  export {
306
- Se as MonacoEditor,
307
- ue as useMonacoEditor
330
+ Te as MonacoEditor,
331
+ he as useMonacoEditor
308
332
  };
@@ -1 +1 @@
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"})});
1
+ (function(s,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):(s=typeof globalThis<"u"?globalThis:s||self,e(s["kong-ui-public-monaco-editor"]={},s.Vue,s.KongIcons,s.monaco,s.monaco$1,s.shiki,s["kong-ui-public-i18n"]))})(this,function(s,e,O,N,x,S,b){"use strict";function B(n){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(o,t,a.get?a:{enumerable:!0,get:()=>n[t]})}}return o.default=n,Object.freeze(o)}const f=B(N),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 k=()=>{};function L(n,o){function t(...a){return new Promise((r,c)=>{Promise.resolve(n(()=>o.apply(this,a),{fn:o,thisArg:this,args:a})).then(r).catch(c)})}return t}function U(n,o={}){let t,a,r=k;const c=d=>{clearTimeout(d),r(),r=k};let l;return d=>{const _=e.toValue(n),u=e.toValue(o.maxWait);return t&&c(t),_<=0||u!==void 0&&u<=0?(a&&(c(a),a=void 0),Promise.resolve(d())):new Promise((C,i)=>{r=o.rejectOnCancel?i:C,l=d,u&&!a&&(a=setTimeout(()=>{t&&c(t),a=void 0,C(l())},u)),t=setTimeout(()=>{a&&c(a),a=void 0,C(d())},_)})}}function V(n,o=200,t={}){return L(U(o,t),n)}function W(n){var o;const t=e.toValue(n);return(o=t==null?void 0:t.$el)!==null&&o!==void 0?o:t}const E=e.ref(!1);let h=null;async function D(){return h||(h=(async()=>{var n,o;try{const t=((n=f.json)==null?void 0:n.jsonDefaults)||((o=f.languages.json)==null?void 0:o.jsonDefaults);t==null||t.setModeConfiguration({tokens:!1});const a=await S.getSingletonHighlighter({themes:Object.values(S.bundledThemes),langs:Object.values(S.bundledLanguages)});a.getLoadedLanguages().forEach(r=>{f.languages.register({id:r})}),x.shikiToMonaco(a,f),E.value=!0}catch(t){throw h=null,t}})(),h)}function I(n,o){let t,a=!1;const r=e.reactive({editorStatus:"loading",searchBoxIsRevealed:!1,hasContent:!1,theme:o.theme||"light"}),c=i=>{!a||!t||t.setValue(i)},l=i=>t==null?void 0:t.updateOptions({readOnly:i}),g=()=>t==null?void 0:t.focus(),d=i=>{try{if(!t||!i)return;t.focus(),t.trigger("keyboard",i,null)}catch(p){console.error(`useMonacoEditor: Failed to trigger command: ${i}`,p)}},_=()=>{var i;try{if(!t)return;if(r.searchBoxIsRevealed)return(i=t.getContribution("editor.contrib.findController"))==null?void 0:i.closeFindWidget();d("actions.find")}catch(p){console.error("useMonacoEditor: Failed to close findController.",p)}},u=V(()=>f.editor.remeasureFonts(),200);return(()=>{D();let i;e.watch([E,()=>e.toValue(n)],([p,q])=>{var F;const w=W(q);if(!(w instanceof HTMLElement)||!p){a=!1;return}if(!a){if(!i){const m=f.Uri.parse(`inmemory://model/${o.language}-${crypto.randomUUID()}`);i=f.editor.createModel(o.code.value,o.language,m)}t=f.editor.create(w,{...j,readOnly:o.readOnly||!1,language:o.language,theme:r.theme==="light"?"catppuccin-latte":"catppuccin-mocha",model:i,editContext:!1,...o.monacoOptions}),a=!0,r.editorStatus="ready",r.hasContent=!!o.code.value,t.onDidChangeModelContent(()=>{var y;const m=t.getValue();r.hasContent=!!m.length,(y=o.onChanged)==null||y.call(o,m)}),(F=o.onCreated)==null||F.call(o),u();try{const m=t.getContribution("editor.contrib.findController");if(m){const y=m.getState();y.onFindReplaceStateChange(()=>{r.searchBoxIsRevealed=y.isRevealed})}}catch(m){console.error("useMonacoEditor: Failed to get the state of findController",m)}}},{immediate:!0,flush:"post"})})(),e.onMounted(u),e.onActivated(u),e.onBeforeUnmount(()=>{if(!t)return;const i=t.getModel();t.dispose(),i&&i.dispose()}),{editor:t,editorStates:r,setContent:c,setReadOnly:l,focus:g,remeasureFonts:u,toggleSearchWidget:_,triggerKeyboardCommand:d}}const P={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 R(){const n=b.createI18n("en-us",P);return{i18n:n,i18nT:b.i18nTComponent(n)}}const K=e.defineComponent({__name:"MonacoEditorStatusOverlay",props:{title:{},message:{},icon:{}},setup(n){return(o,t)=>{const a=e.resolveComponent("KEmptyState");return e.openBlock(),e.createBlock(a,{class:"monaco-editor-status-overlay",message:n.message,title:n.title},e.createSlots({_:2},[n.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.icon),{decorative:""}))]),key:"0"}:void 0]),1032,["message","title"])}}}),T=(n,o)=>{const t=n.__vccOpts||n;for(const[a,r]of o)t[a]=r;return t},M=T(K,[["__scopeId","data-v-062eadb5"]]),H=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(n){const o=e.useModel(n,"modelValue"),{i18n:t}=R(),a=e.useTemplateRef("editorRef"),r=e.computed(()=>n.theme==="dark"?"dark":"light"),c=e.computed(()=>l.editorStates.editorStatus==="ready"&&!l.editorStates.hasContent),l=I(a,{language:n.language,code:o,theme:r.value,monacoOptions:n.options,onChanged:g=>{o.value=g}});return(g,d)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["monaco-editor-container",[r.value,{loading:e.unref(l).editorStates.editorStatus==="loading"}]]),"data-testid":"monaco-editor-container"},[e.createElementVNode("div",{ref_key:"editorRef",ref:a,class:"monaco-editor-target","data-testid":"monaco-editor-target"},null,512),e.renderSlot(g.$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(M,{key:0,"data-testid":"monaco-editor-status-overlay-loading",icon:e.unref(O.ProgressIcon),message:e.unref(t).t("editor.messages.loading_message",{type:n.language}),title:e.unref(t).t("editor.messages.loading_title",{type:n.language})},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0),e.renderSlot(g.$slots,"state-empty",{isEmpty:c.value},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[c.value?(e.openBlock(),e.createBlock(M,{key:0,"data-testid":"monaco-editor-status-overlay-empty",icon:e.unref(O.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=H,s.useMonacoEditor=I,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
@@ -1 +1 @@
1
- {"version":3,"file":"MonacoEditor.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/MonacoEditor.vue"],"names":[],"mappings":"AAkTA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE5C,KAAK,WAAW,GAAG;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;MAGE;IACF,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,oCAAoC,CAAC,GAAG,SAAS,CAAA;CAC3E,CAAC;AAQF;;GAEG;AACH,QAAA,MAAM,KAAK,wDAGT,CAAA;AAyBF,KAAK,gBAAgB,GAAG;IACxB;;OAEG;IACH,UAAU,EAAE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;CACjC,CAAC;AAKF,KAAK,iBAAiB,GAAG,WAAW,GAAG,gBAAgB,CAAC;AA8IxD,QAAA,IAAI,OAAO;;CAAU,EAAE,QAAQ;;CAAY,CAAE;AAC7C,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,GACpD;IAAE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG,CAAA;CAAE,CAAC;AAOtD,QAAA,MAAM,UAAU;;;;kFAGd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"MonacoEditor.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/MonacoEditor.vue"],"names":[],"mappings":"AAmTA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE5C,KAAK,WAAW,GAAG;IACjB;;;OAGG;IACH,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;MAGE;IACF,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,oCAAoC,CAAC,GAAG,SAAS,CAAA;CAC3E,CAAC;AAQF;;GAEG;AACH,QAAA,MAAM,KAAK,wDAGT,CAAA;AAyBF,KAAK,gBAAgB,GAAG;IACxB;;OAEG;IACH,UAAU,EAAE,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC;CACjC,CAAC;AAKF,KAAK,iBAAiB,GAAG,WAAW,GAAG,gBAAgB,CAAC;AA+IxD,QAAA,IAAI,OAAO;;CAAU,EAAE,QAAQ;;CAAY,CAAE;AAC7C,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,OAAO,KAAK,GAAG,CAAA;CAAE,GACpD;IAAE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG,CAAA;CAAE,CAAC;AAOtD,QAAA,MAAM,UAAU;;;;kFAGd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"MonacoEditorStatusOverlay.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/MonacoEditorStatusOverlay.vue"],"names":[],"mappings":"AAkEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,KAAK,WAAW,GAAG;IACjB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,CAAC;AA6DF,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
1
+ {"version":3,"file":"MonacoEditorStatusOverlay.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/MonacoEditorStatusOverlay.vue"],"names":[],"mappings":"AAmEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AAEpC,KAAK,WAAW,GAAG;IACjB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,CAAC;AA8DF,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -18,7 +18,7 @@ export declare function useMonacoEditor<T extends MaybeElement>(target: MaybeCom
18
18
  setContent: (content: string) => void;
19
19
  setReadOnly: (readOnly: boolean) => void;
20
20
  focus: () => void;
21
- remeasureFonts: import("@vueuse/core").UseDebounceFnReturn<() => void | undefined>;
21
+ remeasureFonts: import("@vueuse/core").UseDebounceFnReturn<() => void>;
22
22
  toggleSearchWidget: () => void;
23
23
  triggerKeyboardCommand: (id: string) => void;
24
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useMonacoEditor.d.ts","sourceRoot":"","sources":["../../../../src/composables/useMonacoEditor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC,OAAO,KAAK,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,KAAK,EAAsB,sBAAsB,EAAE,MAAM,UAAU,CAAA;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"}
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;AAwC1E;;;;;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;EAwIlD"}
@@ -1,5 +1,6 @@
1
1
  import type { Plugin } from 'vite';
2
2
  import type { EditorFeature, EditorLanguage, NegatedEditorFeature, IFeatureDefinition } from 'monaco-editor/esm/metadata.js';
3
+ import type { BundledLanguage, BundledTheme } from 'shiki';
3
4
  type Options = {
4
5
  /**
5
6
  * Include only a subset of the languages supported.
@@ -50,7 +51,37 @@ type Options = {
50
51
  * ```
51
52
  */
52
53
  features?: Array<EditorFeature | NegatedEditorFeature>;
54
+ /**
55
+ * Shiki configuration options.
56
+ * @type {{ themes?: BundledTheme[]; langs?: BundledLanguage[] }}
57
+ */
58
+ shiki?: {
59
+ /**
60
+ * Languages to include for Shiki syntax highlighting.
61
+ *
62
+ * @type {BundledLanguage[]}
63
+ * @defaultValue The same languages specified in the`languages` option above
64
+ * @example
65
+ * ```ts
66
+ * // Only include JavaScript and JSON support
67
+ * langs: ['javascript', 'json']
68
+ * ```
69
+ */
70
+ langs?: BundledLanguage[];
71
+ /**
72
+ * Themes to include for Shiki syntax highlighting.
73
+ *
74
+ * @type {BundledTheme[]}
75
+ * @defaultValue ['catppuccin-latte', 'catppuccin-mocha']
76
+ * @example
77
+ * ```ts
78
+ * // Include the 'nord' theme
79
+ * themes: ['nord']
80
+ * ```
81
+ */
82
+ themes?: BundledTheme[];
83
+ };
53
84
  };
54
- export default function (options?: Options): Plugin;
85
+ export default function plugin(options?: Options): Plugin;
55
86
  export {};
56
87
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../vite-plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,+BAA+B,CAAA;AAGtC,KAAK,OAAO,GAAG;IACb;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,cAAc,EAAE,CAAA;IAE5B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,eAAe,CAAC,EAAE,kBAAkB,EAAE,CAAA;IAEtC;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,GAAG,oBAAoB,CAAC,CAAA;CACvD,CAAA;AAsGD,MAAM,CAAC,OAAO,WAAU,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAqEjD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../vite-plugin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAM1D,KAAK,OAAO,GAAG;IACb;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,cAAc,EAAE,CAAA;IAE5B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,eAAe,CAAC,EAAE,kBAAkB,EAAE,CAAA;IAEtC;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,GAAG,oBAAoB,CAAC,CAAA;IAEtD;;;KAGC;IACD,KAAK,CAAC,EAAE;QACN;;;;;;;;;;UAUE;QACF,KAAK,CAAC,EAAE,eAAe,EAAE,CAAA;QAEzB;;;;;;;;;;WAUG;QACH,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;KACxB,CAAA;CACF,CAAA;AA+GD,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAkFxD"}
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  const metadata_js = require("monaco-editor/esm/metadata.js");
3
+ const shikiCodegen = require("shiki-codegen");
4
+ const shiki = require("shiki");
3
5
  const WORKER_ALIASES = {
4
6
  javascript: "typescript",
5
7
  less: "css",
@@ -7,10 +9,17 @@ const WORKER_ALIASES = {
7
9
  handlebars: "html",
8
10
  razor: "html"
9
11
  };
10
- const VIRTUAL_MODULE_ID = "\0virtual:monaco-editor";
12
+ const VIRTUAL_MODULE_MONACO_ID = "\0virtual:monaco-editor";
13
+ const VIRTUAL_MODULE_SHIKI_ID = "\0virtual:shiki";
11
14
  function generateImports(entries) {
12
15
  const entryArray = Array.isArray(entries) ? entries : [entries];
13
- return entryArray.map((entry) => `import 'monaco-editor/esm/${entry}'`);
16
+ return entryArray.map((entry) => {
17
+ if (entry.endsWith("monaco.contribution")) {
18
+ const lang = entry.split("/").at(-2);
19
+ return `export * as ${lang} from 'monaco-editor/esm/${entry}'`;
20
+ }
21
+ return `import 'monaco-editor/esm/${entry}'`;
22
+ });
14
23
  }
15
24
  function resolveFeatures(requestedFeatures, allFeatureIds) {
16
25
  if (!requestedFeatures) {
@@ -66,62 +75,72 @@ function generateWorkerCode(languageIds, languagesDict, customLanguages) {
66
75
  "}"
67
76
  ];
68
77
  }
69
- function index(options) {
78
+ function plugin(options) {
70
79
  return {
71
80
  name: "vite-plugin-monaco",
72
81
  enforce: "pre",
73
82
  resolveId(id) {
74
83
  if (id === "monaco-editor") {
75
- return VIRTUAL_MODULE_ID;
84
+ return VIRTUAL_MODULE_MONACO_ID;
85
+ } else if (id === "shiki") {
86
+ return VIRTUAL_MODULE_SHIKI_ID;
76
87
  }
77
88
  },
78
89
  load(id) {
79
- if (id !== VIRTUAL_MODULE_ID) {
80
- return;
90
+ var _a, _b;
91
+ if (id === VIRTUAL_MODULE_MONACO_ID) {
92
+ const languagesDict = Object.fromEntries(
93
+ metadata_js.languages.map((lang) => [lang.label, lang])
94
+ );
95
+ const featuresDict = Object.fromEntries(
96
+ metadata_js.features.map((feat) => [feat.label, feat])
97
+ );
98
+ const featuresIds = resolveFeatures(
99
+ options == null ? void 0 : options.features,
100
+ Object.keys(featuresDict)
101
+ );
102
+ const featureImports = featuresIds.flatMap((featureId) => {
103
+ const feature = featuresDict[featureId];
104
+ if (!(feature == null ? void 0 : feature.entry)) {
105
+ return [];
106
+ }
107
+ return generateImports(feature.entry);
108
+ });
109
+ const languageIds = (options == null ? void 0 : options.languages) || Object.keys(languagesDict);
110
+ const languageImports = languageIds.flatMap((langId) => {
111
+ const lang = languagesDict[langId];
112
+ if (!(lang == null ? void 0 : lang.entry)) {
113
+ return [];
114
+ }
115
+ return generateImports(lang.entry);
116
+ });
117
+ const customLanguageImports = ((options == null ? void 0 : options.customLanguages) || []).map(
118
+ ({ entry }) => `import '${entry}'`
119
+ );
120
+ const workerCode = generateWorkerCode(
121
+ languageIds,
122
+ languagesDict,
123
+ options == null ? void 0 : options.customLanguages
124
+ );
125
+ return [
126
+ "import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'",
127
+ ...featureImports,
128
+ ...languageImports,
129
+ ...customLanguageImports,
130
+ ...workerCode,
131
+ "export * from 'monaco-editor/esm/vs/editor/editor.api'",
132
+ "export default monaco"
133
+ ].join("\n");
134
+ } else if (id === VIRTUAL_MODULE_SHIKI_ID) {
135
+ const languageIds = ((_a = options == null ? void 0 : options.shiki) == null ? void 0 : _a.langs) || ((options == null ? void 0 : options.languages) || metadata_js.languages.map((lang) => lang.label)).filter((lang) => lang in shiki.bundledLanguages);
136
+ return shikiCodegen.codegen({
137
+ themes: ((_b = options == null ? void 0 : options.shiki) == null ? void 0 : _b.themes) || ["catppuccin-latte", "catppuccin-mocha"],
138
+ engine: "javascript",
139
+ langs: languageIds,
140
+ typescript: false
141
+ });
81
142
  }
82
- const languagesDict = Object.fromEntries(
83
- metadata_js.languages.map((lang) => [lang.label, lang])
84
- );
85
- const featuresDict = Object.fromEntries(
86
- metadata_js.features.map((feat) => [feat.label, feat])
87
- );
88
- const featuresIds = resolveFeatures(
89
- options == null ? void 0 : options.features,
90
- Object.keys(featuresDict)
91
- );
92
- const featureImports = featuresIds.flatMap((featureId) => {
93
- const feature = featuresDict[featureId];
94
- if (!(feature == null ? void 0 : feature.entry)) {
95
- return [];
96
- }
97
- return generateImports(feature.entry);
98
- });
99
- const languageIds = (options == null ? void 0 : options.languages) || Object.keys(languagesDict);
100
- const languageImports = languageIds.flatMap((langId) => {
101
- const lang = languagesDict[langId];
102
- if (!(lang == null ? void 0 : lang.entry)) {
103
- return [];
104
- }
105
- return generateImports(lang.entry);
106
- });
107
- const customLanguageImports = ((options == null ? void 0 : options.customLanguages) || []).map(
108
- ({ entry }) => `import '${entry}'`
109
- );
110
- const workerCode = generateWorkerCode(
111
- languageIds,
112
- languagesDict,
113
- options == null ? void 0 : options.customLanguages
114
- );
115
- return [
116
- "import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'",
117
- ...featureImports,
118
- ...languageImports,
119
- ...customLanguageImports,
120
- ...workerCode,
121
- "export * from 'monaco-editor/esm/vs/editor/editor.api'",
122
- "export default monaco"
123
- ].join("\n");
124
143
  }
125
144
  };
126
145
  }
127
- module.exports = index;
146
+ module.exports = plugin;
@@ -1,4 +1,6 @@
1
1
  import { languages, features } from "monaco-editor/esm/metadata.js";
2
+ import { codegen } from "shiki-codegen";
3
+ import { bundledLanguages } from "shiki";
2
4
  const WORKER_ALIASES = {
3
5
  javascript: "typescript",
4
6
  less: "css",
@@ -6,10 +8,17 @@ const WORKER_ALIASES = {
6
8
  handlebars: "html",
7
9
  razor: "html"
8
10
  };
9
- const VIRTUAL_MODULE_ID = "\0virtual:monaco-editor";
11
+ const VIRTUAL_MODULE_MONACO_ID = "\0virtual:monaco-editor";
12
+ const VIRTUAL_MODULE_SHIKI_ID = "\0virtual:shiki";
10
13
  function generateImports(entries) {
11
14
  const entryArray = Array.isArray(entries) ? entries : [entries];
12
- return entryArray.map((entry) => `import 'monaco-editor/esm/${entry}'`);
15
+ return entryArray.map((entry) => {
16
+ if (entry.endsWith("monaco.contribution")) {
17
+ const lang = entry.split("/").at(-2);
18
+ return `export * as ${lang} from 'monaco-editor/esm/${entry}'`;
19
+ }
20
+ return `import 'monaco-editor/esm/${entry}'`;
21
+ });
13
22
  }
14
23
  function resolveFeatures(requestedFeatures, allFeatureIds) {
15
24
  if (!requestedFeatures) {
@@ -65,64 +74,74 @@ function generateWorkerCode(languageIds, languagesDict, customLanguages) {
65
74
  "}"
66
75
  ];
67
76
  }
68
- function index(options) {
77
+ function plugin(options) {
69
78
  return {
70
79
  name: "vite-plugin-monaco",
71
80
  enforce: "pre",
72
81
  resolveId(id) {
73
82
  if (id === "monaco-editor") {
74
- return VIRTUAL_MODULE_ID;
83
+ return VIRTUAL_MODULE_MONACO_ID;
84
+ } else if (id === "shiki") {
85
+ return VIRTUAL_MODULE_SHIKI_ID;
75
86
  }
76
87
  },
77
88
  load(id) {
78
- if (id !== VIRTUAL_MODULE_ID) {
79
- return;
89
+ var _a, _b;
90
+ if (id === VIRTUAL_MODULE_MONACO_ID) {
91
+ const languagesDict = Object.fromEntries(
92
+ languages.map((lang) => [lang.label, lang])
93
+ );
94
+ const featuresDict = Object.fromEntries(
95
+ features.map((feat) => [feat.label, feat])
96
+ );
97
+ const featuresIds = resolveFeatures(
98
+ options == null ? void 0 : options.features,
99
+ Object.keys(featuresDict)
100
+ );
101
+ const featureImports = featuresIds.flatMap((featureId) => {
102
+ const feature = featuresDict[featureId];
103
+ if (!(feature == null ? void 0 : feature.entry)) {
104
+ return [];
105
+ }
106
+ return generateImports(feature.entry);
107
+ });
108
+ const languageIds = (options == null ? void 0 : options.languages) || Object.keys(languagesDict);
109
+ const languageImports = languageIds.flatMap((langId) => {
110
+ const lang = languagesDict[langId];
111
+ if (!(lang == null ? void 0 : lang.entry)) {
112
+ return [];
113
+ }
114
+ return generateImports(lang.entry);
115
+ });
116
+ const customLanguageImports = ((options == null ? void 0 : options.customLanguages) || []).map(
117
+ ({ entry }) => `import '${entry}'`
118
+ );
119
+ const workerCode = generateWorkerCode(
120
+ languageIds,
121
+ languagesDict,
122
+ options == null ? void 0 : options.customLanguages
123
+ );
124
+ return [
125
+ "import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'",
126
+ ...featureImports,
127
+ ...languageImports,
128
+ ...customLanguageImports,
129
+ ...workerCode,
130
+ "export * from 'monaco-editor/esm/vs/editor/editor.api'",
131
+ "export default monaco"
132
+ ].join("\n");
133
+ } else if (id === VIRTUAL_MODULE_SHIKI_ID) {
134
+ const languageIds = ((_a = options == null ? void 0 : options.shiki) == null ? void 0 : _a.langs) || ((options == null ? void 0 : options.languages) || languages.map((lang) => lang.label)).filter((lang) => lang in bundledLanguages);
135
+ return codegen({
136
+ themes: ((_b = options == null ? void 0 : options.shiki) == null ? void 0 : _b.themes) || ["catppuccin-latte", "catppuccin-mocha"],
137
+ engine: "javascript",
138
+ langs: languageIds,
139
+ typescript: false
140
+ });
80
141
  }
81
- const languagesDict = Object.fromEntries(
82
- languages.map((lang) => [lang.label, lang])
83
- );
84
- const featuresDict = Object.fromEntries(
85
- features.map((feat) => [feat.label, feat])
86
- );
87
- const featuresIds = resolveFeatures(
88
- options == null ? void 0 : options.features,
89
- Object.keys(featuresDict)
90
- );
91
- const featureImports = featuresIds.flatMap((featureId) => {
92
- const feature = featuresDict[featureId];
93
- if (!(feature == null ? void 0 : feature.entry)) {
94
- return [];
95
- }
96
- return generateImports(feature.entry);
97
- });
98
- const languageIds = (options == null ? void 0 : options.languages) || Object.keys(languagesDict);
99
- const languageImports = languageIds.flatMap((langId) => {
100
- const lang = languagesDict[langId];
101
- if (!(lang == null ? void 0 : lang.entry)) {
102
- return [];
103
- }
104
- return generateImports(lang.entry);
105
- });
106
- const customLanguageImports = ((options == null ? void 0 : options.customLanguages) || []).map(
107
- ({ entry }) => `import '${entry}'`
108
- );
109
- const workerCode = generateWorkerCode(
110
- languageIds,
111
- languagesDict,
112
- options == null ? void 0 : options.customLanguages
113
- );
114
- return [
115
- "import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'",
116
- ...featureImports,
117
- ...languageImports,
118
- ...customLanguageImports,
119
- ...workerCode,
120
- "export * from 'monaco-editor/esm/vs/editor/editor.api'",
121
- "export default monaco"
122
- ].join("\n");
123
142
  }
124
143
  };
125
144
  }
126
145
  export {
127
- index as default
146
+ plugin as default
128
147
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kong-ui-public/monaco-editor",
3
- "version": "0.4.11",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "main": "./dist/runtime/monaco-editor.umd.js",
6
6
  "module": "./dist/runtime/monaco-editor.es.js",
@@ -46,7 +46,8 @@
46
46
  "peerDependencies": {
47
47
  "@kong/icons": "^1.41.0",
48
48
  "@kong/kongponents": ">=9.42.0 <10.0.0",
49
- "monaco-editor": ">=0.55.0 <1.0.0",
49
+ "monaco-editor": ">=0.52.0 <1.0.0",
50
+ "shiki": ">=3.0.0 <4.0.0",
50
51
  "vue": "^3.5.26",
51
52
  "@kong-ui-public/i18n": "^2.4.5"
52
53
  },
@@ -55,11 +56,14 @@
55
56
  "@kong/icons": "^1.41.0",
56
57
  "@kong/kongponents": "9.48.8",
57
58
  "monaco-editor": "^0.55.1",
59
+ "shiki": "^3.20.0",
58
60
  "vue": "^3.5.26",
59
61
  "@kong-ui-public/i18n": "^2.4.5"
60
62
  },
61
63
  "dependencies": {
62
- "@vueuse/core": "^14.1.0"
64
+ "@shikijs/monaco": "^3.20.0",
65
+ "@vueuse/core": "^14.1.0",
66
+ "shiki-codegen": "^3.20.0"
63
67
  },
64
68
  "scripts": {
65
69
  "dev": "cross-env USE_SANDBOX=true vite",