@web-utils/component 2.8.0 → 2.8.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.
@@ -1,28 +1,45 @@
1
- var m = Object.defineProperty, g = Object.defineProperties;
2
- var h = Object.getOwnPropertyDescriptors;
3
- var d = Object.getOwnPropertySymbols;
4
- var f = Object.prototype.hasOwnProperty, y = Object.prototype.propertyIsEnumerable;
5
- var c = (e, t, o) => t in e ? m(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o, l = (e, t) => {
6
- for (var o in t || (t = {}))
7
- f.call(t, o) && c(e, o, t[o]);
8
- if (d)
9
- for (var o of d(t))
10
- y.call(t, o) && c(e, o, t[o]);
11
- return e;
12
- }, s = (e, t) => g(e, h(t));
1
+ var I = Object.defineProperty, v = Object.defineProperties;
2
+ var k = Object.getOwnPropertyDescriptors;
3
+ var y = Object.getOwnPropertySymbols;
4
+ var C = Object.prototype.hasOwnProperty, A = Object.prototype.propertyIsEnumerable;
5
+ var w = (t, e, a) => e in t ? I(t, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[e] = a, m = (t, e) => {
6
+ for (var a in e || (e = {}))
7
+ C.call(e, a) && w(t, a, e[a]);
8
+ if (y)
9
+ for (var a of y(e))
10
+ A.call(e, a) && w(t, a, e[a]);
11
+ return t;
12
+ }, f = (t, e) => v(t, k(e));
13
+ var g = (t, e, a) => new Promise((i, n) => {
14
+ var r = (s) => {
15
+ try {
16
+ o(a.next(s));
17
+ } catch (c) {
18
+ n(c);
19
+ }
20
+ }, l = (s) => {
21
+ try {
22
+ o(a.throw(s));
23
+ } catch (c) {
24
+ n(c);
25
+ }
26
+ }, o = (s) => s.done ? i(s.value) : Promise.resolve(s.value).then(r, l);
27
+ o((a = a.apply(t, e)).next());
28
+ });
13
29
  import "tinymce/skins/lightgray/skin.min.css";
14
- import w from "tinymce";
15
- import b from "@tinymce/tinymce-vue";
30
+ import P from "tinymce";
31
+ import R from "@tinymce/tinymce-vue";
16
32
  import "tinymce/themes/modern/theme";
17
33
  import "tinymce/plugins/contextmenu";
18
34
  import "tinymce/plugins/wordcount";
35
+ import "tinymce/plugins/paste";
19
36
  import "tinymce/plugins/image";
20
37
  import "tinymce/plugins/fullscreen";
21
38
  import "tinymce/plugins/preview";
22
39
  import "tinymce/plugins/imagetools";
23
- import { guid as v } from "@web-utils/core";
24
- import { n as F } from "../chunks/vueComponentNormalizer.446f5dc4.mjs";
25
- const k = {
40
+ import { getFilePrefix as T, guid as S } from "@web-utils/core";
41
+ import { n as U } from "../chunks/vueComponentNormalizer.446f5dc4.mjs";
42
+ const B = {
26
43
  Redo: "重做",
27
44
  Undo: "撤销",
28
45
  Cut: "剪切",
@@ -411,52 +428,189 @@ const k = {
411
428
  Spellcheck: "拼写检查",
412
429
  Caption: "标题",
413
430
  "Insert template": "插入模板"
414
- };
415
- var C = function() {
416
- var e = this, t = e.$createElement, o = e._self._c || t;
417
- return e.show ? o("div", {
431
+ }, D = '方正小标宋="方正小标宋";仿宋GB2312="仿宋GB2312";微软雅黑="微软雅黑";宋体="宋体";黑体="黑体";仿宋="仿宋";楷体="楷体";隶书="隶书";幼圆="幼圆";Arial="Arial";', L = `
432
+ * {
433
+ margin: 0;
434
+ padding: 0
435
+ }
436
+
437
+ body {
438
+ font-family: 微软雅黑, sans-serif;
439
+ padding: 10px;
440
+ font-size: 18px
441
+ }
442
+
443
+ .template-tag {
444
+ font-style: italic;
445
+ color: #1e90ff;
446
+ margin: 0 10px;
447
+ font-weight: bold;
448
+ cursor: help !important;
449
+ font-family: 黑体, serif;
450
+ }
451
+
452
+ .mce-content-body img {
453
+ max-width: 100%;
454
+ }
455
+ `;
456
+ function _(t) {
457
+ let e;
458
+ const a = t.naturalHeight, i = document.createElement("canvas");
459
+ i.width = 1, i.height = a;
460
+ const n = i.getContext("2d");
461
+ n.drawImage(t, 0, 0);
462
+ try {
463
+ e = n.getImageData(0, 0, 1, a).data;
464
+ } catch (c) {
465
+ return console.log("Cannot check verticalSquash: CORS?"), 1;
466
+ }
467
+ let r = 0, l = a, o = a;
468
+ for (; o > r; )
469
+ e[(o - 1) * 4 + 3] === 0 ? l = o : r = o, o = l + r >> 1;
470
+ const s = o / a;
471
+ return s === 0 ? 1 : s;
472
+ }
473
+ function F(t) {
474
+ const e = atob(t.split(",")[1]), a = new ArrayBuffer(e.length), i = new Uint8Array(a);
475
+ for (let n = 0; n < e.length; n++)
476
+ i[n] = e.charCodeAt(n);
477
+ return a;
478
+ }
479
+ function H(t) {
480
+ const e = t.split(",")[0].split(":")[1].split(";")[0], a = F(t);
481
+ return new Blob([a], { type: e });
482
+ }
483
+ function x(t) {
484
+ const e = new DataView(t);
485
+ if (e.getUint16(0, !1) !== 65496)
486
+ return -2;
487
+ const a = e.byteLength;
488
+ let i = 2;
489
+ for (; i < a; ) {
490
+ const n = e.getUint16(i, !1);
491
+ if (i += 2, n === 65505) {
492
+ if (e.getUint32(i += 2, !1) !== 1165519206)
493
+ return -1;
494
+ const r = e.getUint16(i += 6, !1) === 18761;
495
+ i += e.getUint32(i + 4, r);
496
+ const l = e.getUint16(i, r);
497
+ i += 2;
498
+ for (let o = 0; o < l; o++)
499
+ if (e.getUint16(i + o * 12, r) === 274)
500
+ return e.getUint16(i + o * 12 + 8, r);
501
+ } else {
502
+ if ((n & 65280) !== 65280)
503
+ break;
504
+ i += e.getUint16(i, !1);
505
+ }
506
+ }
507
+ return -1;
508
+ }
509
+ function E(t, e, a) {
510
+ const i = t.width, n = t.height;
511
+ switch (a > 4 && (t.width = n, t.height = i), a) {
512
+ case 2:
513
+ e.translate(i, 0), e.scale(-1, 1);
514
+ break;
515
+ case 3:
516
+ e.translate(i, n), e.rotate(Math.PI);
517
+ break;
518
+ case 4:
519
+ e.translate(0, n), e.scale(1, -1);
520
+ break;
521
+ case 5:
522
+ e.rotate(0.5 * Math.PI), e.scale(1, -1);
523
+ break;
524
+ case 6:
525
+ e.rotate(0.5 * Math.PI), e.translate(0, -n);
526
+ break;
527
+ case 7:
528
+ e.rotate(0.5 * Math.PI), e.translate(i, -n), e.scale(-1, 1);
529
+ break;
530
+ case 8:
531
+ e.rotate(-0.5 * Math.PI), e.translate(-i, 0);
532
+ break;
533
+ }
534
+ }
535
+ function $(t) {
536
+ return t.split(",")[0].split(":")[1].split(";")[0];
537
+ }
538
+ function M(t) {
539
+ return `.${$(t).replace("image/", "")}`;
540
+ }
541
+ function z(t, e) {
542
+ return g(this, null, function* () {
543
+ return new Promise((a, i) => {
544
+ const n = new Image();
545
+ n.onload = function() {
546
+ const r = _(n), l = x(F(n.src)), o = document.createElement("canvas"), s = o.getContext("2d"), c = e.compress.width, h = e.compress.height;
547
+ let d = n.width, p = n.height;
548
+ d < p && p > h ? (d = parseInt(`${h * n.width / n.height}`), p = h) : d >= p && d > c && (p = parseInt(`${c * n.height / n.width}`), d = c), o.width = d, o.height = p, l > 0 && E(o, s, l), s.drawImage(n, 0, 0, d, p / r);
549
+ const u = o.toDataURL("image/jpeg", e.compress.quality);
550
+ /;base64,null/.test(u) || /;base64,$/.test(u) ? (e.onError(new Error(`Compress fail, dataURL is ${u}.`)), i(Error("图片压缩失败"))) : a(G(u, `${T(e.fileName)}.jpg`));
551
+ }, n.src = t;
552
+ });
553
+ });
554
+ }
555
+ function q(t, e) {
556
+ return g(this, null, function* () {
557
+ const a = yield N(t);
558
+ return z(a, m({ fileName: t.name }, e));
559
+ });
560
+ }
561
+ function N(t) {
562
+ return new Promise((e, a) => {
563
+ const i = new FileReader();
564
+ i.onload = function(n) {
565
+ e(n.target.result);
566
+ }, i.onerror = function(n) {
567
+ a(n);
568
+ }, i.readAsDataURL(t);
569
+ });
570
+ }
571
+ function G(t = "", e) {
572
+ const a = H(t);
573
+ return a.name = e || `image${M(t)}`, a;
574
+ }
575
+ var j = function() {
576
+ var t = this, e = t.$createElement, a = t._self._c || e;
577
+ return t.show ? a("div", {
418
578
  class: ["tinymce-editor", {
419
- "none-resize": !e.resize
579
+ "none-resize": !t.resize
420
580
  }]
421
- }, [o("Editor", {
581
+ }, [a("Editor", {
422
582
  ref: "editor",
423
583
  attrs: {
424
- disabled: e.inputDisabled,
584
+ disabled: t.inputDisabled,
425
585
  "model-events": "change input undo redo SetContent",
426
- init: e.init
586
+ init: t.init
427
587
  },
428
588
  model: {
429
- value: e.val,
430
- callback: function(a) {
431
- e.val = a;
589
+ value: t.val,
590
+ callback: function(i) {
591
+ t.val = i;
432
592
  },
433
593
  expression: "val"
434
594
  }
435
- }), o("ElUpload", {
595
+ }), a("ElUpload", {
436
596
  ref: "uploader",
437
597
  staticStyle: {
438
598
  display: "none"
439
599
  },
440
600
  attrs: {
441
- action: e.action,
442
- headers: e.headers,
443
- "before-upload": e.beforeUploadFile,
444
- "on-success": e.onFileUploadSuccess,
601
+ action: t.action,
602
+ "http-request": t.uploadImageFile,
445
603
  "show-file-list": !1,
446
- data: {
447
- unid: e.guid(),
448
- type: e.fileLabel
449
- },
450
604
  "auto-upload": "",
451
605
  accept: ".jpg,.jpeg,.png,.gif,.bmp"
452
606
  }
453
- }, [o("span")])], 1) : e._e();
454
- }, I = [];
455
- w.addI18n("zh_CN", k);
456
- const S = {
607
+ }, [a("span")])], 1) : t._e();
608
+ }, O = [];
609
+ P.addI18n("zh_CN", B);
610
+ const V = {
457
611
  name: "TinymceWrapper",
458
612
  components: {
459
- Editor: b
613
+ Editor: R
460
614
  },
461
615
  inject: {
462
616
  elForm: {
@@ -472,6 +626,9 @@ const S = {
472
626
  default: ""
473
627
  },
474
628
  resize: Boolean,
629
+ api: Function,
630
+ getHeader: Function,
631
+ getUploadUrl: Function,
475
632
  disabled: {
476
633
  type: Boolean,
477
634
  default: !1
@@ -495,47 +652,47 @@ const S = {
495
652
  type: String,
496
653
  default: "编辑"
497
654
  },
498
- queryParams: Object,
499
- getHeader: Function,
500
- getUploadUrl: Function,
501
- imageUrl: String
655
+ queryParams: Object
502
656
  },
503
657
  data() {
504
- const t = ["fullscreen", "image", "wordcount"].join(","), o = this.buttons || [];
505
- let a = this.toolbar || " | ";
506
- return a = `bold italic underline | alignleft aligncenter alignright alignjustify | fontselect fontsizeselect | removeformat | | ${a}`, o && (a += ` ${o.map((r) => r.name).join(" ")}`), a += " | fullscreen", {
658
+ const e = ["fullscreen", "image", "wordcount", "paste"].join(","), a = this.buttons || [];
659
+ let i = this.toolbar || " | ";
660
+ return i = `undo redo | bold italic underline | alignleft aligncenter alignright alignjustify | fontselect fontsizeselect | removeformat | | ${i}`, a && (i += ` ${a.map((r) => r.name).join(" ")}`), i += " | fullscreen", {
507
661
  val: "",
508
662
  show: !0,
509
663
  init: {
510
664
  setup: (r) => {
511
- r.settings.dialog_title = this.dialogTitle, r.settings.show_types = this.showTypes, r.on("PreInit", (i) => {
512
- i.target.dom.doc.body.style.fontFamily = "微软雅黑";
513
- }), r.on("Blur", (i) => {
514
- this.$emit("on-blur", i);
515
- }), r.on("DialogShow", (i) => {
516
- this.$emit("dialog-show", i);
517
- }), r.on("DialogHide", (i) => {
518
- this.$emit("dialog-hide", i);
519
- }), o.forEach((i) => {
520
- i.icon = ` ${i.icon}`;
521
- const { onclick: p } = i;
522
- r.addButton(i.name, s(l({}, i), {
523
- onclick: () => p(r)
665
+ r.settings.dialog_title = this.dialogTitle, r.settings.show_types = this.showTypes, r.on("paste", (o) => {
666
+ const s = o.clipboardData || o.dataTransfer;
667
+ return !(this.processItems(o, s.items) || this.processItems(o, s.files));
668
+ }), r.on("PreInit", (o) => {
669
+ o.target.dom.doc.body.style.fontFamily = "微软雅黑";
670
+ }), r.on("Blur", (o) => {
671
+ this.$emit("on-blur", o);
672
+ }), r.on("DialogShow", (o) => {
673
+ this.$emit("dialog-show", o);
674
+ }), r.on("DialogHide", (o) => {
675
+ this.$emit("dialog-hide", o);
676
+ }), a.forEach((o) => {
677
+ o.icon = ` ${o.icon}`;
678
+ const { onclick: s } = o;
679
+ r.addButton(o.name, f(m({}, o), {
680
+ onclick: () => s(r)
524
681
  }));
525
682
  });
526
- const n = {
683
+ const l = {
527
684
  icon: " el-icon-picture",
528
685
  name: "uploadImage",
529
686
  title: "上传图片",
530
687
  onclick: this.upload
531
688
  };
532
- r.addButton(n.name, s(l({}, n), {
533
- onclick: () => n.onclick(r)
689
+ r.addButton(l.name, f(m({}, l), {
690
+ onclick: () => l.onclick(r)
534
691
  }));
535
692
  },
536
- toolbar: a,
693
+ toolbar: i,
537
694
  placeholder: "在这里输入文字",
538
- content_style: "*{margin:0;padding:0} body{font-family: 微软雅黑, sans-serif;padding:10px; font-size: 18px} .template-tag {font-style: italic;color: #1e90ff;margin: 0 10px;font-weight: bold;cursor: help !important;font-family: 黑体,serif;}",
695
+ content_style: L,
539
696
  fontname: "宋体",
540
697
  fontFamily: "宋体",
541
698
  branding: !1,
@@ -545,8 +702,9 @@ const S = {
545
702
  menubar: !1,
546
703
  height: "100%",
547
704
  elementpath: !1,
548
- plugins: `${t},${this.plugins}`,
549
- font_formats: '微软雅黑="微软雅黑";宋体="宋体";黑体="黑体";仿宋="仿宋";楷体="楷体";隶书="隶书";幼圆="幼圆";Arial="Arial";'
705
+ plugins: `${e},${this.plugins}`,
706
+ font_formats: D,
707
+ fontsize_formats: "8pt 10pt 12pt 14pt 18pt 24pt 36pt"
550
708
  }
551
709
  };
552
710
  },
@@ -558,26 +716,26 @@ const S = {
558
716
  return this.prop ? this.prop : this.elFormItem ? this.elFormItem.prop : "";
559
717
  },
560
718
  action() {
561
- var e;
562
- return (e = this.getUploadUrl) == null ? void 0 : e.call(this);
719
+ var t;
720
+ return (t = this.getUploadUrl) == null ? void 0 : t.call(this);
563
721
  },
564
722
  headers() {
565
- var e;
566
- return (e = this.getHeader) == null ? void 0 : e.call(this);
723
+ var t;
724
+ return (t = this.getHeader) == null ? void 0 : t.call(this);
567
725
  }
568
726
  },
569
727
  watch: {
570
728
  value: {
571
729
  immediate: !0,
572
- handler(e) {
573
- this.val = e;
730
+ handler(t) {
731
+ this.val = t;
574
732
  }
575
733
  },
576
- dialogTitle(e) {
577
- this.getEditor() && (this.getEditor().settings.dialog_title = e);
734
+ dialogTitle(t) {
735
+ this.getEditor() && (this.getEditor().settings.dialog_title = t);
578
736
  },
579
- val(e) {
580
- this.elForm && this.elFormItem && this.elForm.clearValidate([this.elFormItem.prop]), this.$emit("input", e);
737
+ val(t) {
738
+ this.elForm && this.elFormItem && this.elForm.clearValidate([this.elFormItem.prop]), this.$emit("input", t);
581
739
  }
582
740
  },
583
741
  deactivated() {
@@ -587,42 +745,77 @@ const S = {
587
745
  this.show = !0;
588
746
  },
589
747
  methods: {
748
+ uploadImageFile(n) {
749
+ return g(this, arguments, function* ({ file: t, onError: e, onProgress: a, onSuccess: i }) {
750
+ var r, l;
751
+ try {
752
+ this.loading = this.$loading({ text: "压缩中...", background: "rgba(0,0,0,0.2)" });
753
+ const o = yield q(t, {
754
+ compress: {
755
+ width: 1920,
756
+ height: 1600,
757
+ quality: 0.8
758
+ }
759
+ });
760
+ this.loading.text = "上传中...";
761
+ const s = yield this.api((r = this.getUploadUrl) == null ? void 0 : r.call(this), o, {
762
+ data: { unid: S(), type: this.fileLabel },
763
+ onprogress(c) {
764
+ a == null || a(c);
765
+ }
766
+ });
767
+ this.insertImage(s.data.filePath), i == null || i(s, t), this.$refs.uploader.clearFiles();
768
+ } catch (o) {
769
+ e == null || e(o);
770
+ }
771
+ (l = this.loading) == null || l.close();
772
+ });
773
+ },
774
+ processItems(t, e) {
775
+ let a = !1;
776
+ for (let i = 0; i < e.length; i++) {
777
+ const n = e[i];
778
+ if (/^image\/(jpeg|png|gif|bmp)$/.test(n.type)) {
779
+ const r = n.getAsFile ? n.getAsFile() : n;
780
+ this.uploadImageFile({ file: r }), t.preventDefault(), a = !0;
781
+ }
782
+ }
783
+ return a;
784
+ },
590
785
  getEditor() {
591
786
  return this.$refs.editor.editor;
592
787
  },
593
- guid: v,
594
788
  focus() {
595
789
  this.getEditor().focus();
596
790
  },
597
791
  upload() {
598
792
  this.$refs.uploader.$refs["upload-inner"].handleClick();
599
793
  },
600
- beforeUploadFile() {
794
+ insertImage(t) {
795
+ this.getEditor().insertContent(`<img alt="图片" src="${this.replaceImageUrl(t)}"/>`);
601
796
  },
602
- onFileUploadSuccess(e) {
603
- this.getEditor().insertContent(
604
- `<img alt="图片" src="${e.data.filePath.replace("/var/local/data/merge", this.imageUrl || "")}"/>`
605
- );
797
+ replaceImageUrl(t) {
798
+ return t.replace("/var/local/data/merge", "");
606
799
  }
607
800
  }
608
- }, u = {};
609
- var A = /* @__PURE__ */ F(
610
- S,
611
- C,
612
- I,
801
+ }, b = {};
802
+ var W = /* @__PURE__ */ U(
803
+ V,
804
+ j,
805
+ O,
613
806
  !1,
614
- P,
807
+ Y,
615
808
  null,
616
809
  null,
617
810
  null
618
811
  );
619
- function P(e) {
620
- for (let t in u)
621
- this[t] = u[t];
812
+ function Y(t) {
813
+ for (let e in b)
814
+ this[e] = b[e];
622
815
  }
623
- const G = /* @__PURE__ */ function() {
624
- return A.exports;
816
+ const ce = /* @__PURE__ */ function() {
817
+ return W.exports;
625
818
  }();
626
819
  export {
627
- G as default
820
+ ce as default
628
821
  };