UNPKG

vue-files-preview-inno

Version:

A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.

140 lines (139 loc) 6.23 kB
import { defineComponent as T, shallowRef as y, inject as B, computed as z, toRaw as E, onMounted as P, watch as d, onBeforeUnmount as V, h as W } from "vue"; import { basicSetup as R } from "../../codemirror/dist/index.mjs"; import { EditorState as g, Compartment as A, StateEffect as I } from "../../@codemirror/state/dist/index.mjs"; import { EditorView as h, keymap as M, placeholder as k } from "../../@codemirror/view/dist/index.mjs"; import { indentWithTab as L } from "../../@codemirror/commands/dist/index.mjs"; import { indentUnit as N } from "../../@codemirror/language/dist/index.mjs"; /*! * VueCodemirror v6.1.1 * Copyright (c) Surmon. All rights reserved. * Released under the MIT License. * Surmon */ var G = Object.freeze({ autofocus: !1, disabled: !1, indentWithTab: !0, tabSize: 2, placeholder: "", autoDestroy: !0, extensions: [R] }), _ = Symbol("vue-codemirror-global-config"), u, $ = function(t) { var r = t.onUpdate, c = t.onChange, m = t.onFocus, f = t.onBlur, s = function(n, l) { var o = {}; for (var e in n) Object.prototype.hasOwnProperty.call(n, e) && l.indexOf(e) < 0 && (o[e] = n[e]); if (n != null && typeof Object.getOwnPropertySymbols == "function") { var i = 0; for (e = Object.getOwnPropertySymbols(n); i < e.length; i++) l.indexOf(e[i]) < 0 && Object.prototype.propertyIsEnumerable.call(n, e[i]) && (o[e[i]] = n[e[i]]); } return o; }(t, ["onUpdate", "onChange", "onFocus", "onBlur"]); return g.create({ doc: s.doc, selection: s.selection, extensions: (Array.isArray(s.extensions) ? s.extensions : [s.extensions]).concat([h.updateListener.of(function(n) { r(n), n.docChanged && c(n.state.doc.toString(), n), n.focusChanged && (n.view.hasFocus ? m(n) : f(n)); })]) }); }, v = function(t) { var r = new A(); return { compartment: r, run: function(c) { r.get(t.state) ? t.dispatch({ effects: r.reconfigure(c) }) : t.dispatch({ effects: I.appendConfig.of(r.of(c)) }); } }; }, O = function(t, r) { var c = v(t), m = c.compartment, f = c.run; return function(s) { var n = m.get(t.state); f(s ?? n !== r ? r : []); }; }, b = { type: Boolean, default: void 0 }, q = { autofocus: b, disabled: b, indentWithTab: b, tabSize: Number, placeholder: String, style: Object, autoDestroy: b, phrases: Object, root: Object, extensions: Array, selection: Object }, H = { modelValue: { type: String, default: "" } }, J = Object.assign(Object.assign({}, q), H); (function(t) { t.Change = "change", t.Update = "update", t.Focus = "focus", t.Blur = "blur", t.Ready = "ready", t.ModelUpdate = "update:modelValue"; })(u || (u = {})); var p = {}; p[u.Change] = function(t, r) { return !0; }, p[u.Update] = function(t) { return !0; }, p[u.Focus] = function(t) { return !0; }, p[u.Blur] = function(t) { return !0; }, p[u.Ready] = function(t) { return !0; }; var j = {}; j[u.ModelUpdate] = p[u.Change]; var K = Object.assign(Object.assign({}, p), j), Q = T({ name: "VueCodemirror", props: Object.assign({}, J), emits: Object.assign({}, K), setup: function(t, r) { var c = y(), m = y(), f = y(), s = Object.assign(Object.assign({}, G), B(_, {})), n = z(function() { var l = {}; return Object.keys(E(t)).forEach(function(o) { var e; o !== "modelValue" && (l[o] = (e = t[o]) !== null && e !== void 0 ? e : s[o]); }), l; }); return P(function() { var l; m.value = $({ doc: t.modelValue, selection: n.value.selection, extensions: (l = s.extensions) !== null && l !== void 0 ? l : [], onFocus: function(e) { return r.emit(u.Focus, e); }, onBlur: function(e) { return r.emit(u.Blur, e); }, onUpdate: function(e) { return r.emit(u.Update, e); }, onChange: function(e, i) { e !== t.modelValue && (r.emit(u.Change, e, i), r.emit(u.ModelUpdate, e, i)); } }), f.value = function(e) { return new h(Object.assign({}, e)); }({ state: m.value, parent: c.value, root: n.value.root }); var o = function(e) { var i = function() { return e.state.doc.toString(); }, S = v(e).run, C = O(e, [h.editable.of(!1), g.readOnly.of(!0)]), x = O(e, M.of([L])), U = v(e).run, w = v(e).run, D = v(e).run, F = v(e).run; return { focus: function() { return e.focus(); }, getDoc: i, setDoc: function(a) { a !== i() && e.dispatch({ changes: { from: 0, to: e.state.doc.length, insert: a } }); }, reExtensions: S, toggleDisabled: C, toggleIndentWithTab: x, setTabSize: function(a) { U([g.tabSize.of(a), N.of(" ".repeat(a))]); }, setPhrases: function(a) { w([g.phrases.of(a)]); }, setPlaceholder: function(a) { D(k(a)); }, setStyle: function(a) { a === void 0 && (a = {}), F(h.theme({ "&": Object.assign({}, a) })); } }; }(f.value); d(function() { return t.modelValue; }, function(e) { e !== o.getDoc() && o.setDoc(e); }), d(function() { return t.extensions; }, function(e) { return o.reExtensions(e || []); }, { immediate: !0 }), d(function() { return n.value.disabled; }, function(e) { return o.toggleDisabled(e); }, { immediate: !0 }), d(function() { return n.value.indentWithTab; }, function(e) { return o.toggleIndentWithTab(e); }, { immediate: !0 }), d(function() { return n.value.tabSize; }, function(e) { return o.setTabSize(e); }, { immediate: !0 }), d(function() { return n.value.phrases; }, function(e) { return o.setPhrases(e || {}); }, { immediate: !0 }), d(function() { return n.value.placeholder; }, function(e) { return o.setPlaceholder(e); }, { immediate: !0 }), d(function() { return n.value.style; }, function(e) { return o.setStyle(e); }, { immediate: !0 }), n.value.autofocus && o.focus(), r.emit(u.Ready, { state: m.value, view: f.value, container: c.value }); }), V(function() { n.value.autoDestroy && f.value && function(l) { l.destroy(); }(f.value); }), function() { return W("div", { class: "v-codemirror", style: { display: "contents" }, ref: c }); }; } }), oe = Q; export { oe as Codemirror, G as DEFAULT_CONFIG }; //# sourceMappingURL=vue-codemirror.esm.mjs.map