overtype 2.3.9 → 2.3.10
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 +72 -8
- package/dist/overtype-webcomponent.esm.js +57 -3
- package/dist/overtype-webcomponent.esm.js.map +2 -2
- package/dist/overtype-webcomponent.js +57 -3
- package/dist/overtype-webcomponent.js.map +2 -2
- package/dist/overtype-webcomponent.min.js +17 -17
- package/dist/overtype.cjs +57 -3
- package/dist/overtype.cjs.map +2 -2
- package/dist/overtype.d.ts +1 -0
- package/dist/overtype.esm.js +57 -3
- package/dist/overtype.esm.js.map +2 -2
- package/dist/overtype.js +57 -3
- package/dist/overtype.js.map +2 -2
- package/dist/overtype.min.js +9 -9
- package/package.json +1 -1
- package/src/overtype.d.ts +1 -0
- package/src/overtype.js +53 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v2.3.
|
|
2
|
+
* OverType v2.3.10
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author David Miranda
|
|
@@ -5191,6 +5191,7 @@ ${blockSuffix}` : suffix;
|
|
|
5191
5191
|
return;
|
|
5192
5192
|
}
|
|
5193
5193
|
this._fileUploadCounter = 0;
|
|
5194
|
+
this._uploadedFiles = /* @__PURE__ */ new Map();
|
|
5194
5195
|
this._boundHandleFilePaste = this._handleFilePaste.bind(this);
|
|
5195
5196
|
this._boundHandleFileDrop = this._handleFileDrop.bind(this);
|
|
5196
5197
|
this._boundHandleDragOver = this._handleDragOver.bind(this);
|
|
@@ -5199,6 +5200,53 @@ ${blockSuffix}` : suffix;
|
|
|
5199
5200
|
this.textarea.addEventListener("dragover", this._boundHandleDragOver);
|
|
5200
5201
|
this.fileUploadInitialized = true;
|
|
5201
5202
|
}
|
|
5203
|
+
/**
|
|
5204
|
+
* Extract URLs from markdown link syntax: [text](url) or .
|
|
5205
|
+
* @private
|
|
5206
|
+
*/
|
|
5207
|
+
_extractMarkdownUrls(text) {
|
|
5208
|
+
const urls = [];
|
|
5209
|
+
const re = /!?\[[^\]]*\]\(([^)\s]+)/g;
|
|
5210
|
+
let m;
|
|
5211
|
+
while ((m = re.exec(text)) !== null)
|
|
5212
|
+
urls.push(m[1]);
|
|
5213
|
+
return urls;
|
|
5214
|
+
}
|
|
5215
|
+
/**
|
|
5216
|
+
* Track URLs that were just inserted, pairing each with the source File.
|
|
5217
|
+
* If multiple URLs appear in one inserted block, all get associated with
|
|
5218
|
+
* the same file (rare; happens if onInsertFile returns several links).
|
|
5219
|
+
* @private
|
|
5220
|
+
*/
|
|
5221
|
+
_trackInsertedUrls(insertedText, file) {
|
|
5222
|
+
if (!this._uploadedFiles || !file || !insertedText)
|
|
5223
|
+
return;
|
|
5224
|
+
for (const url of this._extractMarkdownUrls(insertedText)) {
|
|
5225
|
+
this._uploadedFiles.set(url, { filename: file.name, file });
|
|
5226
|
+
}
|
|
5227
|
+
}
|
|
5228
|
+
/**
|
|
5229
|
+
* Diff the tracked-URL set against the current value and fire
|
|
5230
|
+
* fileUpload.onRemoveFile for any URL no longer present.
|
|
5231
|
+
* @private
|
|
5232
|
+
*/
|
|
5233
|
+
_checkForRemovedUploads() {
|
|
5234
|
+
var _a;
|
|
5235
|
+
if (!this._uploadedFiles || this._uploadedFiles.size === 0)
|
|
5236
|
+
return;
|
|
5237
|
+
const cb = (_a = this.options.fileUpload) == null ? void 0 : _a.onRemoveFile;
|
|
5238
|
+
const value = this.textarea.value;
|
|
5239
|
+
const removed = [];
|
|
5240
|
+
for (const [url, info] of this._uploadedFiles) {
|
|
5241
|
+
if (!value.includes(url))
|
|
5242
|
+
removed.push({ url, info });
|
|
5243
|
+
}
|
|
5244
|
+
for (const { url, info } of removed) {
|
|
5245
|
+
this._uploadedFiles.delete(url);
|
|
5246
|
+
if (cb)
|
|
5247
|
+
cb({ url, filename: info.filename, file: info.file });
|
|
5248
|
+
}
|
|
5249
|
+
}
|
|
5202
5250
|
_handleFilePaste(e) {
|
|
5203
5251
|
var _a, _b;
|
|
5204
5252
|
if (!((_b = (_a = e == null ? void 0 : e.clipboardData) == null ? void 0 : _a.files) == null ? void 0 : _b.length))
|
|
@@ -5231,6 +5279,7 @@ ${blockSuffix}` : suffix;
|
|
|
5231
5279
|
}
|
|
5232
5280
|
this.options.fileUpload.onInsertFile(file).then((text) => {
|
|
5233
5281
|
this.textarea.value = this.textarea.value.replace(placeholder, text);
|
|
5282
|
+
this._trackInsertedUrls(text, file);
|
|
5234
5283
|
this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
|
|
5235
5284
|
}, (error) => {
|
|
5236
5285
|
console.error("OverType: File upload failed", error);
|
|
@@ -5243,6 +5292,7 @@ ${blockSuffix}` : suffix;
|
|
|
5243
5292
|
const texts = Array.isArray(result) ? result : [result];
|
|
5244
5293
|
texts.forEach((text, index) => {
|
|
5245
5294
|
this.textarea.value = this.textarea.value.replace(files[index].placeholder, text);
|
|
5295
|
+
this._trackInsertedUrls(text, files[index].file);
|
|
5246
5296
|
});
|
|
5247
5297
|
this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
|
|
5248
5298
|
}, (error) => {
|
|
@@ -5264,6 +5314,7 @@ ${blockSuffix}` : suffix;
|
|
|
5264
5314
|
this._boundHandleFilePaste = null;
|
|
5265
5315
|
this._boundHandleFileDrop = null;
|
|
5266
5316
|
this._boundHandleDragOver = null;
|
|
5317
|
+
this._uploadedFiles = null;
|
|
5267
5318
|
this.fileUploadInitialized = false;
|
|
5268
5319
|
}
|
|
5269
5320
|
insertAtCursor(text) {
|
|
@@ -5308,9 +5359,12 @@ ${blockSuffix}` : suffix;
|
|
|
5308
5359
|
* @private
|
|
5309
5360
|
*/
|
|
5310
5361
|
_notifyChange() {
|
|
5311
|
-
if (!this.
|
|
5362
|
+
if (!this.initialized)
|
|
5312
5363
|
return;
|
|
5313
|
-
this.
|
|
5364
|
+
this._checkForRemovedUploads();
|
|
5365
|
+
if (this.options.onChange) {
|
|
5366
|
+
this.options.onChange(this.textarea.value, this);
|
|
5367
|
+
}
|
|
5314
5368
|
}
|
|
5315
5369
|
/**
|
|
5316
5370
|
* Apply background styling to code blocks
|