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.d.ts
CHANGED
|
@@ -135,6 +135,7 @@ export interface Options {
|
|
|
135
135
|
mimeTypes?: string[];
|
|
136
136
|
batch?: boolean;
|
|
137
137
|
onInsertFile: (file: File | File[]) => Promise<string | string[]>;
|
|
138
|
+
onRemoveFile?: (info: { url: string; filename: string; file: File }) => void;
|
|
138
139
|
};
|
|
139
140
|
|
|
140
141
|
// Callbacks
|
package/dist/overtype.esm.js
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
|
|
@@ -5172,6 +5172,7 @@ var _OverType = class _OverType {
|
|
|
5172
5172
|
return;
|
|
5173
5173
|
}
|
|
5174
5174
|
this._fileUploadCounter = 0;
|
|
5175
|
+
this._uploadedFiles = /* @__PURE__ */ new Map();
|
|
5175
5176
|
this._boundHandleFilePaste = this._handleFilePaste.bind(this);
|
|
5176
5177
|
this._boundHandleFileDrop = this._handleFileDrop.bind(this);
|
|
5177
5178
|
this._boundHandleDragOver = this._handleDragOver.bind(this);
|
|
@@ -5180,6 +5181,53 @@ var _OverType = class _OverType {
|
|
|
5180
5181
|
this.textarea.addEventListener("dragover", this._boundHandleDragOver);
|
|
5181
5182
|
this.fileUploadInitialized = true;
|
|
5182
5183
|
}
|
|
5184
|
+
/**
|
|
5185
|
+
* Extract URLs from markdown link syntax: [text](url) or .
|
|
5186
|
+
* @private
|
|
5187
|
+
*/
|
|
5188
|
+
_extractMarkdownUrls(text) {
|
|
5189
|
+
const urls = [];
|
|
5190
|
+
const re = /!?\[[^\]]*\]\(([^)\s]+)/g;
|
|
5191
|
+
let m;
|
|
5192
|
+
while ((m = re.exec(text)) !== null)
|
|
5193
|
+
urls.push(m[1]);
|
|
5194
|
+
return urls;
|
|
5195
|
+
}
|
|
5196
|
+
/**
|
|
5197
|
+
* Track URLs that were just inserted, pairing each with the source File.
|
|
5198
|
+
* If multiple URLs appear in one inserted block, all get associated with
|
|
5199
|
+
* the same file (rare; happens if onInsertFile returns several links).
|
|
5200
|
+
* @private
|
|
5201
|
+
*/
|
|
5202
|
+
_trackInsertedUrls(insertedText, file) {
|
|
5203
|
+
if (!this._uploadedFiles || !file || !insertedText)
|
|
5204
|
+
return;
|
|
5205
|
+
for (const url of this._extractMarkdownUrls(insertedText)) {
|
|
5206
|
+
this._uploadedFiles.set(url, { filename: file.name, file });
|
|
5207
|
+
}
|
|
5208
|
+
}
|
|
5209
|
+
/**
|
|
5210
|
+
* Diff the tracked-URL set against the current value and fire
|
|
5211
|
+
* fileUpload.onRemoveFile for any URL no longer present.
|
|
5212
|
+
* @private
|
|
5213
|
+
*/
|
|
5214
|
+
_checkForRemovedUploads() {
|
|
5215
|
+
var _a;
|
|
5216
|
+
if (!this._uploadedFiles || this._uploadedFiles.size === 0)
|
|
5217
|
+
return;
|
|
5218
|
+
const cb = (_a = this.options.fileUpload) == null ? void 0 : _a.onRemoveFile;
|
|
5219
|
+
const value = this.textarea.value;
|
|
5220
|
+
const removed = [];
|
|
5221
|
+
for (const [url, info] of this._uploadedFiles) {
|
|
5222
|
+
if (!value.includes(url))
|
|
5223
|
+
removed.push({ url, info });
|
|
5224
|
+
}
|
|
5225
|
+
for (const { url, info } of removed) {
|
|
5226
|
+
this._uploadedFiles.delete(url);
|
|
5227
|
+
if (cb)
|
|
5228
|
+
cb({ url, filename: info.filename, file: info.file });
|
|
5229
|
+
}
|
|
5230
|
+
}
|
|
5183
5231
|
_handleFilePaste(e) {
|
|
5184
5232
|
var _a, _b;
|
|
5185
5233
|
if (!((_b = (_a = e == null ? void 0 : e.clipboardData) == null ? void 0 : _a.files) == null ? void 0 : _b.length))
|
|
@@ -5212,6 +5260,7 @@ var _OverType = class _OverType {
|
|
|
5212
5260
|
}
|
|
5213
5261
|
this.options.fileUpload.onInsertFile(file).then((text) => {
|
|
5214
5262
|
this.textarea.value = this.textarea.value.replace(placeholder, text);
|
|
5263
|
+
this._trackInsertedUrls(text, file);
|
|
5215
5264
|
this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
|
|
5216
5265
|
}, (error) => {
|
|
5217
5266
|
console.error("OverType: File upload failed", error);
|
|
@@ -5224,6 +5273,7 @@ var _OverType = class _OverType {
|
|
|
5224
5273
|
const texts = Array.isArray(result) ? result : [result];
|
|
5225
5274
|
texts.forEach((text, index) => {
|
|
5226
5275
|
this.textarea.value = this.textarea.value.replace(files[index].placeholder, text);
|
|
5276
|
+
this._trackInsertedUrls(text, files[index].file);
|
|
5227
5277
|
});
|
|
5228
5278
|
this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
|
|
5229
5279
|
}, (error) => {
|
|
@@ -5245,6 +5295,7 @@ var _OverType = class _OverType {
|
|
|
5245
5295
|
this._boundHandleFilePaste = null;
|
|
5246
5296
|
this._boundHandleFileDrop = null;
|
|
5247
5297
|
this._boundHandleDragOver = null;
|
|
5298
|
+
this._uploadedFiles = null;
|
|
5248
5299
|
this.fileUploadInitialized = false;
|
|
5249
5300
|
}
|
|
5250
5301
|
insertAtCursor(text) {
|
|
@@ -5289,9 +5340,12 @@ var _OverType = class _OverType {
|
|
|
5289
5340
|
* @private
|
|
5290
5341
|
*/
|
|
5291
5342
|
_notifyChange() {
|
|
5292
|
-
if (!this.
|
|
5343
|
+
if (!this.initialized)
|
|
5293
5344
|
return;
|
|
5294
|
-
this.
|
|
5345
|
+
this._checkForRemovedUploads();
|
|
5346
|
+
if (this.options.onChange) {
|
|
5347
|
+
this.options.onChange(this.textarea.value, this);
|
|
5348
|
+
}
|
|
5295
5349
|
}
|
|
5296
5350
|
/**
|
|
5297
5351
|
* Apply background styling to code blocks
|