@textbus/platform-browser 3.8.2 → 3.8.4
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/core/selection-bridge.d.ts +0 -3
- package/bundles/index.esm.js +122 -105
- package/bundles/index.js +121 -104
- package/package.json +3 -3
@@ -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;
|
@@ -8,8 +8,6 @@ import { Input, ViewOptions } from './types';
|
|
8
8
|
*/
|
9
9
|
export declare class SelectionBridge implements NativeSelectionBridge {
|
10
10
|
private config;
|
11
|
-
private injector;
|
12
|
-
private controller;
|
13
11
|
private selection;
|
14
12
|
private rootComponentRef;
|
15
13
|
private input;
|
@@ -24,7 +22,6 @@ export declare class SelectionBridge implements NativeSelectionBridge {
|
|
24
22
|
private ignoreSelectionChange;
|
25
23
|
private changeFromUser;
|
26
24
|
private docContainer;
|
27
|
-
private maskContainer;
|
28
25
|
private cacheCaretPositionTimer;
|
29
26
|
private oldCaretPosition;
|
30
27
|
constructor(config: ViewOptions, injector: Injector, controller: Controller, selection: Selection, rootComponentRef: RootComponentRef, input: Input, renderer: Renderer);
|
package/bundles/index.esm.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import 'reflect-metadata';
|
2
2
|
import { InjectionToken, Injectable, Inject, Injector, Optional } from '@tanbo/di';
|
3
3
|
import { VTextNode, VElement, Controller, Selection, RootComponentRef, Renderer, Scheduler, Slot, ContentType, Event, invokeListener, Keyboard, Commander, makeError, Starter, NativeRenderer, NativeSelectionBridge, OutputRenderer, History, Registry } from '@textbus/core';
|
4
|
-
import { Subject, filter, fromEvent, Subscription, distinctUntilChanged, merge, map, Observable } from '@tanbo/stream';
|
4
|
+
import { Subject, filter, fromEvent, delay, Subscription, distinctUntilChanged, merge, map, Observable } from '@tanbo/stream';
|
5
5
|
|
6
6
|
function createElement(tagName, options = {}) {
|
7
7
|
const el = document.createElement(tagName);
|
@@ -177,8 +177,6 @@ class Input {
|
|
177
177
|
let SelectionBridge = class SelectionBridge {
|
178
178
|
constructor(config, injector, controller, selection, rootComponentRef, input, renderer) {
|
179
179
|
this.config = config;
|
180
|
-
this.injector = injector;
|
181
|
-
this.controller = controller;
|
182
180
|
this.selection = selection;
|
183
181
|
this.rootComponentRef = rootComponentRef;
|
184
182
|
this.input = input;
|
@@ -191,7 +189,6 @@ let SelectionBridge = class SelectionBridge {
|
|
191
189
|
this.ignoreSelectionChange = false;
|
192
190
|
this.changeFromUser = false;
|
193
191
|
this.docContainer = injector.get(VIEW_DOCUMENT);
|
194
|
-
this.maskContainer = injector.get(VIEW_MASK);
|
195
192
|
this.onSelectionChange = this.selectionChangeEvent.asObservable().pipe(filter(() => {
|
196
193
|
return !controller.readonly;
|
197
194
|
}));
|
@@ -498,7 +495,15 @@ let SelectionBridge = class SelectionBridge {
|
|
498
495
|
}
|
499
496
|
}));
|
500
497
|
}
|
501
|
-
|
498
|
+
let isUpdating = false;
|
499
|
+
this.subs.push(this.renderer.onViewUpdateBefore.subscribe(() => {
|
500
|
+
isUpdating = true;
|
501
|
+
}), this.renderer.onViewUpdated.pipe(delay()).subscribe(() => {
|
502
|
+
isUpdating = false;
|
503
|
+
}), fromEvent(document, 'selectionchange').subscribe(() => {
|
504
|
+
if (isUpdating) {
|
505
|
+
return;
|
506
|
+
}
|
502
507
|
this.syncSelection(connector);
|
503
508
|
}));
|
504
509
|
}
|
@@ -1736,61 +1741,67 @@ let MagicInput = class MagicInput extends Input {
|
|
1736
1741
|
}
|
1737
1742
|
handleDefaultActions(textarea) {
|
1738
1743
|
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
|
-
}
|
1744
|
+
this.copyHandler(ev);
|
1757
1745
|
}), 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
|
-
});
|
1746
|
+
this.pasteHandler(ev);
|
1747
|
+
}));
|
1748
|
+
}
|
1749
|
+
copyHandler(ev) {
|
1750
|
+
const selection = this.selection;
|
1751
|
+
if (!selection.isSelected) {
|
1752
|
+
return;
|
1753
|
+
}
|
1754
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1755
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1756
|
+
if (typeof content === 'object') {
|
1757
|
+
const clipboardData = ev.clipboardData;
|
1758
|
+
const nativeSelection = document.getSelection();
|
1759
|
+
const range = nativeSelection.getRangeAt(0);
|
1760
|
+
const div = document.createElement('div');
|
1761
|
+
const fragment = range.cloneContents();
|
1762
|
+
div.append(fragment);
|
1763
|
+
clipboardData.setData('text/html', div.innerHTML);
|
1764
|
+
clipboardData.setData('text', div.innerText);
|
1778
1765
|
ev.preventDefault();
|
1779
|
-
return;
|
1780
1766
|
}
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1767
|
+
}
|
1768
|
+
}
|
1769
|
+
pasteHandler(ev) {
|
1770
|
+
const text = ev.clipboardData.getData('Text');
|
1771
|
+
const types = Array.from(ev.clipboardData.types || []);
|
1772
|
+
const files = Array.from(ev.clipboardData.files);
|
1773
|
+
if (types.every(type => type === 'Files') && files.length) {
|
1774
|
+
Promise.all(files.filter(i => {
|
1775
|
+
return /image/i.test(i.type);
|
1776
|
+
}).map(item => {
|
1777
|
+
const reader = new FileReader();
|
1778
|
+
return new Promise(resolve => {
|
1779
|
+
reader.onload = (event) => {
|
1780
|
+
resolve(event.target.result);
|
1781
|
+
};
|
1782
|
+
reader.readAsDataURL(item);
|
1783
|
+
});
|
1784
|
+
})).then(urls => {
|
1785
|
+
const html = urls.map(i => {
|
1786
|
+
return `<img src=${i}>`;
|
1787
|
+
}).join('');
|
1788
|
+
this.paste(html, text);
|
1790
1789
|
});
|
1791
|
-
|
1790
|
+
ev.preventDefault();
|
1791
|
+
return;
|
1792
|
+
}
|
1793
|
+
const div = this.doc.createElement('div');
|
1794
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
1795
|
+
div.contentEditable = 'true';
|
1796
|
+
this.doc.body.appendChild(div);
|
1797
|
+
div.focus();
|
1798
|
+
setTimeout(() => {
|
1799
|
+
this.doc.body.removeChild(div);
|
1800
|
+
div.style.cssText = '';
|
1801
|
+
this.paste(div, text);
|
1802
|
+
});
|
1792
1803
|
}
|
1793
|
-
|
1804
|
+
paste(dom, text) {
|
1794
1805
|
const slot = this.parser.parse(dom, new Slot([
|
1795
1806
|
ContentType.BlockComponent,
|
1796
1807
|
ContentType.InlineComponent,
|
@@ -2122,61 +2133,67 @@ let NativeInput = class NativeInput extends Input {
|
|
2122
2133
|
}
|
2123
2134
|
handleDefaultActions(textarea) {
|
2124
2135
|
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
|
-
}
|
2136
|
+
this.copyHandler(ev);
|
2143
2137
|
}), 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
|
-
});
|
2138
|
+
this.pasteHandler(ev);
|
2139
|
+
}));
|
2140
|
+
}
|
2141
|
+
copyHandler(ev) {
|
2142
|
+
const selection = this.selection;
|
2143
|
+
if (!selection.isSelected) {
|
2144
|
+
return;
|
2145
|
+
}
|
2146
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
2147
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
2148
|
+
if (typeof content === 'object') {
|
2149
|
+
const clipboardData = ev.clipboardData;
|
2150
|
+
const nativeSelection = document.getSelection();
|
2151
|
+
const range = nativeSelection.getRangeAt(0);
|
2152
|
+
const div = document.createElement('div');
|
2153
|
+
const fragment = range.cloneContents();
|
2154
|
+
div.append(fragment);
|
2155
|
+
clipboardData.setData('text/html', div.innerHTML);
|
2156
|
+
clipboardData.setData('text', div.innerText);
|
2164
2157
|
ev.preventDefault();
|
2165
|
-
return;
|
2166
2158
|
}
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2159
|
+
}
|
2160
|
+
}
|
2161
|
+
pasteHandler(ev) {
|
2162
|
+
const text = ev.clipboardData.getData('Text');
|
2163
|
+
const types = Array.from(ev.clipboardData.types || []);
|
2164
|
+
const files = Array.from(ev.clipboardData.files);
|
2165
|
+
if (types.every(type => type === 'Files') && files.length) {
|
2166
|
+
Promise.all(files.filter(i => {
|
2167
|
+
return /image/i.test(i.type);
|
2168
|
+
}).map(item => {
|
2169
|
+
const reader = new FileReader();
|
2170
|
+
return new Promise(resolve => {
|
2171
|
+
reader.onload = (event) => {
|
2172
|
+
resolve(event.target.result);
|
2173
|
+
};
|
2174
|
+
reader.readAsDataURL(item);
|
2175
|
+
});
|
2176
|
+
})).then(urls => {
|
2177
|
+
const html = urls.map(i => {
|
2178
|
+
return `<img src=${i}>`;
|
2179
|
+
}).join('');
|
2180
|
+
this.paste(html, text);
|
2176
2181
|
});
|
2177
|
-
|
2182
|
+
ev.preventDefault();
|
2183
|
+
return;
|
2184
|
+
}
|
2185
|
+
const div = document.createElement('div');
|
2186
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
2187
|
+
div.contentEditable = 'true';
|
2188
|
+
document.body.appendChild(div);
|
2189
|
+
div.focus();
|
2190
|
+
setTimeout(() => {
|
2191
|
+
document.body.removeChild(div);
|
2192
|
+
div.style.cssText = '';
|
2193
|
+
this.paste(div, text);
|
2194
|
+
});
|
2178
2195
|
}
|
2179
|
-
|
2196
|
+
paste(dom, text) {
|
2180
2197
|
const slot = this.parser.parse(dom, new Slot([
|
2181
2198
|
ContentType.BlockComponent,
|
2182
2199
|
ContentType.InlineComponent,
|
package/bundles/index.js
CHANGED
@@ -179,8 +179,6 @@ class Input {
|
|
179
179
|
exports.SelectionBridge = class SelectionBridge {
|
180
180
|
constructor(config, injector, controller, selection, rootComponentRef, input, renderer) {
|
181
181
|
this.config = config;
|
182
|
-
this.injector = injector;
|
183
|
-
this.controller = controller;
|
184
182
|
this.selection = selection;
|
185
183
|
this.rootComponentRef = rootComponentRef;
|
186
184
|
this.input = input;
|
@@ -193,7 +191,6 @@ exports.SelectionBridge = class SelectionBridge {
|
|
193
191
|
this.ignoreSelectionChange = false;
|
194
192
|
this.changeFromUser = false;
|
195
193
|
this.docContainer = injector.get(VIEW_DOCUMENT);
|
196
|
-
this.maskContainer = injector.get(VIEW_MASK);
|
197
194
|
this.onSelectionChange = this.selectionChangeEvent.asObservable().pipe(stream.filter(() => {
|
198
195
|
return !controller.readonly;
|
199
196
|
}));
|
@@ -500,7 +497,15 @@ exports.SelectionBridge = class SelectionBridge {
|
|
500
497
|
}
|
501
498
|
}));
|
502
499
|
}
|
503
|
-
|
500
|
+
let isUpdating = false;
|
501
|
+
this.subs.push(this.renderer.onViewUpdateBefore.subscribe(() => {
|
502
|
+
isUpdating = true;
|
503
|
+
}), this.renderer.onViewUpdated.pipe(stream.delay()).subscribe(() => {
|
504
|
+
isUpdating = false;
|
505
|
+
}), stream.fromEvent(document, 'selectionchange').subscribe(() => {
|
506
|
+
if (isUpdating) {
|
507
|
+
return;
|
508
|
+
}
|
504
509
|
this.syncSelection(connector);
|
505
510
|
}));
|
506
511
|
}
|
@@ -1738,61 +1743,67 @@ exports.MagicInput = class MagicInput extends Input {
|
|
1738
1743
|
}
|
1739
1744
|
handleDefaultActions(textarea) {
|
1740
1745
|
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
|
-
}
|
1746
|
+
this.copyHandler(ev);
|
1759
1747
|
}), 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
|
-
});
|
1748
|
+
this.pasteHandler(ev);
|
1749
|
+
}));
|
1750
|
+
}
|
1751
|
+
copyHandler(ev) {
|
1752
|
+
const selection = this.selection;
|
1753
|
+
if (!selection.isSelected) {
|
1754
|
+
return;
|
1755
|
+
}
|
1756
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
1757
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
1758
|
+
if (typeof content === 'object') {
|
1759
|
+
const clipboardData = ev.clipboardData;
|
1760
|
+
const nativeSelection = document.getSelection();
|
1761
|
+
const range = nativeSelection.getRangeAt(0);
|
1762
|
+
const div = document.createElement('div');
|
1763
|
+
const fragment = range.cloneContents();
|
1764
|
+
div.append(fragment);
|
1765
|
+
clipboardData.setData('text/html', div.innerHTML);
|
1766
|
+
clipboardData.setData('text', div.innerText);
|
1780
1767
|
ev.preventDefault();
|
1781
|
-
return;
|
1782
1768
|
}
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1769
|
+
}
|
1770
|
+
}
|
1771
|
+
pasteHandler(ev) {
|
1772
|
+
const text = ev.clipboardData.getData('Text');
|
1773
|
+
const types = Array.from(ev.clipboardData.types || []);
|
1774
|
+
const files = Array.from(ev.clipboardData.files);
|
1775
|
+
if (types.every(type => type === 'Files') && files.length) {
|
1776
|
+
Promise.all(files.filter(i => {
|
1777
|
+
return /image/i.test(i.type);
|
1778
|
+
}).map(item => {
|
1779
|
+
const reader = new FileReader();
|
1780
|
+
return new Promise(resolve => {
|
1781
|
+
reader.onload = (event) => {
|
1782
|
+
resolve(event.target.result);
|
1783
|
+
};
|
1784
|
+
reader.readAsDataURL(item);
|
1785
|
+
});
|
1786
|
+
})).then(urls => {
|
1787
|
+
const html = urls.map(i => {
|
1788
|
+
return `<img src=${i}>`;
|
1789
|
+
}).join('');
|
1790
|
+
this.paste(html, text);
|
1792
1791
|
});
|
1793
|
-
|
1792
|
+
ev.preventDefault();
|
1793
|
+
return;
|
1794
|
+
}
|
1795
|
+
const div = this.doc.createElement('div');
|
1796
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
1797
|
+
div.contentEditable = 'true';
|
1798
|
+
this.doc.body.appendChild(div);
|
1799
|
+
div.focus();
|
1800
|
+
setTimeout(() => {
|
1801
|
+
this.doc.body.removeChild(div);
|
1802
|
+
div.style.cssText = '';
|
1803
|
+
this.paste(div, text);
|
1804
|
+
});
|
1794
1805
|
}
|
1795
|
-
|
1806
|
+
paste(dom, text) {
|
1796
1807
|
const slot = this.parser.parse(dom, new core.Slot([
|
1797
1808
|
core.ContentType.BlockComponent,
|
1798
1809
|
core.ContentType.InlineComponent,
|
@@ -2124,61 +2135,67 @@ exports.NativeInput = class NativeInput extends Input {
|
|
2124
2135
|
}
|
2125
2136
|
handleDefaultActions(textarea) {
|
2126
2137
|
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
|
-
}
|
2138
|
+
this.copyHandler(ev);
|
2145
2139
|
}), 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
|
-
});
|
2140
|
+
this.pasteHandler(ev);
|
2141
|
+
}));
|
2142
|
+
}
|
2143
|
+
copyHandler(ev) {
|
2144
|
+
const selection = this.selection;
|
2145
|
+
if (!selection.isSelected) {
|
2146
|
+
return;
|
2147
|
+
}
|
2148
|
+
if (selection.startSlot === selection.endSlot && selection.endOffset - selection.startOffset === 1) {
|
2149
|
+
const content = selection.startSlot.getContentAtIndex(selection.startOffset);
|
2150
|
+
if (typeof content === 'object') {
|
2151
|
+
const clipboardData = ev.clipboardData;
|
2152
|
+
const nativeSelection = document.getSelection();
|
2153
|
+
const range = nativeSelection.getRangeAt(0);
|
2154
|
+
const div = document.createElement('div');
|
2155
|
+
const fragment = range.cloneContents();
|
2156
|
+
div.append(fragment);
|
2157
|
+
clipboardData.setData('text/html', div.innerHTML);
|
2158
|
+
clipboardData.setData('text', div.innerText);
|
2166
2159
|
ev.preventDefault();
|
2167
|
-
return;
|
2168
2160
|
}
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2161
|
+
}
|
2162
|
+
}
|
2163
|
+
pasteHandler(ev) {
|
2164
|
+
const text = ev.clipboardData.getData('Text');
|
2165
|
+
const types = Array.from(ev.clipboardData.types || []);
|
2166
|
+
const files = Array.from(ev.clipboardData.files);
|
2167
|
+
if (types.every(type => type === 'Files') && files.length) {
|
2168
|
+
Promise.all(files.filter(i => {
|
2169
|
+
return /image/i.test(i.type);
|
2170
|
+
}).map(item => {
|
2171
|
+
const reader = new FileReader();
|
2172
|
+
return new Promise(resolve => {
|
2173
|
+
reader.onload = (event) => {
|
2174
|
+
resolve(event.target.result);
|
2175
|
+
};
|
2176
|
+
reader.readAsDataURL(item);
|
2177
|
+
});
|
2178
|
+
})).then(urls => {
|
2179
|
+
const html = urls.map(i => {
|
2180
|
+
return `<img src=${i}>`;
|
2181
|
+
}).join('');
|
2182
|
+
this.paste(html, text);
|
2178
2183
|
});
|
2179
|
-
|
2184
|
+
ev.preventDefault();
|
2185
|
+
return;
|
2186
|
+
}
|
2187
|
+
const div = document.createElement('div');
|
2188
|
+
div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
|
2189
|
+
div.contentEditable = 'true';
|
2190
|
+
document.body.appendChild(div);
|
2191
|
+
div.focus();
|
2192
|
+
setTimeout(() => {
|
2193
|
+
document.body.removeChild(div);
|
2194
|
+
div.style.cssText = '';
|
2195
|
+
this.paste(div, text);
|
2196
|
+
});
|
2180
2197
|
}
|
2181
|
-
|
2198
|
+
paste(dom, text) {
|
2182
2199
|
const slot = this.parser.parse(dom, new core.Slot([
|
2183
2200
|
core.ContentType.BlockComponent,
|
2184
2201
|
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.4",
|
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",
|
@@ -27,7 +27,7 @@
|
|
27
27
|
"dependencies": {
|
28
28
|
"@tanbo/di": "^1.1.8",
|
29
29
|
"@tanbo/stream": "^1.2.5",
|
30
|
-
"@textbus/core": "^3.8.
|
30
|
+
"@textbus/core": "^3.8.4",
|
31
31
|
"reflect-metadata": "^0.1.13"
|
32
32
|
},
|
33
33
|
"devDependencies": {
|
@@ -48,5 +48,5 @@
|
|
48
48
|
"bugs": {
|
49
49
|
"url": "https://github.com/textbus/textbus.git/issues"
|
50
50
|
},
|
51
|
-
"gitHead": "
|
51
|
+
"gitHead": "7359230a08229933be9cb78590b6777256fa5582"
|
52
52
|
}
|