overtype 2.3.8 → 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 +58 -3
- package/dist/overtype.js.map +2 -2
- package/dist/overtype.min.js +10 -9
- package/package.json +1 -1
- package/src/overtype.d.ts +1 -0
- package/src/overtype.js +53 -3
package/dist/overtype.cjs
CHANGED
|
@@ -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
|
|
@@ -5195,6 +5195,7 @@ var _OverType = class _OverType {
|
|
|
5195
5195
|
return;
|
|
5196
5196
|
}
|
|
5197
5197
|
this._fileUploadCounter = 0;
|
|
5198
|
+
this._uploadedFiles = /* @__PURE__ */ new Map();
|
|
5198
5199
|
this._boundHandleFilePaste = this._handleFilePaste.bind(this);
|
|
5199
5200
|
this._boundHandleFileDrop = this._handleFileDrop.bind(this);
|
|
5200
5201
|
this._boundHandleDragOver = this._handleDragOver.bind(this);
|
|
@@ -5203,6 +5204,53 @@ var _OverType = class _OverType {
|
|
|
5203
5204
|
this.textarea.addEventListener("dragover", this._boundHandleDragOver);
|
|
5204
5205
|
this.fileUploadInitialized = true;
|
|
5205
5206
|
}
|
|
5207
|
+
/**
|
|
5208
|
+
* Extract URLs from markdown link syntax: [text](url) or .
|
|
5209
|
+
* @private
|
|
5210
|
+
*/
|
|
5211
|
+
_extractMarkdownUrls(text) {
|
|
5212
|
+
const urls = [];
|
|
5213
|
+
const re = /!?\[[^\]]*\]\(([^)\s]+)/g;
|
|
5214
|
+
let m;
|
|
5215
|
+
while ((m = re.exec(text)) !== null)
|
|
5216
|
+
urls.push(m[1]);
|
|
5217
|
+
return urls;
|
|
5218
|
+
}
|
|
5219
|
+
/**
|
|
5220
|
+
* Track URLs that were just inserted, pairing each with the source File.
|
|
5221
|
+
* If multiple URLs appear in one inserted block, all get associated with
|
|
5222
|
+
* the same file (rare; happens if onInsertFile returns several links).
|
|
5223
|
+
* @private
|
|
5224
|
+
*/
|
|
5225
|
+
_trackInsertedUrls(insertedText, file) {
|
|
5226
|
+
if (!this._uploadedFiles || !file || !insertedText)
|
|
5227
|
+
return;
|
|
5228
|
+
for (const url of this._extractMarkdownUrls(insertedText)) {
|
|
5229
|
+
this._uploadedFiles.set(url, { filename: file.name, file });
|
|
5230
|
+
}
|
|
5231
|
+
}
|
|
5232
|
+
/**
|
|
5233
|
+
* Diff the tracked-URL set against the current value and fire
|
|
5234
|
+
* fileUpload.onRemoveFile for any URL no longer present.
|
|
5235
|
+
* @private
|
|
5236
|
+
*/
|
|
5237
|
+
_checkForRemovedUploads() {
|
|
5238
|
+
var _a;
|
|
5239
|
+
if (!this._uploadedFiles || this._uploadedFiles.size === 0)
|
|
5240
|
+
return;
|
|
5241
|
+
const cb = (_a = this.options.fileUpload) == null ? void 0 : _a.onRemoveFile;
|
|
5242
|
+
const value = this.textarea.value;
|
|
5243
|
+
const removed = [];
|
|
5244
|
+
for (const [url, info] of this._uploadedFiles) {
|
|
5245
|
+
if (!value.includes(url))
|
|
5246
|
+
removed.push({ url, info });
|
|
5247
|
+
}
|
|
5248
|
+
for (const { url, info } of removed) {
|
|
5249
|
+
this._uploadedFiles.delete(url);
|
|
5250
|
+
if (cb)
|
|
5251
|
+
cb({ url, filename: info.filename, file: info.file });
|
|
5252
|
+
}
|
|
5253
|
+
}
|
|
5206
5254
|
_handleFilePaste(e) {
|
|
5207
5255
|
var _a, _b;
|
|
5208
5256
|
if (!((_b = (_a = e == null ? void 0 : e.clipboardData) == null ? void 0 : _a.files) == null ? void 0 : _b.length))
|
|
@@ -5235,6 +5283,7 @@ var _OverType = class _OverType {
|
|
|
5235
5283
|
}
|
|
5236
5284
|
this.options.fileUpload.onInsertFile(file).then((text) => {
|
|
5237
5285
|
this.textarea.value = this.textarea.value.replace(placeholder, text);
|
|
5286
|
+
this._trackInsertedUrls(text, file);
|
|
5238
5287
|
this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
|
|
5239
5288
|
}, (error) => {
|
|
5240
5289
|
console.error("OverType: File upload failed", error);
|
|
@@ -5247,6 +5296,7 @@ var _OverType = class _OverType {
|
|
|
5247
5296
|
const texts = Array.isArray(result) ? result : [result];
|
|
5248
5297
|
texts.forEach((text, index) => {
|
|
5249
5298
|
this.textarea.value = this.textarea.value.replace(files[index].placeholder, text);
|
|
5299
|
+
this._trackInsertedUrls(text, files[index].file);
|
|
5250
5300
|
});
|
|
5251
5301
|
this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
|
|
5252
5302
|
}, (error) => {
|
|
@@ -5268,6 +5318,7 @@ var _OverType = class _OverType {
|
|
|
5268
5318
|
this._boundHandleFilePaste = null;
|
|
5269
5319
|
this._boundHandleFileDrop = null;
|
|
5270
5320
|
this._boundHandleDragOver = null;
|
|
5321
|
+
this._uploadedFiles = null;
|
|
5271
5322
|
this.fileUploadInitialized = false;
|
|
5272
5323
|
}
|
|
5273
5324
|
insertAtCursor(text) {
|
|
@@ -5312,9 +5363,12 @@ var _OverType = class _OverType {
|
|
|
5312
5363
|
* @private
|
|
5313
5364
|
*/
|
|
5314
5365
|
_notifyChange() {
|
|
5315
|
-
if (!this.
|
|
5366
|
+
if (!this.initialized)
|
|
5316
5367
|
return;
|
|
5317
|
-
this.
|
|
5368
|
+
this._checkForRemovedUploads();
|
|
5369
|
+
if (this.options.onChange) {
|
|
5370
|
+
this.options.onChange(this.textarea.value, this);
|
|
5371
|
+
}
|
|
5318
5372
|
}
|
|
5319
5373
|
/**
|
|
5320
5374
|
* Apply background styling to code blocks
|