@kong-ui-public/monaco-editor 0.9.0 → 0.9.1

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.
@@ -3,8 +3,8 @@ import { ProgressIcon as oe, CodeblockIcon as ae } from "@kong/icons";
3
3
  import * as g from "monaco-editor";
4
4
  import { shikiToMonaco as ne } from "@shikijs/monaco";
5
5
  import { getSingletonHighlighter as re, bundledLanguages as se, bundledThemes as ie } from "shiki";
6
- import { createI18n as le, i18nTComponent as ce } from "@kong-ui-public/i18n";
7
- const ue = "'JetBrains Mono', Consolas, monospace", de = "12px", me = "500", ge = "20px", fe = Object.freeze({
6
+ import { createI18n as le, i18nTComponent as ue } from "@kong-ui-public/i18n";
7
+ const ce = "'JetBrains Mono', Consolas, monospace", de = "12px", me = "500", ge = "20px", fe = Object.freeze({
8
8
  autoClosingQuotes: "always",
9
9
  automaticLayout: !0,
10
10
  // Auto resize layout
@@ -13,7 +13,7 @@ const ue = "'JetBrains Mono', Consolas, monospace", de = "12px", me = "500", ge
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: ue,
16
+ fontFamily: ce,
17
17
  fontSize: Number(de.replace("px", "")),
18
18
  fontWeight: me,
19
19
  lineHeight: Number(ge.replace("px", "")),
@@ -94,7 +94,7 @@ function ve(t, o = {}) {
94
94
  function ye(t, o = 200, e = {}) {
95
95
  return he(ve(o, e), t);
96
96
  }
97
- const D = j(!1);
97
+ const V = j(!1);
98
98
  let p = null;
99
99
  async function pe() {
100
100
  return p || (p = (async () => {
@@ -110,7 +110,7 @@ async function pe() {
110
110
  );
111
111
  a.getLoadedLanguages().forEach((r) => {
112
112
  g.languages.register({ id: r });
113
- }), ne(a, g), D.value = !0;
113
+ }), ne(a, g), V.value = !0;
114
114
  } catch (e) {
115
115
  throw p = null, e;
116
116
  }
@@ -127,21 +127,21 @@ function Se(t, o) {
127
127
  }), y = (n) => {
128
128
  !r || !e.value || e.value.setValue(n);
129
129
  }, d = (n) => {
130
- var c;
131
- return (c = e.value) == null ? void 0 : c.updateOptions({ readOnly: n });
130
+ var u;
131
+ return (u = e.value) == null ? void 0 : u.updateOptions({ readOnly: n });
132
132
  }, f = () => {
133
133
  var n;
134
134
  return (n = e.value) == null ? void 0 : n.focus();
135
135
  }, m = (n) => {
136
136
  var E;
137
- const c = (E = e.value) == null ? void 0 : E.getModel();
138
- c && g.editor.setModelLanguage(c, n);
137
+ const u = (E = e.value) == null ? void 0 : E.getModel();
138
+ u && g.editor.setModelLanguage(u, n);
139
139
  }, l = (n) => {
140
140
  try {
141
141
  if (!e.value || !n) return;
142
142
  e.value.focus(), e.value.trigger("keyboard", n, null);
143
- } catch (c) {
144
- console.error(`useMonacoEditor: Failed to trigger command: ${n}`, c);
143
+ } catch (u) {
144
+ console.error(`useMonacoEditor: Failed to trigger command: ${n}`, u);
145
145
  }
146
146
  }, h = () => {
147
147
  var n;
@@ -150,22 +150,24 @@ function Se(t, o) {
150
150
  if (i.searchBoxIsRevealed)
151
151
  return (n = e.value.getContribution("editor.contrib.findController")) == null ? void 0 : n.closeFindWidget();
152
152
  l("actions.find");
153
- } catch (c) {
154
- console.error("useMonacoEditor: Failed to close findController.", c);
153
+ } catch (u) {
154
+ console.error("useMonacoEditor: Failed to close findController.", u);
155
155
  }
156
156
  }, b = /* @__PURE__ */ ye(() => g.editor.remeasureFonts(), 200);
157
157
  return (() => {
158
- pe(), k([D, () => S(t)], ([n, c], [, E]) => {
158
+ pe(), k([V, () => S(t)], ([n, u], [, E]) => {
159
159
  var w;
160
- const _ = S(c), V = S(E);
160
+ const _ = S(u), P = S(E);
161
161
  if (!(_ instanceof HTMLElement) || !n) {
162
162
  r = !1;
163
163
  return;
164
164
  }
165
- if (!(r && V === _)) {
166
- if (!a) {
167
- const u = g.Uri.parse(`inmemory://model/${o.language}-${crypto.randomUUID()}`);
168
- a = g.editor.createModel(o.code.value, o.language, u);
165
+ if (!(r && P === _)) {
166
+ if (a)
167
+ a.setValue(o.code.value);
168
+ else {
169
+ const c = g.Uri.parse(`inmemory://model/${o.language}-${crypto.randomUUID()}`);
170
+ a = g.editor.createModel(o.code.value, o.language, c);
169
171
  }
170
172
  e.value = g.editor.create(_, {
171
173
  ...fe,
@@ -177,20 +179,20 @@ function Se(t, o) {
177
179
  ...o.monacoOptions
178
180
  }), r = !0, i.editorStatus = "ready", i.hasContent = !!o.code.value, e.value.onDidChangeModelContent(() => {
179
181
  if (s) return;
180
- const u = e.value.getValue();
181
- i.hasContent = !!u.length, o.code.value = u;
182
+ const c = e.value.getValue();
183
+ i.hasContent = !!c.length, o.code.value = c;
182
184
  }), (w = o.onReady) == null || w.call(o, e.value), b();
183
185
  try {
184
- const u = e.value.getContribution("editor.contrib.findController"), M = u == null ? void 0 : u.getState();
186
+ const c = e.value.getContribution("editor.contrib.findController"), M = c == null ? void 0 : c.getState();
185
187
  M == null || M.onFindReplaceStateChange(() => {
186
188
  i.searchBoxIsRevealed = M.isRevealed;
187
189
  });
188
- } catch (u) {
189
- console.error("useMonacoEditor: Failed to get the state of findController", u);
190
+ } catch (c) {
191
+ console.error("useMonacoEditor: Failed to get the state of findController", c);
190
192
  }
191
193
  $(() => {
192
- var u;
193
- (u = e.value) == null || u.dispose();
194
+ var c;
195
+ (c = e.value) == null || c.dispose();
194
196
  });
195
197
  }
196
198
  }, {
@@ -199,8 +201,8 @@ function Se(t, o) {
199
201
  });
200
202
  })(), k(o.code, (n) => {
201
203
  if (!e.value || !a || !r) return;
202
- const c = a.getValue();
203
- n !== c && (s = !0, e.value.executeEdits("external", [
204
+ const u = a.getValue();
205
+ n !== u && (s = !0, e.value.executeEdits("external", [
204
206
  {
205
207
  range: a.getFullModelRange(),
206
208
  text: n
@@ -236,7 +238,7 @@ function Ee() {
236
238
  const t = le("en-us", be);
237
239
  return {
238
240
  i18n: t,
239
- i18nT: ce(t)
241
+ i18nT: ue(t)
240
242
  // Translation component <i18n-t>
241
243
  };
242
244
  }
@@ -265,12 +267,12 @@ const Me = /* @__PURE__ */ U({
265
267
  ]), 1032, ["message", "title"]);
266
268
  };
267
269
  }
268
- }), P = (t, o) => {
270
+ }), D = (t, o) => {
269
271
  const e = t.__vccOpts || t;
270
272
  for (const [a, r] of o)
271
273
  e[a] = r;
272
274
  return e;
273
- }, N = /* @__PURE__ */ P(Me, [["__scopeId", "data-v-062eadb5"]]), Oe = /* @__PURE__ */ U({
275
+ }, N = /* @__PURE__ */ D(Me, [["__scopeId", "data-v-062eadb5"]]), Oe = /* @__PURE__ */ U({
274
276
  __name: "MonacoEditor",
275
277
  props: /* @__PURE__ */ L({
276
278
  theme: { default: "light" },
@@ -351,7 +353,7 @@ const Me = /* @__PURE__ */ U({
351
353
  ], !0) : O("", !0)
352
354
  ], 2));
353
355
  }
354
- }), Le = /* @__PURE__ */ P(Oe, [["__scopeId", "data-v-89d4c84e"]]);
356
+ }), Le = /* @__PURE__ */ D(Oe, [["__scopeId", "data-v-89d4c84e"]]);
355
357
  export {
356
358
  Le as MonacoEditor,
357
359
  Se as useMonacoEditor
@@ -1 +1 @@
1
- (function(d,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@kong/icons"),require("monaco-editor"),require("@shikijs/monaco"),require("shiki"),require("@kong-ui-public/i18n")):typeof define=="function"&&define.amd?define(["exports","vue","@kong/icons","monaco-editor","@shikijs/monaco","shiki","@kong-ui-public/i18n"],e):(d=typeof globalThis<"u"?globalThis:d||self,e(d["kong-ui-public-monaco-editor"]={},d.Vue,d.KongIcons,d.monaco,d.monaco$1,d.shiki,d["kong-ui-public-i18n"]))})(this,function(d,e,O,L,V,E,I){"use strict";function R(o){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(n,t,a.get?a:{enumerable:!0,get:()=>o[t]})}}return n.default=o,Object.freeze(n)}const h=R(L),U=Object.freeze({autoClosingQuotes:"always",automaticLayout:!0,bracketPairColorization:{enabled:!0},hideCursorInOverviewRuler:!0,fontFamily:"'JetBrains Mono', Consolas, monospace",fontSize:Number("12px".replace("px","")),fontWeight:"500",lineHeight:Number("20px".replace("px","")),formatOnPaste:!0,formatOnType:!0,lineNumbersMinChars:3,minimap:{enabled:!1},stickyScroll:{enabled:!0},suggest:{showWords:!1},quickSuggestions:!0,suggestOnTriggerCharacters:!0,wordBasedSuggestions:"off",overviewRulerLanes:0,renderWhitespace:"boundary",scrollBeyondLastLine:!1,roundedSelection:!1,wordWrapColumn:120,colorDecorators:!0,folding:!0,fixedOverflowWidgets:!0,tabSize:2,detectIndentation:!1,insertSpaces:!0,trimAutoWhitespace:!0,wordWrap:"bounded",find:{addExtraSpaceOnTop:!1}});typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const T=()=>{};function j(o,n){function t(...a){return new Promise((i,s)=>{Promise.resolve(o(()=>n.apply(this,a),{fn:n,thisArg:this,args:a})).then(i).catch(s)})}return t}function W(o,n={}){let t,a,i=T;const s=g=>{clearTimeout(g),i(),i=T};let l;return g=>{const p=e.toValue(o),f=e.toValue(n.maxWait);return t&&s(t),p<=0||f!==void 0&&f<=0?(a&&(s(a),a=void 0),Promise.resolve(g())):new Promise((c,y)=>{i=n.rejectOnCancel?y:c,l=g,f&&!a&&(a=setTimeout(()=>{t&&s(t),a=void 0,c(l())},f)),t=setTimeout(()=>{a&&s(a),a=void 0,c(g())},p)})}}function v(o,n=200,t={}){return j(W(n,t),o)}const w=e.ref(!1);let S=null;async function D(){return S||(S=(async()=>{var o,n;try{const t=((o=h.json)==null?void 0:o.jsonDefaults)||((n=h.languages.json)==null?void 0:n.jsonDefaults);t==null||t.setModeConfiguration({tokens:!1});const a=await E.getSingletonHighlighter({themes:Object.values(E.bundledThemes),langs:Object.values(E.bundledLanguages)});a.getLoadedLanguages().forEach(i=>{h.languages.register({id:i})}),V.shikiToMonaco(a,h),w.value=!0}catch(t){throw S=null,t}})(),S)}function x(o,n){const t=e.shallowRef();let a,i=!1,s=!1;const l=e.reactive({editorStatus:"loading",searchBoxIsRevealed:!1,hasContent:!1,theme:n.theme||"light"}),C=r=>{!i||!t.value||t.value.setValue(r)},g=r=>{var u;return(u=t.value)==null?void 0:u.updateOptions({readOnly:r})},p=()=>{var r;return(r=t.value)==null?void 0:r.focus()},f=r=>{var b;const u=(b=t.value)==null?void 0:b.getModel();u&&h.editor.setModelLanguage(u,r)},c=r=>{try{if(!t.value||!r)return;t.value.focus(),t.value.trigger("keyboard",r,null)}catch(u){console.error(`useMonacoEditor: Failed to trigger command: ${r}`,u)}},y=()=>{var r;try{if(!t.value)return;if(l.searchBoxIsRevealed)return(r=t.value.getContribution("editor.contrib.findController"))==null?void 0:r.closeFindWidget();c("actions.find")}catch(u){console.error("useMonacoEditor: Failed to close findController.",u)}},_=v(()=>h.editor.remeasureFonts(),200);return(()=>{D(),e.watch([w,()=>e.toValue(o)],([r,u],[,b])=>{var B;const M=e.toValue(u),A=e.toValue(b);if(!(M instanceof HTMLElement)||!r){i=!1;return}if(!(i&&A===M)){if(!a){const m=h.Uri.parse(`inmemory://model/${n.language}-${crypto.randomUUID()}`);a=h.editor.createModel(n.code.value,n.language,m)}t.value=h.editor.create(M,{...U,readOnly:n.readOnly||!1,language:n.language,theme:l.theme==="light"?"catppuccin-latte":"catppuccin-mocha",model:a,editContext:!1,...n.monacoOptions}),i=!0,l.editorStatus="ready",l.hasContent=!!n.code.value,t.value.onDidChangeModelContent(()=>{if(s)return;const m=t.value.getValue();l.hasContent=!!m.length,n.code.value=m}),(B=n.onReady)==null||B.call(n,t.value),_();try{const m=t.value.getContribution("editor.contrib.findController"),k=m==null?void 0:m.getState();k==null||k.onFindReplaceStateChange(()=>{l.searchBoxIsRevealed=k.isRevealed})}catch(m){console.error("useMonacoEditor: Failed to get the state of findController",m)}e.onWatcherCleanup(()=>{var m;(m=t.value)==null||m.dispose()})}},{immediate:!0,flush:"post"})})(),e.watch(n.code,r=>{if(!t.value||!a||!i)return;const u=a.getValue();r!==u&&(s=!0,t.value.executeEdits("external",[{range:a.getFullModelRange(),text:r}]),t.value.pushUndoStop(),l.hasContent=!!r.length,s=!1)}),e.onMounted(_),e.onActivated(_),e.onBeforeUnmount(()=>{if(!t.value)return;const r=t.value.getModel();t.value.dispose(),r&&r.dispose()}),{editor:t,editorStates:l,setContent:C,setReadOnly:g,focus:p,setLanguage:f,remeasureFonts:_,toggleSearchWidget:y,triggerKeyboardCommand:c}}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 K(){const o=I.createI18n("en-us",P);return{i18n:o,i18nT:I.i18nTComponent(o)}}const H=e.defineComponent({__name:"MonacoEditorStatusOverlay",props:{title:{},message:{},icon:{}},setup(o){return(n,t)=>{const a=e.resolveComponent("KEmptyState");return e.openBlock(),e.createBlock(a,{class:"monaco-editor-status-overlay",message:o.message,title:o.title},e.createSlots({_:2},[o.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.icon),{decorative:""}))]),key:"0"}:void 0]),1032,["message","title"])}}}),N=(o,n)=>{const t=o.__vccOpts||o;for(const[a,i]of n)t[a]=i;return t},F=N(H,[["__scopeId","data-v-062eadb5"]]),q=N(e.defineComponent({__name:"MonacoEditor",props:e.mergeModels({theme:{default:"light"},language:{default:"markdown"},loading:{type:Boolean,default:!1},options:{default:()=>{}},showLoadingState:{type:Boolean,default:!0},showEmptyState:{type:Boolean,default:!0}},{modelValue:{type:String,required:!0},modelModifiers:{}}),emits:e.mergeModels(["ready"],["update:modelValue"]),setup(o,{expose:n,emit:t}){const a=t,i=e.useModel(o,"modelValue"),{i18n:s}=K(),l=e.useTemplateRef("editorRef"),C=e.computed(()=>o.theme==="dark"?"dark":"light"),g=e.computed(()=>o.loading||f.editorStates.editorStatus==="loading"),p=e.computed(()=>!g.value&&f.editorStates.editorStatus==="ready"&&!f.editorStates.hasContent),f=x(l,{language:o.language,code:i,theme:C.value,monacoOptions:o.options,onReady:c=>{a("ready",c)}});return n({monacoEditor:f}),e.watch(()=>o.language,(c,y)=>{c!==y&&f.setLanguage(c)}),(c,y)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["monaco-editor-container",[C.value,{loading:g.value}]]),"data-testid":"monaco-editor-container"},[e.createElementVNode("div",{ref_key:"editorRef",ref:l,class:"monaco-editor-target","data-testid":"monaco-editor-target"},null,512),o.showLoadingState?e.renderSlot(c.$slots,"state-loading",{key:0,isLoading:g.value},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[g.value?(e.openBlock(),e.createBlock(F,{key:0,"data-testid":"monaco-editor-status-overlay-loading",icon:e.unref(O.ProgressIcon),message:e.unref(s).t("editor.messages.loading_message",{type:o.language}),title:e.unref(s).t("editor.messages.loading_title",{type:o.language})},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0):e.createCommentVNode("",!0),o.showEmptyState?e.renderSlot(c.$slots,"state-empty",{key:1,isEmpty:p.value},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[p.value?(e.openBlock(),e.createBlock(F,{key:0,"data-testid":"monaco-editor-status-overlay-empty",icon:e.unref(O.CodeblockIcon),message:e.unref(s).t("editor.messages.empty_message"),title:e.unref(s).t("editor.messages.empty_title")},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0):e.createCommentVNode("",!0)],2))}}),[["__scopeId","data-v-89d4c84e"]]);d.MonacoEditor=q,d.useMonacoEditor=x,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
1
+ (function(d,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@kong/icons"),require("monaco-editor"),require("@shikijs/monaco"),require("shiki"),require("@kong-ui-public/i18n")):typeof define=="function"&&define.amd?define(["exports","vue","@kong/icons","monaco-editor","@shikijs/monaco","shiki","@kong-ui-public/i18n"],e):(d=typeof globalThis<"u"?globalThis:d||self,e(d["kong-ui-public-monaco-editor"]={},d.Vue,d.KongIcons,d.monaco,d.monaco$1,d.shiki,d["kong-ui-public-i18n"]))})(this,function(d,e,O,L,V,E,I){"use strict";function R(o){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(n,t,a.get?a:{enumerable:!0,get:()=>o[t]})}}return n.default=o,Object.freeze(n)}const h=R(L),U=Object.freeze({autoClosingQuotes:"always",automaticLayout:!0,bracketPairColorization:{enabled:!0},hideCursorInOverviewRuler:!0,fontFamily:"'JetBrains Mono', Consolas, monospace",fontSize:Number("12px".replace("px","")),fontWeight:"500",lineHeight:Number("20px".replace("px","")),formatOnPaste:!0,formatOnType:!0,lineNumbersMinChars:3,minimap:{enabled:!1},stickyScroll:{enabled:!0},suggest:{showWords:!1},quickSuggestions:!0,suggestOnTriggerCharacters:!0,wordBasedSuggestions:"off",overviewRulerLanes:0,renderWhitespace:"boundary",scrollBeyondLastLine:!1,roundedSelection:!1,wordWrapColumn:120,colorDecorators:!0,folding:!0,fixedOverflowWidgets:!0,tabSize:2,detectIndentation:!1,insertSpaces:!0,trimAutoWhitespace:!0,wordWrap:"bounded",find:{addExtraSpaceOnTop:!1}});typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const T=()=>{};function j(o,n){function t(...a){return new Promise((i,s)=>{Promise.resolve(o(()=>n.apply(this,a),{fn:n,thisArg:this,args:a})).then(i).catch(s)})}return t}function v(o,n={}){let t,a,i=T;const s=g=>{clearTimeout(g),i(),i=T};let l;return g=>{const p=e.toValue(o),f=e.toValue(n.maxWait);return t&&s(t),p<=0||f!==void 0&&f<=0?(a&&(s(a),a=void 0),Promise.resolve(g())):new Promise((c,y)=>{i=n.rejectOnCancel?y:c,l=g,f&&!a&&(a=setTimeout(()=>{t&&s(t),a=void 0,c(l())},f)),t=setTimeout(()=>{a&&s(a),a=void 0,c(g())},p)})}}function W(o,n=200,t={}){return j(v(n,t),o)}const w=e.ref(!1);let S=null;async function D(){return S||(S=(async()=>{var o,n;try{const t=((o=h.json)==null?void 0:o.jsonDefaults)||((n=h.languages.json)==null?void 0:n.jsonDefaults);t==null||t.setModeConfiguration({tokens:!1});const a=await E.getSingletonHighlighter({themes:Object.values(E.bundledThemes),langs:Object.values(E.bundledLanguages)});a.getLoadedLanguages().forEach(i=>{h.languages.register({id:i})}),V.shikiToMonaco(a,h),w.value=!0}catch(t){throw S=null,t}})(),S)}function x(o,n){const t=e.shallowRef();let a,i=!1,s=!1;const l=e.reactive({editorStatus:"loading",searchBoxIsRevealed:!1,hasContent:!1,theme:n.theme||"light"}),C=r=>{!i||!t.value||t.value.setValue(r)},g=r=>{var u;return(u=t.value)==null?void 0:u.updateOptions({readOnly:r})},p=()=>{var r;return(r=t.value)==null?void 0:r.focus()},f=r=>{var b;const u=(b=t.value)==null?void 0:b.getModel();u&&h.editor.setModelLanguage(u,r)},c=r=>{try{if(!t.value||!r)return;t.value.focus(),t.value.trigger("keyboard",r,null)}catch(u){console.error(`useMonacoEditor: Failed to trigger command: ${r}`,u)}},y=()=>{var r;try{if(!t.value)return;if(l.searchBoxIsRevealed)return(r=t.value.getContribution("editor.contrib.findController"))==null?void 0:r.closeFindWidget();c("actions.find")}catch(u){console.error("useMonacoEditor: Failed to close findController.",u)}},_=W(()=>h.editor.remeasureFonts(),200);return(()=>{D(),e.watch([w,()=>e.toValue(o)],([r,u],[,b])=>{var B;const M=e.toValue(u),A=e.toValue(b);if(!(M instanceof HTMLElement)||!r){i=!1;return}if(!(i&&A===M)){if(a)a.setValue(n.code.value);else{const m=h.Uri.parse(`inmemory://model/${n.language}-${crypto.randomUUID()}`);a=h.editor.createModel(n.code.value,n.language,m)}t.value=h.editor.create(M,{...U,readOnly:n.readOnly||!1,language:n.language,theme:l.theme==="light"?"catppuccin-latte":"catppuccin-mocha",model:a,editContext:!1,...n.monacoOptions}),i=!0,l.editorStatus="ready",l.hasContent=!!n.code.value,t.value.onDidChangeModelContent(()=>{if(s)return;const m=t.value.getValue();l.hasContent=!!m.length,n.code.value=m}),(B=n.onReady)==null||B.call(n,t.value),_();try{const m=t.value.getContribution("editor.contrib.findController"),k=m==null?void 0:m.getState();k==null||k.onFindReplaceStateChange(()=>{l.searchBoxIsRevealed=k.isRevealed})}catch(m){console.error("useMonacoEditor: Failed to get the state of findController",m)}e.onWatcherCleanup(()=>{var m;(m=t.value)==null||m.dispose()})}},{immediate:!0,flush:"post"})})(),e.watch(n.code,r=>{if(!t.value||!a||!i)return;const u=a.getValue();r!==u&&(s=!0,t.value.executeEdits("external",[{range:a.getFullModelRange(),text:r}]),t.value.pushUndoStop(),l.hasContent=!!r.length,s=!1)}),e.onMounted(_),e.onActivated(_),e.onBeforeUnmount(()=>{if(!t.value)return;const r=t.value.getModel();t.value.dispose(),r&&r.dispose()}),{editor:t,editorStates:l,setContent:C,setReadOnly:g,focus:p,setLanguage:f,remeasureFonts:_,toggleSearchWidget:y,triggerKeyboardCommand:c}}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 K(){const o=I.createI18n("en-us",P);return{i18n:o,i18nT:I.i18nTComponent(o)}}const H=e.defineComponent({__name:"MonacoEditorStatusOverlay",props:{title:{},message:{},icon:{}},setup(o){return(n,t)=>{const a=e.resolveComponent("KEmptyState");return e.openBlock(),e.createBlock(a,{class:"monaco-editor-status-overlay",message:o.message,title:o.title},e.createSlots({_:2},[o.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.icon),{decorative:""}))]),key:"0"}:void 0]),1032,["message","title"])}}}),N=(o,n)=>{const t=o.__vccOpts||o;for(const[a,i]of n)t[a]=i;return t},F=N(H,[["__scopeId","data-v-062eadb5"]]),q=N(e.defineComponent({__name:"MonacoEditor",props:e.mergeModels({theme:{default:"light"},language:{default:"markdown"},loading:{type:Boolean,default:!1},options:{default:()=>{}},showLoadingState:{type:Boolean,default:!0},showEmptyState:{type:Boolean,default:!0}},{modelValue:{type:String,required:!0},modelModifiers:{}}),emits:e.mergeModels(["ready"],["update:modelValue"]),setup(o,{expose:n,emit:t}){const a=t,i=e.useModel(o,"modelValue"),{i18n:s}=K(),l=e.useTemplateRef("editorRef"),C=e.computed(()=>o.theme==="dark"?"dark":"light"),g=e.computed(()=>o.loading||f.editorStates.editorStatus==="loading"),p=e.computed(()=>!g.value&&f.editorStates.editorStatus==="ready"&&!f.editorStates.hasContent),f=x(l,{language:o.language,code:i,theme:C.value,monacoOptions:o.options,onReady:c=>{a("ready",c)}});return n({monacoEditor:f}),e.watch(()=>o.language,(c,y)=>{c!==y&&f.setLanguage(c)}),(c,y)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["monaco-editor-container",[C.value,{loading:g.value}]]),"data-testid":"monaco-editor-container"},[e.createElementVNode("div",{ref_key:"editorRef",ref:l,class:"monaco-editor-target","data-testid":"monaco-editor-target"},null,512),o.showLoadingState?e.renderSlot(c.$slots,"state-loading",{key:0,isLoading:g.value},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[g.value?(e.openBlock(),e.createBlock(F,{key:0,"data-testid":"monaco-editor-status-overlay-loading",icon:e.unref(O.ProgressIcon),message:e.unref(s).t("editor.messages.loading_message",{type:o.language}),title:e.unref(s).t("editor.messages.loading_title",{type:o.language})},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0):e.createCommentVNode("",!0),o.showEmptyState?e.renderSlot(c.$slots,"state-empty",{key:1,isEmpty:p.value},()=>[e.createVNode(e.Transition,{name:"fade"},{default:e.withCtx(()=>[p.value?(e.openBlock(),e.createBlock(F,{key:0,"data-testid":"monaco-editor-status-overlay-empty",icon:e.unref(O.CodeblockIcon),message:e.unref(s).t("editor.messages.empty_message"),title:e.unref(s).t("editor.messages.empty_title")},null,8,["icon","message","title"])):e.createCommentVNode("",!0)]),_:1})],!0):e.createCommentVNode("",!0)],2))}}),[["__scopeId","data-v-89d4c84e"]]);d.MonacoEditor=q,d.useMonacoEditor=x,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
@@ -1 +1 @@
1
- {"version":3,"file":"useMonacoEditor.d.ts","sourceRoot":"","sources":["../../../../src/composables/useMonacoEditor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC,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;EAwKlD"}
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,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;EA0KlD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kong-ui-public/monaco-editor",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
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",