@textbus/platform-browser 3.8.2 → 3.8.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/core/magic-input.d.ts +3 -1
- package/bundles/core/native-input.d.ts +3 -1
- package/bundles/index.esm.js +112 -100
- package/bundles/index.js +112 -100
- package/package.json +2 -2
@@ -73,7 +73,9 @@ export declare class MagicInput extends Input {
|
|
73
73
|
destroy(): void;
|
74
74
|
private init;
|
75
75
|
private handleDefaultActions;
|
76
|
-
|
76
|
+
copyHandler(ev: ClipboardEvent): void;
|
77
|
+
pasteHandler(ev: ClipboardEvent): void;
|
78
|
+
private paste;
|
77
79
|
private handleShortcut;
|
78
80
|
private handleInput;
|
79
81
|
private createEditableFrame;
|
@@ -47,7 +47,9 @@ export declare class NativeInput extends Input {
|
|
47
47
|
blur(): void;
|
48
48
|
destroy(): void;
|
49
49
|
private handleDefaultActions;
|
50
|
-
|
50
|
+
copyHandler(ev: ClipboardEvent): void;
|
51
|
+
pasteHandler(ev: ClipboardEvent): void;
|
52
|
+
private paste;
|
51
53
|
private handleShortcut;
|
52
54
|
private handleInput;
|
53
55
|
private handleMobileInput;
|
package/bundles/index.esm.js
CHANGED
@@ -1736,61 +1736,67 @@ let MagicInput = class MagicInput extends Input {
|
|
1736
1736
|
}
|
1737
1737
|
handleDefaultActions(textarea) {
|
1738
1738
|
this.subscription.add(fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
|
1739
|
-
|
1740
|
-
if (!selection.isSelected) {
|
1741
|
-
return;
|
1742
|
-
}
|
1743
|
-
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1744
|
-
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1745
|
-
if (typeof content === 'object') {
|
1746
|
-
const clipboardData = ev.clipboardData;
|
1747
|
-
const nativeSelection = document.getSelection();
|
1748
|
-
const range = nativeSelection.getRangeAt(0);
|
1749
|
-
const div = document.createElement('div');
|
1750
|
-
const fragment = range.cloneContents();
|
1751
|
-
div.append(fragment);
|
1752
|
-
clipboardData.setData('text/html', div.innerHTML);
|
1753
|
-
clipboardData.setData('text', div.innerText);
|
1754
|
-
ev.preventDefault();
|
1755
|
-
}
|
1756
|
-
}
|
1739
|
+
this.copyHandler(ev);
|
1757
1740
|
}), fromEvent(textarea, 'paste').subscribe(ev => {
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
});
|
1741
|
+
this.pasteHandler(ev);
|
1742
|
+
}));
|
1743
|
+
}
|
1744
|
+
copyHandler(ev) {
|
1745
|
+
const selection = this.selection;
|
1746
|
+
if (!selection.isSelected) {
|
1747
|
+
return;
|
1748
|
+
}
|
1749
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1750
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1751
|
+
if (typeof content === 'object') {
|
1752
|
+
const clipboardData = ev.clipboardData;
|
1753
|
+
const nativeSelection = document.getSelection();
|
1754
|
+
const range = nativeSelection.getRangeAt(0);
|
1755
|
+
const div = document.createElement('div');
|
1756
|
+
const fragment = range.cloneContents();
|
1757
|
+
div.append(fragment);
|
1758
|
+
clipboardData.setData('text/html', div.innerHTML);
|
1759
|
+
clipboardData.setData('text', div.innerText);
|
1778
1760
|
ev.preventDefault();
|
1779
|
-
return;
|
1780
1761
|
}
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1762
|
+
}
|
1763
|
+
}
|
1764
|
+
pasteHandler(ev) {
|
1765
|
+
const text = ev.clipboardData.getData('Text');
|
1766
|
+
const types = Array.from(ev.clipboardData.types || []);
|
1767
|
+
const files = Array.from(ev.clipboardData.files);
|
1768
|
+
if (types.every(type => type === 'Files') && files.length) {
|
1769
|
+
Promise.all(files.filter(i => {
|
1770
|
+
return /image/i.test(i.type);
|
1771
|
+
}).map(item => {
|
1772
|
+
const reader = new FileReader();
|
1773
|
+
return new Promise(resolve => {
|
1774
|
+
reader.onload = (event) => {
|
1775
|
+
resolve(event.target.result);
|
1776
|
+
};
|
1777
|
+
reader.readAsDataURL(item);
|
1778
|
+
});
|
1779
|
+
})).then(urls => {
|
1780
|
+
const html = urls.map(i => {
|
1781
|
+
return `<img src=${i}>`;
|
1782
|
+
}).join('');
|
1783
|
+
this.paste(html, text);
|
1790
1784
|
});
|
1791
|
-
|
1785
|
+
ev.preventDefault();
|
1786
|
+
return;
|
1787
|
+
}
|
1788
|
+
const div = this.doc.createElement('div');
|
1789
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
1790
|
+
div.contentEditable = 'true';
|
1791
|
+
this.doc.body.appendChild(div);
|
1792
|
+
div.focus();
|
1793
|
+
setTimeout(() => {
|
1794
|
+
this.doc.body.removeChild(div);
|
1795
|
+
div.style.cssText = '';
|
1796
|
+
this.paste(div, text);
|
1797
|
+
});
|
1792
1798
|
}
|
1793
|
-
|
1799
|
+
paste(dom, text) {
|
1794
1800
|
const slot = this.parser.parse(dom, new Slot([
|
1795
1801
|
ContentType.BlockComponent,
|
1796
1802
|
ContentType.InlineComponent,
|
@@ -2122,61 +2128,67 @@ let NativeInput = class NativeInput extends Input {
|
|
2122
2128
|
}
|
2123
2129
|
handleDefaultActions(textarea) {
|
2124
2130
|
this.subscription.add(fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
|
2125
|
-
|
2126
|
-
if (!selection.isSelected) {
|
2127
|
-
return;
|
2128
|
-
}
|
2129
|
-
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
2130
|
-
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
2131
|
-
if (typeof content === 'object') {
|
2132
|
-
const clipboardData = ev.clipboardData;
|
2133
|
-
const nativeSelection = document.getSelection();
|
2134
|
-
const range = nativeSelection.getRangeAt(0);
|
2135
|
-
const div = document.createElement('div');
|
2136
|
-
const fragment = range.cloneContents();
|
2137
|
-
div.append(fragment);
|
2138
|
-
clipboardData.setData('text/html', div.innerHTML);
|
2139
|
-
clipboardData.setData('text', div.innerText);
|
2140
|
-
ev.preventDefault();
|
2141
|
-
}
|
2142
|
-
}
|
2131
|
+
this.copyHandler(ev);
|
2143
2132
|
}), fromEvent(textarea, 'paste').subscribe(ev => {
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
});
|
2133
|
+
this.pasteHandler(ev);
|
2134
|
+
}));
|
2135
|
+
}
|
2136
|
+
copyHandler(ev) {
|
2137
|
+
const selection = this.selection;
|
2138
|
+
if (!selection.isSelected) {
|
2139
|
+
return;
|
2140
|
+
}
|
2141
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
2142
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
2143
|
+
if (typeof content === 'object') {
|
2144
|
+
const clipboardData = ev.clipboardData;
|
2145
|
+
const nativeSelection = document.getSelection();
|
2146
|
+
const range = nativeSelection.getRangeAt(0);
|
2147
|
+
const div = document.createElement('div');
|
2148
|
+
const fragment = range.cloneContents();
|
2149
|
+
div.append(fragment);
|
2150
|
+
clipboardData.setData('text/html', div.innerHTML);
|
2151
|
+
clipboardData.setData('text', div.innerText);
|
2164
2152
|
ev.preventDefault();
|
2165
|
-
return;
|
2166
2153
|
}
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2154
|
+
}
|
2155
|
+
}
|
2156
|
+
pasteHandler(ev) {
|
2157
|
+
const text = ev.clipboardData.getData('Text');
|
2158
|
+
const types = Array.from(ev.clipboardData.types || []);
|
2159
|
+
const files = Array.from(ev.clipboardData.files);
|
2160
|
+
if (types.every(type => type === 'Files') && files.length) {
|
2161
|
+
Promise.all(files.filter(i => {
|
2162
|
+
return /image/i.test(i.type);
|
2163
|
+
}).map(item => {
|
2164
|
+
const reader = new FileReader();
|
2165
|
+
return new Promise(resolve => {
|
2166
|
+
reader.onload = (event) => {
|
2167
|
+
resolve(event.target.result);
|
2168
|
+
};
|
2169
|
+
reader.readAsDataURL(item);
|
2170
|
+
});
|
2171
|
+
})).then(urls => {
|
2172
|
+
const html = urls.map(i => {
|
2173
|
+
return `<img src=${i}>`;
|
2174
|
+
}).join('');
|
2175
|
+
this.paste(html, text);
|
2176
2176
|
});
|
2177
|
-
|
2177
|
+
ev.preventDefault();
|
2178
|
+
return;
|
2179
|
+
}
|
2180
|
+
const div = document.createElement('div');
|
2181
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
2182
|
+
div.contentEditable = 'true';
|
2183
|
+
document.body.appendChild(div);
|
2184
|
+
div.focus();
|
2185
|
+
setTimeout(() => {
|
2186
|
+
document.body.removeChild(div);
|
2187
|
+
div.style.cssText = '';
|
2188
|
+
this.paste(div, text);
|
2189
|
+
});
|
2178
2190
|
}
|
2179
|
-
|
2191
|
+
paste(dom, text) {
|
2180
2192
|
const slot = this.parser.parse(dom, new Slot([
|
2181
2193
|
ContentType.BlockComponent,
|
2182
2194
|
ContentType.InlineComponent,
|
package/bundles/index.js
CHANGED
@@ -1738,61 +1738,67 @@ exports.MagicInput = class MagicInput extends Input {
|
|
1738
1738
|
}
|
1739
1739
|
handleDefaultActions(textarea) {
|
1740
1740
|
this.subscription.add(stream.fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
|
1741
|
-
|
1742
|
-
if (!selection.isSelected) {
|
1743
|
-
return;
|
1744
|
-
}
|
1745
|
-
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1746
|
-
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1747
|
-
if (typeof content === 'object') {
|
1748
|
-
const clipboardData = ev.clipboardData;
|
1749
|
-
const nativeSelection = document.getSelection();
|
1750
|
-
const range = nativeSelection.getRangeAt(0);
|
1751
|
-
const div = document.createElement('div');
|
1752
|
-
const fragment = range.cloneContents();
|
1753
|
-
div.append(fragment);
|
1754
|
-
clipboardData.setData('text/html', div.innerHTML);
|
1755
|
-
clipboardData.setData('text', div.innerText);
|
1756
|
-
ev.preventDefault();
|
1757
|
-
}
|
1758
|
-
}
|
1741
|
+
this.copyHandler(ev);
|
1759
1742
|
}), stream.fromEvent(textarea, 'paste').subscribe(ev => {
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
});
|
1743
|
+
this.pasteHandler(ev);
|
1744
|
+
}));
|
1745
|
+
}
|
1746
|
+
copyHandler(ev) {
|
1747
|
+
const selection = this.selection;
|
1748
|
+
if (!selection.isSelected) {
|
1749
|
+
return;
|
1750
|
+
}
|
1751
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1752
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1753
|
+
if (typeof content === 'object') {
|
1754
|
+
const clipboardData = ev.clipboardData;
|
1755
|
+
const nativeSelection = document.getSelection();
|
1756
|
+
const range = nativeSelection.getRangeAt(0);
|
1757
|
+
const div = document.createElement('div');
|
1758
|
+
const fragment = range.cloneContents();
|
1759
|
+
div.append(fragment);
|
1760
|
+
clipboardData.setData('text/html', div.innerHTML);
|
1761
|
+
clipboardData.setData('text', div.innerText);
|
1780
1762
|
ev.preventDefault();
|
1781
|
-
return;
|
1782
1763
|
}
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1764
|
+
}
|
1765
|
+
}
|
1766
|
+
pasteHandler(ev) {
|
1767
|
+
const text = ev.clipboardData.getData('Text');
|
1768
|
+
const types = Array.from(ev.clipboardData.types || []);
|
1769
|
+
const files = Array.from(ev.clipboardData.files);
|
1770
|
+
if (types.every(type => type === 'Files') && files.length) {
|
1771
|
+
Promise.all(files.filter(i => {
|
1772
|
+
return /image/i.test(i.type);
|
1773
|
+
}).map(item => {
|
1774
|
+
const reader = new FileReader();
|
1775
|
+
return new Promise(resolve => {
|
1776
|
+
reader.onload = (event) => {
|
1777
|
+
resolve(event.target.result);
|
1778
|
+
};
|
1779
|
+
reader.readAsDataURL(item);
|
1780
|
+
});
|
1781
|
+
})).then(urls => {
|
1782
|
+
const html = urls.map(i => {
|
1783
|
+
return `<img src=${i}>`;
|
1784
|
+
}).join('');
|
1785
|
+
this.paste(html, text);
|
1792
1786
|
});
|
1793
|
-
|
1787
|
+
ev.preventDefault();
|
1788
|
+
return;
|
1789
|
+
}
|
1790
|
+
const div = this.doc.createElement('div');
|
1791
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
1792
|
+
div.contentEditable = 'true';
|
1793
|
+
this.doc.body.appendChild(div);
|
1794
|
+
div.focus();
|
1795
|
+
setTimeout(() => {
|
1796
|
+
this.doc.body.removeChild(div);
|
1797
|
+
div.style.cssText = '';
|
1798
|
+
this.paste(div, text);
|
1799
|
+
});
|
1794
1800
|
}
|
1795
|
-
|
1801
|
+
paste(dom, text) {
|
1796
1802
|
const slot = this.parser.parse(dom, new core.Slot([
|
1797
1803
|
core.ContentType.BlockComponent,
|
1798
1804
|
core.ContentType.InlineComponent,
|
@@ -2124,61 +2130,67 @@ exports.NativeInput = class NativeInput extends Input {
|
|
2124
2130
|
}
|
2125
2131
|
handleDefaultActions(textarea) {
|
2126
2132
|
this.subscription.add(stream.fromEvent(isFirefox() ? textarea : document, 'copy').subscribe(ev => {
|
2127
|
-
|
2128
|
-
if (!selection.isSelected) {
|
2129
|
-
return;
|
2130
|
-
}
|
2131
|
-
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
2132
|
-
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
2133
|
-
if (typeof content === 'object') {
|
2134
|
-
const clipboardData = ev.clipboardData;
|
2135
|
-
const nativeSelection = document.getSelection();
|
2136
|
-
const range = nativeSelection.getRangeAt(0);
|
2137
|
-
const div = document.createElement('div');
|
2138
|
-
const fragment = range.cloneContents();
|
2139
|
-
div.append(fragment);
|
2140
|
-
clipboardData.setData('text/html', div.innerHTML);
|
2141
|
-
clipboardData.setData('text', div.innerText);
|
2142
|
-
ev.preventDefault();
|
2143
|
-
}
|
2144
|
-
}
|
2133
|
+
this.copyHandler(ev);
|
2145
2134
|
}), stream.fromEvent(textarea, 'paste').subscribe(ev => {
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
});
|
2135
|
+
this.pasteHandler(ev);
|
2136
|
+
}));
|
2137
|
+
}
|
2138
|
+
copyHandler(ev) {
|
2139
|
+
const selection = this.selection;
|
2140
|
+
if (!selection.isSelected) {
|
2141
|
+
return;
|
2142
|
+
}
|
2143
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
2144
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
2145
|
+
if (typeof content === 'object') {
|
2146
|
+
const clipboardData = ev.clipboardData;
|
2147
|
+
const nativeSelection = document.getSelection();
|
2148
|
+
const range = nativeSelection.getRangeAt(0);
|
2149
|
+
const div = document.createElement('div');
|
2150
|
+
const fragment = range.cloneContents();
|
2151
|
+
div.append(fragment);
|
2152
|
+
clipboardData.setData('text/html', div.innerHTML);
|
2153
|
+
clipboardData.setData('text', div.innerText);
|
2166
2154
|
ev.preventDefault();
|
2167
|
-
return;
|
2168
2155
|
}
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2156
|
+
}
|
2157
|
+
}
|
2158
|
+
pasteHandler(ev) {
|
2159
|
+
const text = ev.clipboardData.getData('Text');
|
2160
|
+
const types = Array.from(ev.clipboardData.types || []);
|
2161
|
+
const files = Array.from(ev.clipboardData.files);
|
2162
|
+
if (types.every(type => type === 'Files') && files.length) {
|
2163
|
+
Promise.all(files.filter(i => {
|
2164
|
+
return /image/i.test(i.type);
|
2165
|
+
}).map(item => {
|
2166
|
+
const reader = new FileReader();
|
2167
|
+
return new Promise(resolve => {
|
2168
|
+
reader.onload = (event) => {
|
2169
|
+
resolve(event.target.result);
|
2170
|
+
};
|
2171
|
+
reader.readAsDataURL(item);
|
2172
|
+
});
|
2173
|
+
})).then(urls => {
|
2174
|
+
const html = urls.map(i => {
|
2175
|
+
return `<img src=${i}>`;
|
2176
|
+
}).join('');
|
2177
|
+
this.paste(html, text);
|
2178
2178
|
});
|
2179
|
-
|
2179
|
+
ev.preventDefault();
|
2180
|
+
return;
|
2181
|
+
}
|
2182
|
+
const div = document.createElement('div');
|
2183
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
2184
|
+
div.contentEditable = 'true';
|
2185
|
+
document.body.appendChild(div);
|
2186
|
+
div.focus();
|
2187
|
+
setTimeout(() => {
|
2188
|
+
document.body.removeChild(div);
|
2189
|
+
div.style.cssText = '';
|
2190
|
+
this.paste(div, text);
|
2191
|
+
});
|
2180
2192
|
}
|
2181
|
-
|
2193
|
+
paste(dom, text) {
|
2182
2194
|
const slot = this.parser.parse(dom, new core.Slot([
|
2183
2195
|
core.ContentType.BlockComponent,
|
2184
2196
|
core.ContentType.InlineComponent,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@textbus/platform-browser",
|
3
|
-
"version": "3.8.
|
3
|
+
"version": "3.8.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",
|
@@ -48,5 +48,5 @@
|
|
48
48
|
"bugs": {
|
49
49
|
"url": "https://github.com/textbus/textbus.git/issues"
|
50
50
|
},
|
51
|
-
"gitHead": "
|
51
|
+
"gitHead": "bac004b8d0a7acd5c090385c5c2e2aeb41577773"
|
52
52
|
}
|