@textbus/platform-browser 4.3.2 → 4.3.3
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/bundles/index.esm.js +112 -100
- package/bundles/index.js +112 -100
- package/bundles/magic-input.d.ts +3 -1
- package/bundles/native-input.d.ts +3 -1
- package/package.json +3 -3
package/bundles/index.esm.js
CHANGED
@@ -1283,61 +1283,67 @@ let MagicInput = class MagicInput extends Input {
|
|
1283
1283
|
}
|
1284
1284
|
handleDefaultActions(textarea) {
|
1285
1285
|
this.subscription.add(fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
|
1286
|
-
|
1287
|
-
if (!selection.isSelected) {
|
1288
|
-
return;
|
1289
|
-
}
|
1290
|
-
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1291
|
-
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1292
|
-
if (typeof content === 'object') {
|
1293
|
-
const clipboardData = ev.clipboardData;
|
1294
|
-
const nativeSelection = document.getSelection();
|
1295
|
-
const range = nativeSelection.getRangeAt(0);
|
1296
|
-
const div = document.createElement('div');
|
1297
|
-
const fragment = range.cloneContents();
|
1298
|
-
div.append(fragment);
|
1299
|
-
clipboardData.setData('text/html', div.innerHTML);
|
1300
|
-
clipboardData.setData('text', div.innerText);
|
1301
|
-
ev.preventDefault();
|
1302
|
-
}
|
1303
|
-
}
|
1286
|
+
this.copyHandler(ev);
|
1304
1287
|
}), fromEvent(textarea, 'paste').subscribe(ev => {
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
});
|
1288
|
+
this.pasteHandler(ev);
|
1289
|
+
}));
|
1290
|
+
}
|
1291
|
+
copyHandler(ev) {
|
1292
|
+
const selection = this.selection;
|
1293
|
+
if (!selection.isSelected) {
|
1294
|
+
return;
|
1295
|
+
}
|
1296
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1297
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1298
|
+
if (typeof content === 'object') {
|
1299
|
+
const clipboardData = ev.clipboardData;
|
1300
|
+
const nativeSelection = document.getSelection();
|
1301
|
+
const range = nativeSelection.getRangeAt(0);
|
1302
|
+
const div = document.createElement('div');
|
1303
|
+
const fragment = range.cloneContents();
|
1304
|
+
div.append(fragment);
|
1305
|
+
clipboardData.setData('text/html', div.innerHTML);
|
1306
|
+
clipboardData.setData('text', div.innerText);
|
1325
1307
|
ev.preventDefault();
|
1326
|
-
return;
|
1327
1308
|
}
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1309
|
+
}
|
1310
|
+
}
|
1311
|
+
pasteHandler(ev) {
|
1312
|
+
const text = ev.clipboardData.getData('Text');
|
1313
|
+
const types = Array.from(ev.clipboardData.types || []);
|
1314
|
+
const files = Array.from(ev.clipboardData.files);
|
1315
|
+
if (types.every(type => type === 'Files') && files.length) {
|
1316
|
+
Promise.all(files.filter(i => {
|
1317
|
+
return /image/i.test(i.type);
|
1318
|
+
}).map(item => {
|
1319
|
+
const reader = new FileReader();
|
1320
|
+
return new Promise(resolve => {
|
1321
|
+
reader.onload = (event) => {
|
1322
|
+
resolve(event.target.result);
|
1323
|
+
};
|
1324
|
+
reader.readAsDataURL(item);
|
1325
|
+
});
|
1326
|
+
})).then(urls => {
|
1327
|
+
const html = urls.map(i => {
|
1328
|
+
return `<img src=${i}>`;
|
1329
|
+
}).join('');
|
1330
|
+
this.paste(html, text);
|
1337
1331
|
});
|
1338
|
-
|
1332
|
+
ev.preventDefault();
|
1333
|
+
return;
|
1334
|
+
}
|
1335
|
+
const div = this.doc.createElement('div');
|
1336
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
1337
|
+
div.contentEditable = 'true';
|
1338
|
+
this.doc.body.appendChild(div);
|
1339
|
+
div.focus();
|
1340
|
+
setTimeout(() => {
|
1341
|
+
this.doc.body.removeChild(div);
|
1342
|
+
div.style.cssText = '';
|
1343
|
+
this.paste(div, text);
|
1344
|
+
});
|
1339
1345
|
}
|
1340
|
-
|
1346
|
+
paste(dom, text) {
|
1341
1347
|
const slot = this.parser.parse(dom, new Slot([
|
1342
1348
|
ContentType.BlockComponent,
|
1343
1349
|
ContentType.InlineComponent,
|
@@ -1886,61 +1892,67 @@ let NativeInput = class NativeInput extends Input {
|
|
1886
1892
|
}
|
1887
1893
|
handleDefaultActions(textarea) {
|
1888
1894
|
this.subscription.add(fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
|
1889
|
-
|
1890
|
-
if (!selection.isSelected) {
|
1891
|
-
return;
|
1892
|
-
}
|
1893
|
-
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1894
|
-
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1895
|
-
if (typeof content === 'object') {
|
1896
|
-
const clipboardData = ev.clipboardData;
|
1897
|
-
const nativeSelection = document.getSelection();
|
1898
|
-
const range = nativeSelection.getRangeAt(0);
|
1899
|
-
const div = document.createElement('div');
|
1900
|
-
const fragment = range.cloneContents();
|
1901
|
-
div.append(fragment);
|
1902
|
-
clipboardData.setData('text/html', div.innerHTML);
|
1903
|
-
clipboardData.setData('text', div.innerText);
|
1904
|
-
ev.preventDefault();
|
1905
|
-
}
|
1906
|
-
}
|
1895
|
+
this.copyHandler(ev);
|
1907
1896
|
}), fromEvent(textarea, 'paste').subscribe(ev => {
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
});
|
1897
|
+
this.pasteHandler(ev);
|
1898
|
+
}));
|
1899
|
+
}
|
1900
|
+
copyHandler(ev) {
|
1901
|
+
const selection = this.selection;
|
1902
|
+
if (!selection.isSelected) {
|
1903
|
+
return;
|
1904
|
+
}
|
1905
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1906
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1907
|
+
if (typeof content === 'object') {
|
1908
|
+
const clipboardData = ev.clipboardData;
|
1909
|
+
const nativeSelection = document.getSelection();
|
1910
|
+
const range = nativeSelection.getRangeAt(0);
|
1911
|
+
const div = document.createElement('div');
|
1912
|
+
const fragment = range.cloneContents();
|
1913
|
+
div.append(fragment);
|
1914
|
+
clipboardData.setData('text/html', div.innerHTML);
|
1915
|
+
clipboardData.setData('text', div.innerText);
|
1928
1916
|
ev.preventDefault();
|
1929
|
-
return;
|
1930
1917
|
}
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1918
|
+
}
|
1919
|
+
}
|
1920
|
+
pasteHandler(ev) {
|
1921
|
+
const text = ev.clipboardData.getData('Text');
|
1922
|
+
const types = Array.from(ev.clipboardData.types || []);
|
1923
|
+
const files = Array.from(ev.clipboardData.files);
|
1924
|
+
if (types.every(type => type === 'Files') && files.length) {
|
1925
|
+
Promise.all(files.filter(i => {
|
1926
|
+
return /image/i.test(i.type);
|
1927
|
+
}).map(item => {
|
1928
|
+
const reader = new FileReader();
|
1929
|
+
return new Promise(resolve => {
|
1930
|
+
reader.onload = (event) => {
|
1931
|
+
resolve(event.target.result);
|
1932
|
+
};
|
1933
|
+
reader.readAsDataURL(item);
|
1934
|
+
});
|
1935
|
+
})).then(urls => {
|
1936
|
+
const html = urls.map(i => {
|
1937
|
+
return `<img src=${i}>`;
|
1938
|
+
}).join('');
|
1939
|
+
this.paste(html, text);
|
1940
1940
|
});
|
1941
|
-
|
1941
|
+
ev.preventDefault();
|
1942
|
+
return;
|
1943
|
+
}
|
1944
|
+
const div = document.createElement('div');
|
1945
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
1946
|
+
div.contentEditable = 'true';
|
1947
|
+
document.body.appendChild(div);
|
1948
|
+
div.focus();
|
1949
|
+
setTimeout(() => {
|
1950
|
+
document.body.removeChild(div);
|
1951
|
+
div.style.cssText = '';
|
1952
|
+
this.paste(div, text);
|
1953
|
+
});
|
1942
1954
|
}
|
1943
|
-
|
1955
|
+
paste(dom, text) {
|
1944
1956
|
const slot = this.parser.parse(dom, new Slot([
|
1945
1957
|
ContentType.BlockComponent,
|
1946
1958
|
ContentType.InlineComponent,
|
package/bundles/index.js
CHANGED
@@ -1285,61 +1285,67 @@ exports.MagicInput = class MagicInput extends Input {
|
|
1285
1285
|
}
|
1286
1286
|
handleDefaultActions(textarea) {
|
1287
1287
|
this.subscription.add(stream.fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
|
1288
|
-
|
1289
|
-
if (!selection.isSelected) {
|
1290
|
-
return;
|
1291
|
-
}
|
1292
|
-
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1293
|
-
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1294
|
-
if (typeof content === 'object') {
|
1295
|
-
const clipboardData = ev.clipboardData;
|
1296
|
-
const nativeSelection = document.getSelection();
|
1297
|
-
const range = nativeSelection.getRangeAt(0);
|
1298
|
-
const div = document.createElement('div');
|
1299
|
-
const fragment = range.cloneContents();
|
1300
|
-
div.append(fragment);
|
1301
|
-
clipboardData.setData('text/html', div.innerHTML);
|
1302
|
-
clipboardData.setData('text', div.innerText);
|
1303
|
-
ev.preventDefault();
|
1304
|
-
}
|
1305
|
-
}
|
1288
|
+
this.copyHandler(ev);
|
1306
1289
|
}), stream.fromEvent(textarea, 'paste').subscribe(ev => {
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
});
|
1290
|
+
this.pasteHandler(ev);
|
1291
|
+
}));
|
1292
|
+
}
|
1293
|
+
copyHandler(ev) {
|
1294
|
+
const selection = this.selection;
|
1295
|
+
if (!selection.isSelected) {
|
1296
|
+
return;
|
1297
|
+
}
|
1298
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1299
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1300
|
+
if (typeof content === 'object') {
|
1301
|
+
const clipboardData = ev.clipboardData;
|
1302
|
+
const nativeSelection = document.getSelection();
|
1303
|
+
const range = nativeSelection.getRangeAt(0);
|
1304
|
+
const div = document.createElement('div');
|
1305
|
+
const fragment = range.cloneContents();
|
1306
|
+
div.append(fragment);
|
1307
|
+
clipboardData.setData('text/html', div.innerHTML);
|
1308
|
+
clipboardData.setData('text', div.innerText);
|
1327
1309
|
ev.preventDefault();
|
1328
|
-
return;
|
1329
1310
|
}
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1311
|
+
}
|
1312
|
+
}
|
1313
|
+
pasteHandler(ev) {
|
1314
|
+
const text = ev.clipboardData.getData('Text');
|
1315
|
+
const types = Array.from(ev.clipboardData.types || []);
|
1316
|
+
const files = Array.from(ev.clipboardData.files);
|
1317
|
+
if (types.every(type => type === 'Files') && files.length) {
|
1318
|
+
Promise.all(files.filter(i => {
|
1319
|
+
return /image/i.test(i.type);
|
1320
|
+
}).map(item => {
|
1321
|
+
const reader = new FileReader();
|
1322
|
+
return new Promise(resolve => {
|
1323
|
+
reader.onload = (event) => {
|
1324
|
+
resolve(event.target.result);
|
1325
|
+
};
|
1326
|
+
reader.readAsDataURL(item);
|
1327
|
+
});
|
1328
|
+
})).then(urls => {
|
1329
|
+
const html = urls.map(i => {
|
1330
|
+
return `<img src=${i}>`;
|
1331
|
+
}).join('');
|
1332
|
+
this.paste(html, text);
|
1339
1333
|
});
|
1340
|
-
|
1334
|
+
ev.preventDefault();
|
1335
|
+
return;
|
1336
|
+
}
|
1337
|
+
const div = this.doc.createElement('div');
|
1338
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
1339
|
+
div.contentEditable = 'true';
|
1340
|
+
this.doc.body.appendChild(div);
|
1341
|
+
div.focus();
|
1342
|
+
setTimeout(() => {
|
1343
|
+
this.doc.body.removeChild(div);
|
1344
|
+
div.style.cssText = '';
|
1345
|
+
this.paste(div, text);
|
1346
|
+
});
|
1341
1347
|
}
|
1342
|
-
|
1348
|
+
paste(dom, text) {
|
1343
1349
|
const slot = this.parser.parse(dom, new core$1.Slot([
|
1344
1350
|
core$1.ContentType.BlockComponent,
|
1345
1351
|
core$1.ContentType.InlineComponent,
|
@@ -1888,61 +1894,67 @@ exports.NativeInput = class NativeInput extends Input {
|
|
1888
1894
|
}
|
1889
1895
|
handleDefaultActions(textarea) {
|
1890
1896
|
this.subscription.add(stream.fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
|
1891
|
-
|
1892
|
-
if (!selection.isSelected) {
|
1893
|
-
return;
|
1894
|
-
}
|
1895
|
-
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1896
|
-
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1897
|
-
if (typeof content === 'object') {
|
1898
|
-
const clipboardData = ev.clipboardData;
|
1899
|
-
const nativeSelection = document.getSelection();
|
1900
|
-
const range = nativeSelection.getRangeAt(0);
|
1901
|
-
const div = document.createElement('div');
|
1902
|
-
const fragment = range.cloneContents();
|
1903
|
-
div.append(fragment);
|
1904
|
-
clipboardData.setData('text/html', div.innerHTML);
|
1905
|
-
clipboardData.setData('text', div.innerText);
|
1906
|
-
ev.preventDefault();
|
1907
|
-
}
|
1908
|
-
}
|
1897
|
+
this.copyHandler(ev);
|
1909
1898
|
}), stream.fromEvent(textarea, 'paste').subscribe(ev => {
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
});
|
1899
|
+
this.pasteHandler(ev);
|
1900
|
+
}));
|
1901
|
+
}
|
1902
|
+
copyHandler(ev) {
|
1903
|
+
const selection = this.selection;
|
1904
|
+
if (!selection.isSelected) {
|
1905
|
+
return;
|
1906
|
+
}
|
1907
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1908
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1909
|
+
if (typeof content === 'object') {
|
1910
|
+
const clipboardData = ev.clipboardData;
|
1911
|
+
const nativeSelection = document.getSelection();
|
1912
|
+
const range = nativeSelection.getRangeAt(0);
|
1913
|
+
const div = document.createElement('div');
|
1914
|
+
const fragment = range.cloneContents();
|
1915
|
+
div.append(fragment);
|
1916
|
+
clipboardData.setData('text/html', div.innerHTML);
|
1917
|
+
clipboardData.setData('text', div.innerText);
|
1930
1918
|
ev.preventDefault();
|
1931
|
-
return;
|
1932
1919
|
}
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1920
|
+
}
|
1921
|
+
}
|
1922
|
+
pasteHandler(ev) {
|
1923
|
+
const text = ev.clipboardData.getData('Text');
|
1924
|
+
const types = Array.from(ev.clipboardData.types || []);
|
1925
|
+
const files = Array.from(ev.clipboardData.files);
|
1926
|
+
if (types.every(type => type === 'Files') && files.length) {
|
1927
|
+
Promise.all(files.filter(i => {
|
1928
|
+
return /image/i.test(i.type);
|
1929
|
+
}).map(item => {
|
1930
|
+
const reader = new FileReader();
|
1931
|
+
return new Promise(resolve => {
|
1932
|
+
reader.onload = (event) => {
|
1933
|
+
resolve(event.target.result);
|
1934
|
+
};
|
1935
|
+
reader.readAsDataURL(item);
|
1936
|
+
});
|
1937
|
+
})).then(urls => {
|
1938
|
+
const html = urls.map(i => {
|
1939
|
+
return `<img src=${i}>`;
|
1940
|
+
}).join('');
|
1941
|
+
this.paste(html, text);
|
1942
1942
|
});
|
1943
|
-
|
1943
|
+
ev.preventDefault();
|
1944
|
+
return;
|
1945
|
+
}
|
1946
|
+
const div = document.createElement('div');
|
1947
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
1948
|
+
div.contentEditable = 'true';
|
1949
|
+
document.body.appendChild(div);
|
1950
|
+
div.focus();
|
1951
|
+
setTimeout(() => {
|
1952
|
+
document.body.removeChild(div);
|
1953
|
+
div.style.cssText = '';
|
1954
|
+
this.paste(div, text);
|
1955
|
+
});
|
1944
1956
|
}
|
1945
|
-
|
1957
|
+
paste(dom, text) {
|
1946
1958
|
const slot = this.parser.parse(dom, new core$1.Slot([
|
1947
1959
|
core$1.ContentType.BlockComponent,
|
1948
1960
|
core$1.ContentType.InlineComponent,
|
package/bundles/magic-input.d.ts
CHANGED
@@ -72,7 +72,9 @@ export declare class MagicInput extends Input {
|
|
72
72
|
private reInit;
|
73
73
|
private init;
|
74
74
|
private handleDefaultActions;
|
75
|
-
|
75
|
+
copyHandler(ev: ClipboardEvent): void;
|
76
|
+
pasteHandler(ev: ClipboardEvent): void;
|
77
|
+
private paste;
|
76
78
|
private handleShortcut;
|
77
79
|
private handleInput;
|
78
80
|
private createEditableFrame;
|
@@ -41,7 +41,9 @@ export declare class NativeInput extends Input {
|
|
41
41
|
blur(): void;
|
42
42
|
destroy(): void;
|
43
43
|
private handleDefaultActions;
|
44
|
-
|
44
|
+
copyHandler(ev: ClipboardEvent): void;
|
45
|
+
pasteHandler(ev: ClipboardEvent): void;
|
46
|
+
private paste;
|
45
47
|
private handleShortcut;
|
46
48
|
private handleInput;
|
47
49
|
private handleMobileInput;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@textbus/platform-browser",
|
3
|
-
"version": "4.3.
|
3
|
+
"version": "4.3.3",
|
4
4
|
"description": "Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.",
|
5
5
|
"main": "./bundles/index.js",
|
6
6
|
"module": "./bundles/index.esm.js",
|
@@ -26,7 +26,7 @@
|
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
28
|
"@tanbo/stream": "^1.2.6",
|
29
|
-
"@textbus/core": "^4.3.
|
29
|
+
"@textbus/core": "^4.3.3",
|
30
30
|
"@viewfly/core": "^1.1.2"
|
31
31
|
},
|
32
32
|
"devDependencies": {
|
@@ -47,5 +47,5 @@
|
|
47
47
|
"bugs": {
|
48
48
|
"url": "https://github.com/textbus/textbus.git/issues"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "d07e5acf88c96bb8eb37760fd71ccc00ae5d3f5b"
|
51
51
|
}
|