@bagelink/vue 1.6.2 → 1.6.4

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.
package/dist/index.mjs CHANGED
@@ -7163,7 +7163,7 @@ var _hoisted_1$52 = {
7163
7163
  default: !1
7164
7164
  },
7165
7165
  modelValue: {
7166
- type: String,
7166
+ type: [String, Object],
7167
7167
  default: ""
7168
7168
  },
7169
7169
  autodetect: {
@@ -7193,48 +7193,64 @@ var _hoisted_1$52 = {
7193
7193
  },
7194
7194
  emits: ["update:modelValue"],
7195
7195
  setup(e, { emit: t }) {
7196
- let j = e, M = t, N = ref(j.modelValue || ""), V = ref(), { loaded: U, loadHighlight: J, highlightCode: WE, setTheme: GE } = useHighlight(j.theme), KE = computed(() => {
7197
- let e = j.height ?? "240px";
7196
+ let j = e, M = t, N = computed(() => typeof j.modelValue == "object");
7197
+ function V(e) {
7198
+ return typeof e == "string" ? e : typeof e == "object" ? JSON.stringify(e, null, 2) : "";
7199
+ }
7200
+ let U = ref(V(j.modelValue)), J = ref(), { loaded: WE, loadHighlight: GE, highlightCode: KE, setTheme: qE } = useHighlight(j.theme), JE = computed(() => {
7201
+ let e = j.height;
7198
7202
  return e.match(/^\d+$/) ? `${e}px` : e;
7199
- }), qE = computed(() => WE(N.value, j.language, j.autodetect, j.ignoreIllegals));
7200
- function JE(e) {
7201
- N.value = e.target.value, M("update:modelValue", N.value);
7203
+ }), YE = computed(() => KE(U.value, j.language, j.autodetect, j.ignoreIllegals));
7204
+ function XE(e) {
7205
+ if (U.value = e.target.value, N.value) try {
7206
+ M("update:modelValue", JSON.parse(U.value));
7207
+ } catch {
7208
+ M("update:modelValue", U.value);
7209
+ }
7210
+ else M("update:modelValue", U.value);
7202
7211
  }
7203
- function YE(e) {
7204
- if (e.key !== "Tab") return;
7212
+ function ZE(e) {
7213
+ if (e.key === "Tab") return;
7205
7214
  e.preventDefault();
7206
7215
  let t = e.target, j = t.selectionStart, I = t.selectionEnd;
7207
- N.value = `${N.value.substring(0, j)} ${N.value.substring(I)}`, M("update:modelValue", N.value), setTimeout(() => {
7208
- t.selectionStart = t.selectionEnd = j + 2;
7216
+ if (U.value = `${U.value.substring(0, j)} ${U.value.substring(I)}`, N.value) try {
7217
+ M("update:modelValue", JSON.parse(U.value));
7218
+ } catch {
7219
+ M("update:modelValue", U.value);
7220
+ }
7221
+ else M("update:modelValue", U.value);
7222
+ setTimeout(() => {
7223
+ t.selectionStart = j + 2, t.selectionEnd = j + 2;
7209
7224
  }, 0);
7210
7225
  }
7211
7226
  return onMounted(async () => {
7212
- await J();
7227
+ await GE();
7213
7228
  }), watch(() => j.theme, (e) => {
7214
- GE(e);
7229
+ qE(e);
7215
7230
  }), watch(() => j.modelValue, (e) => {
7216
- e !== void 0 && e !== N.value && (N.value = e);
7231
+ let t = V(e);
7232
+ t !== U.value && (U.value = t);
7217
7233
  }, { immediate: !0 }), (t, j) => (openBlock(), createElementBlock("div", {
7218
7234
  class: "code-editor-container ltr",
7219
- style: normalizeStyle({ maxHeight: KE.value })
7220
- }, [e.label ? (openBlock(), createElementBlock("label", _hoisted_1$52, toDisplayString(e.label), 1)) : createCommentVNode("", !0), unref(U) ? (openBlock(), createElementBlock("div", {
7235
+ style: normalizeStyle({ maxHeight: JE.value })
7236
+ }, [e.label ? (openBlock(), createElementBlock("label", _hoisted_1$52, toDisplayString(e.label), 1)) : createCommentVNode("", !0), unref(WE) ? (openBlock(), createElementBlock("div", {
7221
7237
  key: 1,
7222
7238
  ref_key: "editorRef",
7223
- ref: V,
7239
+ ref: J,
7224
7240
  class: "code-editor-grandpa hljs"
7225
- }, [createElementVNode("div", _hoisted_2$38, [createElementVNode("pre", _hoisted_3$30, [createElementVNode("code", { innerHTML: qE.value }, null, 8, _hoisted_4$20)]), !e.readonly && !e.disabled ? (openBlock(), createElementBlock("textarea", {
7241
+ }, [createElementVNode("div", _hoisted_2$38, [createElementVNode("pre", _hoisted_3$30, [createElementVNode("code", { innerHTML: YE.value }, null, 8, _hoisted_4$20)]), !e.readonly && !e.disabled ? (openBlock(), createElementBlock("textarea", {
7226
7242
  key: 0,
7227
- value: N.value,
7243
+ value: U.value,
7228
7244
  class: "code-input",
7229
7245
  spellcheck: "false",
7230
7246
  autocomplete: "off",
7231
7247
  autocorrect: "off",
7232
7248
  autocapitalize: "off",
7233
- onInput: JE,
7234
- onKeydown: YE
7249
+ onInput: XE,
7250
+ onKeydown: ZE
7235
7251
  }, null, 40, _hoisted_5$20)) : createCommentVNode("", !0)])], 512)) : createCommentVNode("", !0)], 4));
7236
7252
  }
7237
- }), [["__scopeId", "data-v-da15f4be"]]), _hoisted_1$51 = ["title"], _hoisted_2$37 = [
7253
+ }), [["__scopeId", "data-v-6d314069"]]), _hoisted_1$51 = ["title"], _hoisted_2$37 = [
7238
7254
  "id",
7239
7255
  "placeholder",
7240
7256
  "required"