inline-attacher 0.0.7 → 0.0.8

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/README.md CHANGED
@@ -1,11 +1,13 @@
1
- # 📎 Inline Attachment Next (WIP)
1
+ # 📎 Inline Attacher
2
2
 
3
3
  [![NPM Version](https://img.shields.io/npm/v/inline-attacher.svg?style=for-the-badge)](https://www.npmjs.com/package/inline-attacher)
4
4
  [![NPM Downloads](https://img.shields.io/npm/dt/inline-attacher.svg?style=for-the-badge)](https://www.npmjs.com/package/inline-attacher)
5
- [![License](https://img.shields.io/github/license/EastSun5566/inline-attachment.svg?style=for-the-badge)](https://github.com/EastSun5566/inline-attachment/blob/main/LICENSE)
5
+ [![License](https://img.shields.io/github/license/EastSun5566/inline-attacher.svg?style=for-the-badge)](https://github.com/EastSun5566/inline-attacher/blob/main/LICENSE)
6
6
 
7
7
  > A modern port of [Inline Attachment](https://github.com/Rovak/InlineAttachment)
8
8
 
9
+ 🔗 <https://eastsun5566.github.io/inline-attacher/>
10
+
9
11
  ## Installation
10
12
 
11
13
  ```sh
@@ -1,8 +1,8 @@
1
1
  var w = Object.defineProperty;
2
2
  var x = (n, t, e) => t in n ? w(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
3
3
  var o = (n, t, e) => (x(n, typeof t != "symbol" ? t + "" : t, e), e);
4
- import { EditorView as D } from "@codemirror/view";
5
- const v = {
4
+ import { EditorView as V } from "@codemirror/view";
5
+ const E = {
6
6
  /**
7
7
  * URL where the file will be send
8
8
  */
@@ -90,7 +90,7 @@ const v = {
90
90
  onFileUploaded() {
91
91
  }
92
92
  };
93
- async function P({
93
+ async function D({
94
94
  url: n,
95
95
  ...t
96
96
  }) {
@@ -109,53 +109,53 @@ async function P({
109
109
  };
110
110
  }
111
111
  }
112
- function V(n) {
112
+ function T(n) {
113
113
  return typeof n == "function";
114
114
  }
115
- function T(n, t = "", e = "") {
116
- const r = t.split(".");
117
- let a = n;
118
- for (const s of r)
119
- if (a && typeof a == "object" && s in a)
120
- a = a[s];
115
+ function A(n, t = "", e = "") {
116
+ const s = t.split(".");
117
+ let i = n;
118
+ for (const r of s)
119
+ if (i && typeof i == "object" && r in i)
120
+ i = i[r];
121
121
  else
122
122
  return e;
123
- return a !== void 0 ? a : e;
123
+ return i !== void 0 ? i : e;
124
124
  }
125
- class E {
125
+ class v {
126
126
  constructor(t, e) {
127
- o(this, "options", v);
127
+ o(this, "options", E);
128
128
  o(this, "editor");
129
129
  o(this, "filename", "");
130
130
  o(this, "lastValue", "");
131
- this.editor = t, this.options = { ...v, ...e };
131
+ this.editor = t, this.options = { ...E, ...e };
132
132
  }
133
133
  /** Uploads file */
134
134
  async uploadFile(t) {
135
135
  const {
136
136
  defaultExtension: e,
137
- remoteFilename: r,
138
- uploadFieldName: a,
139
- extraParams: s,
137
+ remoteFilename: s,
138
+ uploadFieldName: i,
139
+ extraParams: r,
140
140
  extraHeaders: l,
141
- uploadUrl: d,
141
+ uploadUrl: c,
142
142
  uploadMethod: p,
143
- beforeFileUpload: c
144
- } = this.options, i = new FormData();
143
+ beforeFileUpload: d
144
+ } = this.options, a = new FormData();
145
145
  let f = e;
146
146
  if (t.name) {
147
147
  const [u] = t.name.match(/\.(.+)$/) || [];
148
148
  u && (f = u);
149
149
  }
150
- const g = (r == null ? void 0 : r(t)) || `image-${Date.now()}.${f}`;
151
- if (this.filename = g, i.append(a, t, g), Object.keys(s).forEach((u) => {
152
- i.append(u, s[u]);
153
- }), !(c != null && c(i)))
150
+ const g = (s == null ? void 0 : s(t)) || `image-${Date.now()}.${f}`;
151
+ if (this.filename = g, a.append(i, t, g), Object.keys(r).forEach((u) => {
152
+ a.append(u, r[u]);
153
+ }), !(d != null && d(a)))
154
154
  return;
155
- const { ok: F, value: m } = await P({
156
- url: d,
155
+ const { ok: F, value: m } = await D({
156
+ url: c,
157
157
  method: p,
158
- body: i,
158
+ body: a,
159
159
  headers: l
160
160
  });
161
161
  if (!F) {
@@ -175,22 +175,22 @@ class E {
175
175
  * Handles upload response
176
176
  */
177
177
  onFileUploadSucceed(t) {
178
- var c, i;
179
- const { onFileUploadSucceed: e, urlText: r, responseUrlKey: a } = this.options;
178
+ var d, a;
179
+ const { onFileUploadSucceed: e, urlText: s, responseUrlKey: i } = this.options;
180
180
  if (!(e != null && e(t)) || !this.lastValue)
181
181
  return;
182
- const s = T(t, a) || "unknown URL";
183
- if (!s)
182
+ const r = A(t, i) || "unknown URL";
183
+ if (!r)
184
184
  return;
185
- const l = /!\[({[^}]+})]\(([^)]+)\)/, d = V(r) ? r(s, t) : r.replace(r.match(l)[1], this.filename).replace(r.match(l)[2], s), p = this.editor.getValue().replace(this.lastValue, d);
186
- this.editor.setValue(p), (i = (c = this.options).onFileUploaded) == null || i.call(c, s);
185
+ const l = /!\[({[^}]+})]\(([^)]+)\)/, c = T(s) ? s(r, t) : s.replace(s.match(l)[1], this.filename).replace(s.match(l)[2], r), p = this.editor.getValue().replace(this.lastValue, c);
186
+ this.editor.setValue(p), (a = (d = this.options).onFileUploaded) == null || a.call(d, r);
187
187
  }
188
188
  /**
189
189
  * Called when a file has failed to upload
190
190
  */
191
191
  onFileUploadError(t) {
192
- var r, a;
193
- if (!((a = (r = this.options).onFileUploadError) != null && a.call(r, t)) || !this.lastValue)
192
+ var s, i;
193
+ if (!((i = (s = this.options).onFileUploadError) != null && i.call(s, t)) || !this.lastValue)
194
194
  return;
195
195
  const e = this.editor.getValue().replace(this.lastValue, this.options.errorText);
196
196
  this.editor.setValue(e);
@@ -199,8 +199,8 @@ class E {
199
199
  * Called when a file has been inserted, either by drop or paste
200
200
  */
201
201
  onFileInserted(t) {
202
- var e, r;
203
- (r = (e = this.options).onFileReceived) != null && r.call(e, t) && (this.lastValue = this.options.progressText, this.editor.insertValue(this.lastValue));
202
+ var e, s;
203
+ (s = (e = this.options).onFileReceived) != null && s.call(e, t) && (this.lastValue = this.options.progressText, this.editor.insertValue(this.lastValue));
204
204
  }
205
205
  handleFiles(t) {
206
206
  Array.from(t).forEach((e) => {
@@ -212,24 +212,23 @@ class E {
212
212
  */
213
213
  onPaste(t) {
214
214
  var e;
215
- t.preventDefault(), (e = t.clipboardData) != null && e.files.length && this.handleFiles(t.clipboardData.files);
215
+ (e = t.clipboardData) != null && e.files.length && this.handleFiles(t.clipboardData.files);
216
216
  }
217
217
  /**
218
218
  * Called when a drop event occurred
219
219
  */
220
220
  onDrop(t) {
221
221
  var e;
222
- t.preventDefault(), (e = t.dataTransfer) != null && e.files.length && this.handleFiles(t.dataTransfer.files);
222
+ (e = t.dataTransfer) != null && e.files.length && this.handleFiles(t.dataTransfer.files);
223
223
  }
224
224
  }
225
- function A(n, t) {
226
- const e = n.scrollTop;
227
- let r = 0, a = !1, s;
228
- n.selectionStart || n.selectionStart === 0 ? a = "ff" : document.selection && (a = "ie"), a === "ie" ? (n.focus(), s = document.selection.createRange(), s.moveStart("character", -n.value.length), r = s.text.length) : a === "ff" && (r = n.selectionStart || 0);
229
- const l = n.value.substring(0, r), d = n.value.substring(r, n.value.length);
230
- n.value = l + t + d, r += t.length, a === "ie" ? (n.focus(), s = document.selection.createRange(), s.moveStart("character", -n.value.length), s.moveStart("character", r), s.moveEnd("character", 0), s.select()) : a === "ff" && (n.selectionStart = r, n.selectionEnd = r, n.focus()), n.scrollTop = e;
225
+ function U(n, t) {
226
+ const e = n.scrollTop, s = n.selectionStart || 0, { value: i } = n, r = i.slice(0, s), l = i.slice(s, i.length);
227
+ n.value = r + t + l;
228
+ const c = s + t.length;
229
+ n.selectionStart = c, n.selectionEnd = c, n.scrollTop = e, n.focus();
231
230
  }
232
- class U {
231
+ class b {
233
232
  constructor(t) {
234
233
  o(this, "instance");
235
234
  this.instance = t;
@@ -238,46 +237,45 @@ class U {
238
237
  return this.instance.value;
239
238
  }
240
239
  insertValue(t) {
241
- A(this.instance, t);
240
+ U(this.instance, t), this.dispatchInputEvent();
242
241
  }
243
242
  setValue(t) {
244
- this.instance.value = t;
243
+ this.instance.value = t, this.dispatchInputEvent();
244
+ }
245
+ dispatchInputEvent() {
246
+ this.instance.dispatchEvent(new InputEvent("input", {
247
+ bubbles: !0,
248
+ cancelable: !0
249
+ }));
245
250
  }
246
251
  }
247
- class y extends E {
252
+ class y extends v {
248
253
  constructor(t, e = {}) {
249
- super(new U(t), e);
254
+ super(new b(t), e);
250
255
  }
251
256
  bind() {
252
257
  this.editor.instance.addEventListener(
253
258
  "paste",
254
259
  (t) => {
255
260
  this.onPaste(t);
256
- },
257
- !1
261
+ }
258
262
  ), this.editor.instance.addEventListener(
259
263
  "drop",
260
264
  (t) => {
261
- t.stopPropagation(), t.preventDefault(), this.onDrop(t);
262
- },
263
- !1
264
- ), this.editor.instance.addEventListener(
265
- "dragenter",
266
- (t) => {
267
- t.stopPropagation(), t.preventDefault();
265
+ t.preventDefault(), this.onDrop(t);
268
266
  }
269
267
  ), this.editor.instance.addEventListener(
270
268
  "dragover",
271
269
  (t) => {
272
- t.stopPropagation(), t.preventDefault();
270
+ t.preventDefault();
273
271
  }
274
272
  );
275
273
  }
276
274
  }
277
- function k(...n) {
275
+ function L(...n) {
278
276
  return new y(...n).bind();
279
277
  }
280
- class b {
278
+ class P {
281
279
  constructor(t) {
282
280
  o(this, "instance");
283
281
  this.instance = t;
@@ -299,41 +297,34 @@ class b {
299
297
  }), this.instance.dispatch({ selection: { anchor: e } });
300
298
  }
301
299
  }
302
- class h extends E {
300
+ class h extends v {
303
301
  constructor(t, e = {}) {
304
- super(new b(t), e);
302
+ super(new P(t), e);
305
303
  }
306
304
  bind() {
307
305
  this.editor.instance.dom.addEventListener(
308
306
  "paste",
309
307
  (t) => {
310
308
  this.onPaste(t);
311
- },
312
- !1
309
+ }
313
310
  ), this.editor.instance.dom.addEventListener(
314
311
  "drop",
315
312
  (t) => {
316
- t.stopPropagation(), t.preventDefault(), this.onDrop(t);
317
- },
318
- !1
319
- ), this.editor.instance.dom.addEventListener(
320
- "dragenter",
321
- (t) => {
322
- t.stopPropagation(), t.preventDefault();
313
+ t.preventDefault(), this.onDrop(t);
323
314
  }
324
315
  ), this.editor.instance.dom.addEventListener(
325
316
  "dragover",
326
317
  (t) => {
327
- t.stopPropagation(), t.preventDefault();
318
+ t.preventDefault();
328
319
  }
329
320
  );
330
321
  }
331
322
  }
332
- function I(...n) {
323
+ function S(...n) {
333
324
  return new h(...n).bind();
334
325
  }
335
326
  function M(n = {}) {
336
- return D.domEventHandlers({
327
+ return V.domEventHandlers({
337
328
  paste: (t, e) => {
338
329
  new h(e, n).onPaste(t);
339
330
  },
@@ -350,10 +341,10 @@ function M(n = {}) {
350
341
  }
351
342
  export {
352
343
  h as CodeMirrorInlineAttachmentAdapter,
353
- v as DEFAULT_OPTIONS,
354
- E as InlineAttachment,
344
+ E as DEFAULT_OPTIONS,
345
+ v as InlineAttachment,
355
346
  y as InputInlineAttachmentAdapter,
356
- k as attach,
357
- I as attachCodeMirror,
347
+ L as attach,
348
+ S as attachCodeMirror,
358
349
  M as inlineAttachmentExtension
359
350
  };
@@ -1 +1 @@
1
- (function(a,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@codemirror/view")):typeof define=="function"&&define.amd?define(["exports","@codemirror/view"],s):(a=typeof globalThis<"u"?globalThis:a||self,s(a.inlineAttacher={},a.CodemirrorView))})(this,function(a,s){"use strict";var L=Object.defineProperty;var M=(a,s,l)=>s in a?L(a,s,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[s]=l;var d=(a,s,l)=>(M(a,typeof s!="symbol"?s+"":s,l),l);const l={uploadUrl:"/upload",uploadMethod:"POST",uploadFieldName:"file",defaultExtension:"png",responseUrlKey:"url",allowedTypes:["image/jpeg","image/png","image/jpg","image/gif"],progressText:"![Uploading file...]()",urlText:"![{alt}]({url})",errorText:"Error uploading file",extraParams:{},extraHeaders:{},beforeFileUpload(){return!0},onFileReceived(){return!0},onFileUploadSucceed(){return!0},onFileUploadError(){return!0},onFileUploaded(){}};async function D({url:n,...t}){try{const e=await fetch(n,t);if(!e.ok)throw new Error(e.statusText);return{ok:!0,value:await e.json()}}catch(e){return{ok:!1,value:e}}}function T(n){return typeof n=="function"}function P(n,t="",e=""){const i=t.split(".");let r=n;for(const o of i)if(r&&typeof r=="object"&&o in r)r=r[o];else return e;return r!==void 0?r:e}class m{constructor(t,e){d(this,"options",l);d(this,"editor");d(this,"filename","");d(this,"lastValue","");this.editor=t,this.options={...l,...e}}async uploadFile(t){const{defaultExtension:e,remoteFilename:i,uploadFieldName:r,extraParams:o,extraHeaders:u,uploadUrl:p,uploadMethod:v,beforeFileUpload:h}=this.options,c=new FormData;let w=e;if(t.name){const[f]=t.name.match(/\.(.+)$/)||[];f&&(w=f)}const F=(i==null?void 0:i(t))||`image-${Date.now()}.${w}`;if(this.filename=F,c.append(r,t,F),Object.keys(o).forEach(f=>{c.append(f,o[f])}),!(h!=null&&h(c)))return;const{ok:I,value:A}=await D({url:p,method:v,body:c,headers:u});if(!I){this.onFileUploadError(A);return}this.onFileUploadSucceed(A)}isFileAllowed(t){const{allowedTypes:e}=this.options;return e.includes("*")||e.includes(t.type)}onFileUploadSucceed(t){var h,c;const{onFileUploadSucceed:e,urlText:i,responseUrlKey:r}=this.options;if(!(e!=null&&e(t))||!this.lastValue)return;const o=P(t,r)||"unknown URL";if(!o)return;const u=/!\[({[^}]+})]\(([^)]+)\)/,p=T(i)?i(o,t):i.replace(i.match(u)[1],this.filename).replace(i.match(u)[2],o),v=this.editor.getValue().replace(this.lastValue,p);this.editor.setValue(v),(c=(h=this.options).onFileUploaded)==null||c.call(h,o)}onFileUploadError(t){var i,r;if(!((r=(i=this.options).onFileUploadError)!=null&&r.call(i,t))||!this.lastValue)return;const e=this.editor.getValue().replace(this.lastValue,this.options.errorText);this.editor.setValue(e)}onFileInserted(t){var e,i;(i=(e=this.options).onFileReceived)!=null&&i.call(e,t)&&(this.lastValue=this.options.progressText,this.editor.insertValue(this.lastValue))}handleFiles(t){Array.from(t).forEach(e=>{this.isFileAllowed(e)&&(this.onFileInserted(e),this.uploadFile(e))})}onPaste(t){var e;t.preventDefault(),(e=t.clipboardData)!=null&&e.files.length&&this.handleFiles(t.clipboardData.files)}onDrop(t){var e;t.preventDefault(),(e=t.dataTransfer)!=null&&e.files.length&&this.handleFiles(t.dataTransfer.files)}}function V(n,t){const e=n.scrollTop;let i=0,r=!1,o;n.selectionStart||n.selectionStart===0?r="ff":document.selection&&(r="ie"),r==="ie"?(n.focus(),o=document.selection.createRange(),o.moveStart("character",-n.value.length),i=o.text.length):r==="ff"&&(i=n.selectionStart||0);const u=n.value.substring(0,i),p=n.value.substring(i,n.value.length);n.value=u+t+p,i+=t.length,r==="ie"?(n.focus(),o=document.selection.createRange(),o.moveStart("character",-n.value.length),o.moveStart("character",i),o.moveEnd("character",0),o.select()):r==="ff"&&(n.selectionStart=i,n.selectionEnd=i,n.focus()),n.scrollTop=e}class y{constructor(t){d(this,"instance");this.instance=t}getValue(){return this.instance.value}insertValue(t){V(this.instance,t)}setValue(t){this.instance.value=t}}class E extends m{constructor(t,e={}){super(new y(t),e)}bind(){this.editor.instance.addEventListener("paste",t=>{this.onPaste(t)},!1),this.editor.instance.addEventListener("drop",t=>{t.stopPropagation(),t.preventDefault(),this.onDrop(t)},!1),this.editor.instance.addEventListener("dragenter",t=>{t.stopPropagation(),t.preventDefault()}),this.editor.instance.addEventListener("dragover",t=>{t.stopPropagation(),t.preventDefault()})}}function x(...n){return new E(...n).bind()}class S{constructor(t){d(this,"instance");this.instance=t}getValue(){return this.instance.state.doc.toString()}insertValue(t){this.instance.dispatch(this.instance.state.replaceSelection(t))}setValue(t){const e=this.instance.state.selection.main.head;this.instance.dispatch({changes:{from:0,to:this.instance.state.doc.length,insert:t}}),this.instance.dispatch({selection:{anchor:e}})}}class g extends m{constructor(t,e={}){super(new S(t),e)}bind(){this.editor.instance.dom.addEventListener("paste",t=>{this.onPaste(t)},!1),this.editor.instance.dom.addEventListener("drop",t=>{t.stopPropagation(),t.preventDefault(),this.onDrop(t)},!1),this.editor.instance.dom.addEventListener("dragenter",t=>{t.stopPropagation(),t.preventDefault()}),this.editor.instance.dom.addEventListener("dragover",t=>{t.stopPropagation(),t.preventDefault()})}}function U(...n){return new g(...n).bind()}function b(n={}){return s.EditorView.domEventHandlers({paste:(t,e)=>{new g(e,n).onPaste(t)},drop:(t,e)=>{t.stopPropagation(),t.preventDefault(),new g(e,n).onDrop(t)},dragenter:t=>{t.stopPropagation(),t.preventDefault()},dragover:t=>{t.stopPropagation(),t.preventDefault()}})}a.CodeMirrorInlineAttachmentAdapter=g,a.DEFAULT_OPTIONS=l,a.InlineAttachment=m,a.InputInlineAttachmentAdapter=E,a.attach=x,a.attachCodeMirror=U,a.inlineAttachmentExtension=b,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@codemirror/view")):typeof define=="function"&&define.amd?define(["exports","@codemirror/view"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r.inlineAttacher={},r.CodemirrorView))})(this,function(r,o){"use strict";var L=Object.defineProperty;var M=(r,o,l)=>o in r?L(r,o,{enumerable:!0,configurable:!0,writable:!0,value:l}):r[o]=l;var d=(r,o,l)=>(M(r,typeof o!="symbol"?o+"":o,l),l);const l={uploadUrl:"/upload",uploadMethod:"POST",uploadFieldName:"file",defaultExtension:"png",responseUrlKey:"url",allowedTypes:["image/jpeg","image/png","image/jpg","image/gif"],progressText:"![Uploading file...]()",urlText:"![{alt}]({url})",errorText:"Error uploading file",extraParams:{},extraHeaders:{},beforeFileUpload(){return!0},onFileReceived(){return!0},onFileUploadSucceed(){return!0},onFileUploadError(){return!0},onFileUploaded(){}};async function T({url:n,...t}){try{const e=await fetch(n,t);if(!e.ok)throw new Error(e.statusText);return{ok:!0,value:await e.json()}}catch(e){return{ok:!1,value:e}}}function V(n){return typeof n=="function"}function y(n,t="",e=""){const i=t.split(".");let s=n;for(const a of i)if(s&&typeof s=="object"&&a in s)s=s[a];else return e;return s!==void 0?s:e}class g{constructor(t,e){d(this,"options",l);d(this,"editor");d(this,"filename","");d(this,"lastValue","");this.editor=t,this.options={...l,...e}}async uploadFile(t){const{defaultExtension:e,remoteFilename:i,uploadFieldName:s,extraParams:a,extraHeaders:u,uploadUrl:h,uploadMethod:E,beforeFileUpload:p}=this.options,c=new FormData;let w=e;if(t.name){const[f]=t.name.match(/\.(.+)$/)||[];f&&(w=f)}const F=(i==null?void 0:i(t))||`image-${Date.now()}.${w}`;if(this.filename=F,c.append(s,t,F),Object.keys(a).forEach(f=>{c.append(f,a[f])}),!(p!=null&&p(c)))return;const{ok:S,value:A}=await T({url:h,method:E,body:c,headers:u});if(!S){this.onFileUploadError(A);return}this.onFileUploadSucceed(A)}isFileAllowed(t){const{allowedTypes:e}=this.options;return e.includes("*")||e.includes(t.type)}onFileUploadSucceed(t){var p,c;const{onFileUploadSucceed:e,urlText:i,responseUrlKey:s}=this.options;if(!(e!=null&&e(t))||!this.lastValue)return;const a=y(t,s)||"unknown URL";if(!a)return;const u=/!\[({[^}]+})]\(([^)]+)\)/,h=V(i)?i(a,t):i.replace(i.match(u)[1],this.filename).replace(i.match(u)[2],a),E=this.editor.getValue().replace(this.lastValue,h);this.editor.setValue(E),(c=(p=this.options).onFileUploaded)==null||c.call(p,a)}onFileUploadError(t){var i,s;if(!((s=(i=this.options).onFileUploadError)!=null&&s.call(i,t))||!this.lastValue)return;const e=this.editor.getValue().replace(this.lastValue,this.options.errorText);this.editor.setValue(e)}onFileInserted(t){var e,i;(i=(e=this.options).onFileReceived)!=null&&i.call(e,t)&&(this.lastValue=this.options.progressText,this.editor.insertValue(this.lastValue))}handleFiles(t){Array.from(t).forEach(e=>{this.isFileAllowed(e)&&(this.onFileInserted(e),this.uploadFile(e))})}onPaste(t){var e;(e=t.clipboardData)!=null&&e.files.length&&this.handleFiles(t.clipboardData.files)}onDrop(t){var e;(e=t.dataTransfer)!=null&&e.files.length&&this.handleFiles(t.dataTransfer.files)}}function D(n,t){const e=n.scrollTop,i=n.selectionStart||0,{value:s}=n,a=s.slice(0,i),u=s.slice(i,s.length);n.value=a+t+u;const h=i+t.length;n.selectionStart=h,n.selectionEnd=h,n.scrollTop=e,n.focus()}class I{constructor(t){d(this,"instance");this.instance=t}getValue(){return this.instance.value}insertValue(t){D(this.instance,t),this.dispatchInputEvent()}setValue(t){this.instance.value=t,this.dispatchInputEvent()}dispatchInputEvent(){this.instance.dispatchEvent(new InputEvent("input",{bubbles:!0,cancelable:!0}))}}class v extends g{constructor(t,e={}){super(new I(t),e)}bind(){this.editor.instance.addEventListener("paste",t=>{this.onPaste(t)}),this.editor.instance.addEventListener("drop",t=>{t.preventDefault(),this.onDrop(t)}),this.editor.instance.addEventListener("dragover",t=>{t.preventDefault()})}}function b(...n){return new v(...n).bind()}class x{constructor(t){d(this,"instance");this.instance=t}getValue(){return this.instance.state.doc.toString()}insertValue(t){this.instance.dispatch(this.instance.state.replaceSelection(t))}setValue(t){const e=this.instance.state.selection.main.head;this.instance.dispatch({changes:{from:0,to:this.instance.state.doc.length,insert:t}}),this.instance.dispatch({selection:{anchor:e}})}}class m extends g{constructor(t,e={}){super(new x(t),e)}bind(){this.editor.instance.dom.addEventListener("paste",t=>{this.onPaste(t)}),this.editor.instance.dom.addEventListener("drop",t=>{t.preventDefault(),this.onDrop(t)}),this.editor.instance.dom.addEventListener("dragover",t=>{t.preventDefault()})}}function P(...n){return new m(...n).bind()}function U(n={}){return o.EditorView.domEventHandlers({paste:(t,e)=>{new m(e,n).onPaste(t)},drop:(t,e)=>{t.stopPropagation(),t.preventDefault(),new m(e,n).onDrop(t)},dragenter:t=>{t.stopPropagation(),t.preventDefault()},dragover:t=>{t.stopPropagation(),t.preventDefault()}})}r.CodeMirrorInlineAttachmentAdapter=m,r.DEFAULT_OPTIONS=l,r.InlineAttachment=g,r.InputInlineAttachmentAdapter=v,r.attach=b,r.attachCodeMirror=P,r.inlineAttachmentExtension=U,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inline-attacher",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "📎 A modern port from Inline Attachment",
5
5
  "type": "module",
6
6
  "files": [
@@ -34,36 +34,36 @@
34
34
  "url": "https://github.com/EastSun5566/inline-attachment/issues/new"
35
35
  },
36
36
  "homepage": "https://github.com/EastSun5566/inline-attachment",
37
- "packageManager": "pnpm@8.6.0",
38
37
  "engines": {
39
- "node": ">=16.0.0",
40
- "pnpm": ">=7.0.0"
38
+ "node": ">=16.0.0"
41
39
  },
42
40
  "peerDependencies": {
43
41
  "@codemirror/view": ">=6.0.0"
44
42
  },
45
43
  "devDependencies": {
46
- "@codemirror/state": "^6.2.1",
47
- "@types/node": "^20.5.0",
48
- "@typescript-eslint/eslint-plugin": "^6.4.0",
49
- "@typescript-eslint/parser": "^6.4.0",
50
- "eslint": "^8.47.0",
44
+ "@codemirror/state": "^6.4.1",
45
+ "@types/node": "^20.16.11",
46
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
47
+ "@typescript-eslint/parser": "^6.21.0",
48
+ "eslint": "^8.57.1",
51
49
  "eslint-config-airbnb-base": "^15.0.0",
52
50
  "eslint-config-airbnb-typescript": "^17.1.0",
53
- "eslint-plugin-import": "^2.28.0",
54
- "rimraf": "^5.0.1",
55
- "typescript": "^5.1.6",
56
- "vite": "^4.4.9"
51
+ "eslint-plugin-import": "^2.31.0",
52
+ "rimraf": "^5.0.10",
53
+ "typescript": "^5.6.3",
54
+ "vite": "^4.5.5"
57
55
  },
58
56
  "dependencies": {
59
- "@codemirror/view": "^6.16.0"
57
+ "@codemirror/view": "^6.34.1"
60
58
  },
61
59
  "scripts": {
62
60
  "dev": "vite",
63
61
  "build": "rimraf dist && tsc && vite build",
64
62
  "preview": "vite preview",
65
63
  "playground:dev": "pnpm -C playground dev",
64
+ "playground:deploy": "pnpm -C playground deploy",
66
65
  "lint": "eslint --fix --ext .ts src",
67
- "release": "pnpx standard-version && git push --follow-tags && pnpm publish"
66
+ "release": "pnpx standard-version && git push --follow-tags && pnpm publish && pnpm dlx jsr publish",
67
+ "size-check": "pnpx vite-bundle-visualizer"
68
68
  }
69
69
  }