@milkdown/plugin-upload 7.5.9 → 7.6.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.
Files changed (2) hide show
  1. package/lib/index.es.js +44 -44
  2. package/package.json +7 -7
package/lib/index.es.js CHANGED
@@ -3,37 +3,37 @@ import { PluginKey as D, Plugin as P } from "@milkdown/prose/state";
3
3
  import { Decoration as k, DecorationSet as C } from "@milkdown/prose/view";
4
4
  import { $ctx as b, $prose as U } from "@milkdown/utils";
5
5
  import { missingNodeInSchema as F } from "@milkdown/exception";
6
- function w(n) {
6
+ function w(a) {
7
7
  return new Promise((s) => {
8
8
  const r = new FileReader();
9
9
  r.addEventListener(
10
10
  "load",
11
11
  () => {
12
12
  s({
13
- alt: n.name,
13
+ alt: a.name,
14
14
  src: r.result
15
15
  });
16
16
  },
17
17
  !1
18
- ), r.readAsDataURL(n);
18
+ ), r.readAsDataURL(a);
19
19
  });
20
20
  }
21
- const A = async (n, s) => {
21
+ const A = async (a, s) => {
22
22
  const r = [];
23
- for (let t = 0; t < n.length; t++) {
24
- const e = n.item(t);
25
- e && e.type.includes("image") && r.push(e);
23
+ for (let e = 0; e < a.length; e++) {
24
+ const t = a.item(e);
25
+ t && t.type.includes("image") && r.push(t);
26
26
  }
27
27
  const { image: l } = s.nodes;
28
28
  if (!l) throw F("image");
29
- return (await Promise.all(r.map((t) => w(t)))).map(({ alt: t, src: e }) => l.createAndFill({ src: e, alt: t }));
29
+ return (await Promise.all(r.map((e) => w(e)))).map(({ alt: e, src: t }) => l.createAndFill({ src: t, alt: e }));
30
30
  }, c = b(
31
31
  {
32
32
  uploader: A,
33
33
  enableHtmlFileUploader: !1,
34
- uploadWidgetFactory: (n, s) => {
34
+ uploadWidgetFactory: (a, s) => {
35
35
  const r = document.createElement("span");
36
- return r.textContent = "Upload in progress...", k.widget(n, r, s);
36
+ return r.textContent = "Upload in progress...", k.widget(a, r, s);
37
37
  }
38
38
  },
39
39
  "uploadConfig"
@@ -42,27 +42,27 @@ c.meta = {
42
42
  package: "@milkdown/plugin-upload",
43
43
  displayName: "Ctx<uploadConfig>"
44
44
  };
45
- const f = U((n) => {
46
- const s = new D("MILKDOWN_UPLOAD"), r = (o, t) => {
45
+ const f = U((a) => {
46
+ const s = new D("MILKDOWN_UPLOAD"), r = (o, e) => {
47
47
  var i;
48
- const e = s.getState(o);
49
- if (!e) return -1;
50
- const a = e.find(
48
+ const t = s.getState(o);
49
+ if (!t) return -1;
50
+ const n = t.find(
51
51
  void 0,
52
52
  void 0,
53
- (d) => d.id === t
53
+ (d) => d.id === e
54
54
  );
55
- return a.length ? ((i = a[0]) == null ? void 0 : i.from) ?? -1 : -1;
56
- }, l = (o, t, e) => {
55
+ return n.length ? ((i = n[0]) == null ? void 0 : i.from) ?? -1 : -1;
56
+ }, l = (o, e, t) => {
57
57
  var m;
58
- if (!e || e.length <= 0) return !1;
59
- const a = Symbol("upload symbol"), i = n.get(y), { tr: d } = o.state, g = t instanceof DragEvent ? ((m = o.posAtCoords({ left: t.clientX, top: t.clientY })) == null ? void 0 : m.pos) ?? d.selection.from : d.selection.from;
60
- o.dispatch(d.setMeta(s, { add: { id: a, pos: g } }));
61
- const { uploader: h } = n.get(c.key);
62
- return h(e, i).then((p) => {
63
- const u = r(o.state, a);
58
+ if (!t || t.length <= 0) return !1;
59
+ const n = Symbol("upload symbol"), i = a.get(y), { tr: d } = o.state, g = e instanceof DragEvent ? ((m = o.posAtCoords({ left: e.clientX, top: e.clientY })) == null ? void 0 : m.pos) ?? d.selection.from : d.selection.from;
60
+ o.dispatch(d.setMeta(s, { add: { id: n, pos: g } }));
61
+ const { uploader: h } = a.get(c.key);
62
+ return h(t, i).then((p) => {
63
+ const u = r(o.state, n);
64
64
  u < 0 || o.dispatch(
65
- o.state.tr.replaceWith(u, u, p).setMeta(s, { remove: { id: a } })
65
+ o.state.tr.replaceWith(u, u, p).setMeta(s, { remove: { id: n } })
66
66
  );
67
67
  }).catch((p) => {
68
68
  console.error(p);
@@ -74,38 +74,38 @@ const f = U((n) => {
74
74
  init() {
75
75
  return C.empty;
76
76
  },
77
- apply(o, t) {
78
- const e = t.map(o.mapping, o.doc), a = o.getMeta(this);
79
- if (!a) return e;
80
- if (a.add) {
81
- const { uploadWidgetFactory: i } = n.get(c.key), d = i(a.add.pos, {
82
- id: a.add.id
77
+ apply(o, e) {
78
+ const t = e.map(o.mapping, o.doc), n = o.getMeta(this);
79
+ if (!n) return t;
80
+ if (n.add) {
81
+ const { uploadWidgetFactory: i } = a.get(c.key), d = i(n.add.pos, {
82
+ id: n.add.id
83
83
  });
84
- return e.add(o.doc, [d]);
84
+ return t.add(o.doc, [d]);
85
85
  }
86
- if (a.remove) {
87
- const i = e.find(
86
+ if (n.remove) {
87
+ const i = t.find(
88
88
  void 0,
89
89
  void 0,
90
- (d) => d.id === a.remove.id
90
+ (d) => d.id === n.remove.id
91
91
  );
92
- return e.remove(i);
92
+ return t.remove(i);
93
93
  }
94
- return e;
94
+ return t;
95
95
  }
96
96
  },
97
97
  props: {
98
98
  decorations(o) {
99
99
  return this.getState(o);
100
100
  },
101
- handlePaste: (o, t) => {
102
- var a, i;
103
- const { enableHtmlFileUploader: e } = n.get(c.key);
104
- return !(t instanceof ClipboardEvent) || !e && ((a = t.clipboardData) != null && a.getData("text/html")) ? !1 : l(o, t, (i = t.clipboardData) == null ? void 0 : i.files);
101
+ handlePaste: (o, e) => {
102
+ var n, i;
103
+ const { enableHtmlFileUploader: t } = a.get(c.key);
104
+ return !(e instanceof ClipboardEvent) || !t && ((n = e.clipboardData) != null && n.getData("text/html")) ? !1 : l(o, e, (i = e.clipboardData) == null ? void 0 : i.files);
105
105
  },
106
- handleDrop: (o, t) => {
107
- var e;
108
- return t instanceof DragEvent ? l(o, t, (e = t.dataTransfer) == null ? void 0 : e.files) : !1;
106
+ handleDrop: (o, e) => {
107
+ var t;
108
+ return e instanceof DragEvent ? l(o, e, (t = e.dataTransfer) == null ? void 0 : t.files) : !1;
109
109
  }
110
110
  }
111
111
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@milkdown/plugin-upload",
3
3
  "type": "module",
4
- "version": "7.5.9",
4
+ "version": "7.6.1",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -30,14 +30,14 @@
30
30
  "@milkdown/prose": "^7.2.0"
31
31
  },
32
32
  "dependencies": {
33
- "tslib": "^2.5.0",
34
- "@milkdown/exception": "7.5.9",
35
- "@milkdown/utils": "7.5.9"
33
+ "tslib": "^2.8.1",
34
+ "@milkdown/utils": "7.6.1",
35
+ "@milkdown/exception": "7.6.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@milkdown/core": "7.5.9",
39
- "@milkdown/ctx": "7.5.9",
40
- "@milkdown/prose": "7.5.9"
38
+ "@milkdown/core": "7.6.1",
39
+ "@milkdown/prose": "7.6.1",
40
+ "@milkdown/ctx": "7.6.1"
41
41
  },
42
42
  "nx": {
43
43
  "targets": {