@web-utils/component 4.0.10 → 4.0.11

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,327 +0,0 @@
1
- import * as d from "monaco-editor/esm/vs/editor/editor.api";
2
- import { NOOP as _ } from "@web-utils/core";
3
- import { n as x } from "./_plugin-vue2_normalizer.CeySl7Fu.mjs";
4
- const y = /[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, w = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
5
- let u, g;
6
- const j = {
7
- // table of character substitutions
8
- "\b": "\\b",
9
- " ": "\\t",
10
- "\n": "\\n",
11
- "\f": "\\f",
12
- "\r": "\\r",
13
- '"': '\\"',
14
- "'": "\\'",
15
- "\\": "\\\\"
16
- };
17
- let c;
18
- function M(t, e = {}) {
19
- const i = e.space || 2, n = e.dropQuotesOnKeys !== !1, o = e.dropQuotesOnNumbers || !1, r = e.inlineShortArrays || !1, a = e.inlineShortArraysDepth || 1, f = e.quoteType || "single", h = e.minify || !1;
20
- o && v(t);
21
- let l = O(t, null, h ? void 0 : i, n, f);
22
- if (r && !h) {
23
- let s = $(l);
24
- if (a > 1)
25
- for (let b = 1; b < a && (l = s, s = $(l), s !== l); b++)
26
- ;
27
- l = s;
28
- }
29
- return l;
30
- }
31
- function v(t) {
32
- if (!E(t)) return;
33
- const e = Object.keys(t);
34
- e && e.forEach(function(i) {
35
- const n = t[i];
36
- if (typeof n == "string") {
37
- const o = n - 0;
38
- t[i] = isNaN(o) ? n : o;
39
- } else (E(n) || Array.isArray(n)) && v(n);
40
- });
41
- }
42
- function E(t) {
43
- return t && typeof t == "object";
44
- }
45
- function $(t, e) {
46
- if (e || (e = 80), typeof e != "number" || e < 20)
47
- throw Error(`Invalid width '${e}'. Expecting number equal or larger than 20.`);
48
- const i = t.split(`
49
- `);
50
- let n = 0, o = null, r = [];
51
- for (; n < i.length; ) {
52
- const a = !!i[n].match(/\[/), f = !!i[n].match(/\],?/);
53
- if (a && !f)
54
- r = [i[n]], o = n;
55
- else if (f && !a && o) {
56
- r.push((i[n] || "").trim());
57
- const h = r.join(" ");
58
- h.length < e && (i.splice(o, n - o + 1, h), n = o), o = null, r = [];
59
- } else
60
- o && r.push((i[n] || "").trim());
61
- n += 1;
62
- }
63
- return i.join(`
64
- `);
65
- }
66
- function O(t, e, i, n, o) {
67
- let r;
68
- if (u = "", g = "", typeof i == "number")
69
- for (r = 0; r < i; r += 1)
70
- g += " ";
71
- else typeof i == "string" && (g = i);
72
- return c = e, m("", { "": t }, n, o);
73
- }
74
- function m(t, e, i, n) {
75
- let o, r, a, f;
76
- const h = u;
77
- let l, s = e[t];
78
- switch (s && typeof s == "object" && typeof s.toJSON == "function" && (s = s.toJSON(t)), typeof c == "function" && (s = c.call(e, t, s)), typeof s) {
79
- case "function":
80
- return s;
81
- case "string":
82
- return p(s, n);
83
- case "number":
84
- return isFinite(s) ? String(s) : "null";
85
- case "boolean":
86
- case "null":
87
- return String(s);
88
- // If the type is 'object', we might be dealing with an object or an array or
89
- // null.
90
- case "object":
91
- if (!s)
92
- return "null";
93
- if (u += g, l = [], Object.prototype.toString.apply(s) === "[object Array]") {
94
- for (f = s.length, o = 0; o < f; o += 1)
95
- l[o] = m(o, s, i, n) || "null";
96
- return a = l.length === 0 ? "[]" : u ? `[
97
- ${u}${l.join(`,
98
- ${u}`)}
99
- ${h}]` : `[${l.join(",")}]`, u = h, a;
100
- }
101
- if (c && typeof c == "object")
102
- for (f = c.length, o = 0; o < f; o += 1)
103
- typeof c[o] == "string" && (r = c[o], a = m(r, s, i, n), a && l.push((i ? S(r, n) : p(r, n)) + (u ? ": " : ":") + a));
104
- else
105
- for (r in s)
106
- Object.prototype.hasOwnProperty.call(s, r) && (a = m(r, s, i, n), a && l.push((i ? S(r, n) : p(r, n)) + (u ? ": " : ":") + a));
107
- return a = l.length === 0 ? "{}" : u ? `{
108
- ${u}${l.join(`,
109
- ${u}`)}
110
- ${h}}` : `{${l.join(",")}}`, u = h, a;
111
- }
112
- }
113
- function p(t, e) {
114
- y.lastIndex = 0;
115
- let i = '"';
116
- return e === "single" && (i = "'"), y.test(t) ? i + t.replace(y, function(n) {
117
- const o = j[n];
118
- return typeof o == "string" ? o : `\\u${`0000${n.charCodeAt(0).toString(16)}`.slice(-4)}`;
119
- }) + i : i + t + i;
120
- }
121
- function S(t, e) {
122
- return w.test(t) ? t : p(t, e);
123
- }
124
- const A = {
125
- name: "MonacoEditor",
126
- props: {
127
- diffEditor: { type: Boolean, default: !1 },
128
- // 是否使用 diff 模式
129
- width: { type: [String, Number], default: "100%" },
130
- height: { type: [String, Number], default: "100%" },
131
- original: String,
132
- // 只有在 diff 模式下有效
133
- value: [String, Object],
134
- language: { type: String, default: "javascript" },
135
- theme: { type: String, default: "vs" },
136
- readOnly: { type: Boolean, default: !1 },
137
- options: {
138
- type: Object,
139
- default() {
140
- return {};
141
- }
142
- },
143
- editorMounted: { type: Function, default: _ },
144
- editorBeforeMount: { type: Function, default: _ },
145
- keyIndex: { type: String }
146
- },
147
- data() {
148
- return {
149
- fullscreen: !1
150
- };
151
- },
152
- computed: {
153
- style() {
154
- return this.fullscreen ? {} : {
155
- width: /^\d+$/.test(this.width) ? `${this.width}px` : this.width,
156
- height: /^\d+$/.test(this.height) ? `${this.height}px` : this.height,
157
- position: "relative"
158
- };
159
- }
160
- },
161
- watch: {
162
- options: {
163
- deep: !0,
164
- handler(t) {
165
- var e;
166
- (e = this.editor) == null || e.updateOptions(t);
167
- }
168
- },
169
- keyIndex() {
170
- let t = this.value;
171
- typeof t == "object" && (t = M(t)), this.editor && t !== this._getValue() && this._setValue(t);
172
- },
173
- language() {
174
- if (this.editor)
175
- if (this.diffEditor) {
176
- const { original: t, modified: e } = this.editor.getModel();
177
- d.editor.setModelLanguage(t, this.language), d.editor.setModelLanguage(e, this.language);
178
- } else
179
- d.editor.setModelLanguage(this.editor.getModel(), this.language);
180
- },
181
- theme() {
182
- this.editor && d.editor.setTheme(this.theme);
183
- },
184
- style() {
185
- this.$nextTick(() => {
186
- var t;
187
- (t = this.editor) == null || t.layout();
188
- });
189
- },
190
- value(t) {
191
- this.editor && t !== this._getValue() && this._setValue(t);
192
- }
193
- },
194
- mounted() {
195
- this.initMonaco(), window.addEventListener("resize", this.onResize);
196
- },
197
- beforeDestroy() {
198
- var t;
199
- window.removeEventListener("resize", this.onResize), (t = this.editor) == null || t.dispose();
200
- },
201
- methods: {
202
- initMonaco() {
203
- const { value: t, language: e, theme: i, readOnly: n, options: o } = this;
204
- Object.assign(o, this._editorBeforeMount()), this.editor = d.editor[this.diffEditor ? "createDiffEditor" : "create"](this.$el, {
205
- value: typeof t == "string" ? t : M(t),
206
- language: e,
207
- theme: i,
208
- readOnly: n,
209
- ...o
210
- }), this.diffEditor && this._setModel(this.value, this.original), this._editorMounted(this.editor), this.editor.addAction({
211
- id: "f1",
212
- label: "full screen",
213
- keybindings: [d.KeyCode.F1],
214
- run: (r) => {
215
- this.toggleFullScreen();
216
- }
217
- }), this.editor.addAction({
218
- id: "escape",
219
- label: "exit full screen",
220
- keybindings: [d.KeyCode.Escape],
221
- run: (r) => {
222
- this.fullscreen = !1;
223
- }
224
- });
225
- },
226
- toggleFullScreen() {
227
- this.fullscreen = !this.fullscreen;
228
- },
229
- async onResize() {
230
- await this.$nextTick();
231
- const t = this.$el;
232
- this.editor.layout({
233
- width: t.clientWidth,
234
- height: t.clientHeight
235
- });
236
- },
237
- _handleFullScreen() {
238
- this.isMaximum ? this.minEditor() : this.maxEditor();
239
- },
240
- // 放大
241
- maxEditor() {
242
- this.isMaximum = !0;
243
- const t = this.$el;
244
- this.originSize = {
245
- width: t.clientWidth,
246
- height: t.clientHeight
247
- }, t.classList.add("editor-fullscreen"), this.editor.layout({
248
- height: document.body.clientHeight,
249
- width: document.body.clientWidth
250
- }), document.addEventListener("keyup", this.handleEsc);
251
- },
252
- handleEsc(t) {
253
- t.keyCode === 27 && this.minEditor();
254
- },
255
- // 缩小
256
- minEditor() {
257
- this.isMaximum = !1, this.$el.classList.remove("editor-fullscreen"), this.editor.layout({
258
- height: this.originSize.height,
259
- width: this.originSize.width
260
- }), document.removeEventListener("keyup", this.handleEsc);
261
- },
262
- _getEditor() {
263
- return this.editor ? this.diffEditor ? this.editor.modifiedEditor : this.editor : null;
264
- },
265
- _setModel(t, e) {
266
- const { language: i } = this, n = d.editor.createModel(e, i), o = d.editor.createModel(t, i);
267
- this.editor.setModel({
268
- original: n,
269
- modified: o
270
- });
271
- },
272
- _setValue(t) {
273
- const e = this._getEditor();
274
- if (e) return e.setValue(t);
275
- },
276
- _getValue() {
277
- const t = this._getEditor();
278
- return t ? t.getValue() : "";
279
- },
280
- _editorBeforeMount() {
281
- return this.editorBeforeMount(d) || {};
282
- },
283
- _editorMounted(t) {
284
- this.editorMounted(t, d), this.diffEditor ? t.onDidUpdateDiff((e) => {
285
- const i = this._getValue();
286
- this._emitChange(i, e);
287
- }) : t.onDidChangeModelContent((e) => {
288
- const i = this._getValue();
289
- this._emitChange(i, e);
290
- });
291
- },
292
- _emitChange(t, e) {
293
- this.$emit("change", t, e), this.$emit("input", t);
294
- }
295
- },
296
- render(t) {
297
- const e = this.options.fullScreen;
298
- return t("div", { class: ["monaco_editor_container", this.fullscreen ? "fullscreen" : ""], style: this.style }, [
299
- e ? t("i", {
300
- class: "el-icon-full-screen",
301
- style: {
302
- width: "1.2em",
303
- height: "1.2em",
304
- position: "absolute",
305
- left: "0px",
306
- top: "0px",
307
- zIndex: "1",
308
- cursor: "pointer"
309
- },
310
- on: { click: this._handleFullScreen }
311
- }) : ""
312
- ]);
313
- }
314
- }, k = null, z = null;
315
- var C = /* @__PURE__ */ x(
316
- A,
317
- k,
318
- z,
319
- !1,
320
- null,
321
- null
322
- );
323
- const F = C.exports;
324
- export {
325
- F as M,
326
- M as c
327
- };
@@ -1,80 +0,0 @@
1
- import g from "photoswipe";
2
- import "photoswipe/dist/photoswipe.css";
3
- import { n as u } from "./_plugin-vue2_normalizer.CeySl7Fu.mjs";
4
- function d(t) {
5
- new g(t).init();
6
- }
7
- async function l(t, r, n = { selector: "chat-image" }) {
8
- const c = t.target;
9
- if (!(!c || c.classList.contains(n.selector) || c.tagName === "IMG"))
10
- return;
11
- const e = r.querySelectorAll(n.selector === "img" ? n.selector : `.${n.selector}`), a = [...e].findIndex((o) => o === c);
12
- a >= 0 && (n.index = a);
13
- const i = await w(e);
14
- await d({ dataSource: i, index: a });
15
- }
16
- async function w(t) {
17
- const r = [];
18
- for (let n = 0, c = t.length; n < c; n++) {
19
- const e = t[n], a = e.getAttribute("data-src") || e.getAttribute("src"), i = {
20
- src: a,
21
- msrc: a,
22
- alt: e.getAttribute("data-title") || e.getAttribute("alt"),
23
- element: e
24
- }, o = e.getAttribute("data-height"), h = e.getAttribute("data-width");
25
- let s = { width: h, height: o };
26
- !o && !h && (s = await f(e), e.setAttribute("data-height", s.height), e.setAttribute("data-width", s.width)), i.w = s.width, i.width = s.width, i.h = s.height, i.height = s.height, r.push(i);
27
- }
28
- return r;
29
- }
30
- function f(t) {
31
- const r = t.getAttribute("data-src") || t.getAttribute("src"), n = t.getAttribute("data-height"), c = t.getAttribute("data-width");
32
- return n && c ? { width: c, height: n } : t.complete ? {
33
- width: t.naturalWidth,
34
- height: t.naturalHeight
35
- } : new Promise((e) => {
36
- const a = new Image();
37
- a.src = r;
38
- const i = {};
39
- a.complete ? (i.width = a.width, i.height = a.height, e(i)) : (a.onload = () => {
40
- i.width = a.width, i.height = a.height, e(i);
41
- }, a.onerror = () => {
42
- i.width = 0, i.height = 0, e(i);
43
- });
44
- });
45
- }
46
- const m = {
47
- name: "PhotoSwipe",
48
- props: {
49
- urls: Array,
50
- selector: {
51
- type: String,
52
- default: "img"
53
- }
54
- },
55
- methods: {
56
- async preview(t) {
57
- await l(t, this.$refs.wrapper, { selector: this.selector });
58
- }
59
- }
60
- };
61
- var p = function() {
62
- var r = this, n = r._self._c;
63
- return n("div", { ref: "wrapper" }, [r._t("default", function() {
64
- return r._l(r.urls, function(c) {
65
- return n("img", { key: c.src, staticStyle: { cursor: "pointer" }, attrs: { width: "100", src: c.src, alt: "" }, on: { click: r.preview } });
66
- });
67
- }, { urls: r.urls, preview: r.preview })], 2);
68
- }, _ = [], b = /* @__PURE__ */ u(
69
- m,
70
- p,
71
- _,
72
- !1,
73
- null,
74
- null
75
- );
76
- const v = b.exports;
77
- export {
78
- v as P,
79
- l as p
80
- };