@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.
@@ -73,7 +73,9 @@ export declare class MagicInput extends Input {
73
73
  destroy(): void;
74
74
  private init;
75
75
  private handleDefaultActions;
76
- private handlePaste;
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
- private handlePaste;
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);
@@ -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
- this.subs.push(fromEvent(document, 'selectionchange').pipe().subscribe(() => {
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
- const selection = this.selection;
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
- const text = ev.clipboardData.getData('Text');
1759
- const types = Array.from(ev.clipboardData.types || []);
1760
- const files = Array.from(ev.clipboardData.files);
1761
- if (types.every(type => type === 'Files') && files.length) {
1762
- Promise.all(files.filter(i => {
1763
- return /image/i.test(i.type);
1764
- }).map(item => {
1765
- const reader = new FileReader();
1766
- return new Promise(resolve => {
1767
- reader.onload = (event) => {
1768
- resolve(event.target.result);
1769
- };
1770
- reader.readAsDataURL(item);
1771
- });
1772
- })).then(urls => {
1773
- const html = urls.map(i => {
1774
- return `<img src=${i}>`;
1775
- }).join('');
1776
- this.handlePaste(html, text);
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
- const div = this.doc.createElement('div');
1782
- div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
1783
- div.contentEditable = 'true';
1784
- this.doc.body.appendChild(div);
1785
- div.focus();
1786
- setTimeout(() => {
1787
- this.doc.body.removeChild(div);
1788
- div.style.cssText = '';
1789
- this.handlePaste(div, text);
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
- handlePaste(dom, text) {
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
- const selection = this.selection;
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
- const text = ev.clipboardData.getData('Text');
2145
- const types = Array.from(ev.clipboardData.types || []);
2146
- const files = Array.from(ev.clipboardData.files);
2147
- if (types.every(type => type === 'Files') && files.length) {
2148
- Promise.all(files.filter(i => {
2149
- return /image/i.test(i.type);
2150
- }).map(item => {
2151
- const reader = new FileReader();
2152
- return new Promise(resolve => {
2153
- reader.onload = (event) => {
2154
- resolve(event.target.result);
2155
- };
2156
- reader.readAsDataURL(item);
2157
- });
2158
- })).then(urls => {
2159
- const html = urls.map(i => {
2160
- return `<img src=${i}>`;
2161
- }).join('');
2162
- this.handlePaste(html, text);
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
- const div = document.createElement('div');
2168
- div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
2169
- div.contentEditable = 'true';
2170
- document.body.appendChild(div);
2171
- div.focus();
2172
- setTimeout(() => {
2173
- document.body.removeChild(div);
2174
- div.style.cssText = '';
2175
- this.handlePaste(div, text);
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
- handlePaste(dom, text) {
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
- this.subs.push(stream.fromEvent(document, 'selectionchange').pipe().subscribe(() => {
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
- const selection = this.selection;
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
- const text = ev.clipboardData.getData('Text');
1761
- const types = Array.from(ev.clipboardData.types || []);
1762
- const files = Array.from(ev.clipboardData.files);
1763
- if (types.every(type => type === 'Files') && files.length) {
1764
- Promise.all(files.filter(i => {
1765
- return /image/i.test(i.type);
1766
- }).map(item => {
1767
- const reader = new FileReader();
1768
- return new Promise(resolve => {
1769
- reader.onload = (event) => {
1770
- resolve(event.target.result);
1771
- };
1772
- reader.readAsDataURL(item);
1773
- });
1774
- })).then(urls => {
1775
- const html = urls.map(i => {
1776
- return `<img src=${i}>`;
1777
- }).join('');
1778
- this.handlePaste(html, text);
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
- const div = this.doc.createElement('div');
1784
- div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
1785
- div.contentEditable = 'true';
1786
- this.doc.body.appendChild(div);
1787
- div.focus();
1788
- setTimeout(() => {
1789
- this.doc.body.removeChild(div);
1790
- div.style.cssText = '';
1791
- this.handlePaste(div, text);
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
- handlePaste(dom, text) {
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
- const selection = this.selection;
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
- const text = ev.clipboardData.getData('Text');
2147
- const types = Array.from(ev.clipboardData.types || []);
2148
- const files = Array.from(ev.clipboardData.files);
2149
- if (types.every(type => type === 'Files') && files.length) {
2150
- Promise.all(files.filter(i => {
2151
- return /image/i.test(i.type);
2152
- }).map(item => {
2153
- const reader = new FileReader();
2154
- return new Promise(resolve => {
2155
- reader.onload = (event) => {
2156
- resolve(event.target.result);
2157
- };
2158
- reader.readAsDataURL(item);
2159
- });
2160
- })).then(urls => {
2161
- const html = urls.map(i => {
2162
- return `<img src=${i}>`;
2163
- }).join('');
2164
- this.handlePaste(html, text);
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
- const div = document.createElement('div');
2170
- div.style.cssText = 'width:1px; height:10px; overflow: hidden; position: fixed; left: 50%; top: 50%; opacity:0';
2171
- div.contentEditable = 'true';
2172
- document.body.appendChild(div);
2173
- div.focus();
2174
- setTimeout(() => {
2175
- document.body.removeChild(div);
2176
- div.style.cssText = '';
2177
- this.handlePaste(div, text);
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
- handlePaste(dom, text) {
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.2",
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.1",
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": "c44236787b0f1ab7798197cf710ed3c4baaf10d4"
51
+ "gitHead": "7359230a08229933be9cb78590b6777256fa5582"
52
52
  }