@textbus/platform-browser 3.1.9 → 3.1.12

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.
@@ -66,7 +66,7 @@ export declare class MagicInput extends Input {
66
66
  private textarea;
67
67
  private isFocus;
68
68
  private nativeFocus;
69
- private isSougouPinYin;
69
+ private ignoreComposition;
70
70
  constructor(parser: Parser, keyboard: Keyboard, commander: Commander, selection: Selection, controller: Controller, scheduler: Scheduler, injector: Injector);
71
71
  focus(range: Range, restart: boolean): void;
72
72
  blur(): void;
@@ -41,7 +41,7 @@ export declare class NativeInput extends Input {
41
41
  private isSafari;
42
42
  private isMac;
43
43
  private isMobileBrowser;
44
- private isSougouPinYin;
44
+ private ignoreComposition;
45
45
  constructor(injector: Injector, parser: Parser, scheduler: Scheduler, selection: Selection, keyboard: Keyboard, renderer: Renderer, commander: Commander, controller: Controller);
46
46
  focus(nativeRange: Range): void;
47
47
  blur(): void;
@@ -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, Registry, History } from '@textbus/core';
4
- import { Subject, filter, fromEvent, Subscription, merge, map, Observable, distinctUntilChanged } from '@tanbo/stream';
4
+ import { Subject, filter, fromEvent, Subscription, distinctUntilChanged, merge, map, Observable } from '@tanbo/stream';
5
5
 
6
6
  function createElement(tagName, options = {}) {
7
7
  const el = document.createElement(tagName);
@@ -1618,7 +1618,7 @@ let MagicInput = class MagicInput extends Input {
1618
1618
  this.textarea = null;
1619
1619
  this.isFocus = false;
1620
1620
  this.nativeFocus = false;
1621
- this.isSougouPinYin = false; // 有 bug 版本搜狗拼音
1621
+ this.ignoreComposition = false; // 有 bug 版本搜狗拼音
1622
1622
  this.onReady = new Promise(resolve => {
1623
1623
  this.subscription.add(fromEvent(this.container, 'load').subscribe(() => {
1624
1624
  const doc = this.container.contentDocument;
@@ -1775,13 +1775,13 @@ let MagicInput = class MagicInput extends Input {
1775
1775
  }
1776
1776
  return !isWriting; // || !this.textarea.value
1777
1777
  })).subscribe(ev => {
1778
+ this.ignoreComposition = false;
1778
1779
  let key = ev.key;
1779
1780
  const keys = ')!@#$%^Z&*(';
1780
1781
  const b = key === 'Process' && /Digit\d/.test(ev.code) && ev.shiftKey;
1781
1782
  if (b) {
1782
1783
  // 大小写锁定为大写 + 全角 + shift + 数字键,还存在问题
1783
1784
  key = keys.charAt(+ev.code.substring(5));
1784
- this.isSougouPinYin = true;
1785
1785
  ev.preventDefault();
1786
1786
  }
1787
1787
  const is = this.keyboard.execShortcut({
@@ -1791,13 +1791,19 @@ let MagicInput = class MagicInput extends Input {
1791
1791
  ctrlKey: this.isMac ? ev.metaKey : ev.ctrlKey
1792
1792
  });
1793
1793
  if (is) {
1794
+ this.ignoreComposition = true;
1794
1795
  ev.preventDefault();
1795
1796
  }
1796
1797
  }));
1797
1798
  }
1798
1799
  handleInput(textarea) {
1799
1800
  let startIndex = 0;
1800
- this.subscription.add(fromEvent(textarea, 'compositionstart').subscribe(() => {
1801
+ this.subscription.add(fromEvent(textarea, 'compositionstart').pipe(filter(() => {
1802
+ return !this.ignoreComposition;
1803
+ })).subscribe(() => {
1804
+ if (!this.selection.isCollapsed) {
1805
+ this.commander.delete();
1806
+ }
1801
1807
  this.composition = true;
1802
1808
  this.caret.compositionState = this.compositionState = null;
1803
1809
  startIndex = this.selection.startOffset;
@@ -1806,7 +1812,11 @@ let MagicInput = class MagicInput extends Input {
1806
1812
  index: startIndex
1807
1813
  });
1808
1814
  invokeListener(startSlot.parent, 'onCompositionStart', event);
1809
- }), fromEvent(textarea, 'compositionupdate').subscribe(ev => {
1815
+ }), fromEvent(textarea, 'compositionupdate').pipe(filter(() => {
1816
+ return !this.ignoreComposition;
1817
+ })).pipe(distinctUntilChanged((prev, next) => {
1818
+ return prev.data !== next.data;
1819
+ })).subscribe(ev => {
1810
1820
  if (ev.data === ' ') {
1811
1821
  // 处理搜狗五笔不符合 composition 事件预期,会意外跳光标的问题
1812
1822
  return;
@@ -1837,15 +1847,14 @@ let MagicInput = class MagicInput extends Input {
1837
1847
  return !ev.isComposing && !!ev.data;
1838
1848
  }), map(ev => {
1839
1849
  return ev.data;
1840
- })), this.isSafari ? new Observable() : fromEvent(textarea, 'compositionend').pipe(map(ev => {
1850
+ })), this.isSafari ? new Observable() : fromEvent(textarea, 'compositionend')
1851
+ .pipe(filter(() => {
1852
+ return !this.ignoreComposition;
1853
+ })).pipe(map(ev => {
1841
1854
  isCompositionEnd = true;
1842
1855
  ev.preventDefault();
1843
1856
  textarea.value = '';
1844
1857
  return ev.data;
1845
- }), filter(() => {
1846
- const b = this.isSougouPinYin;
1847
- this.isSougouPinYin = false;
1848
- return !b;
1849
1858
  }))).subscribe(text => {
1850
1859
  var _a;
1851
1860
  this.composition = false;
@@ -2026,7 +2035,7 @@ let NativeInput = class NativeInput extends Input {
2026
2035
  this.isSafari = isSafari();
2027
2036
  this.isMac = isMac();
2028
2037
  this.isMobileBrowser = isMobileBrowser();
2029
- this.isSougouPinYin = false; // 有 bug 版本搜狗拼音
2038
+ this.ignoreComposition = false; // 有 bug 版本搜狗拼音
2030
2039
  this.documentView = injector.get(VIEW_DOCUMENT);
2031
2040
  if (!controller.readonly) {
2032
2041
  this.documentView.contentEditable = 'true';
@@ -2142,11 +2151,12 @@ let NativeInput = class NativeInput extends Input {
2142
2151
  }
2143
2152
  return !isWriting; // || !this.textarea.value
2144
2153
  })).subscribe(ev => {
2154
+ this.ignoreComposition = false;
2145
2155
  let key = ev.key;
2146
- const b = key === 'Process' && ev.code === 'Digit2';
2156
+ const keys = ')!@#$%^Z&*(';
2157
+ const b = key === 'Process' && /Digit\d/.test(ev.code) && ev.shiftKey;
2147
2158
  if (b) {
2148
- key = '@';
2149
- this.isSougouPinYin = true;
2159
+ key = keys.charAt(+ev.code.substring(5));
2150
2160
  ev.preventDefault();
2151
2161
  }
2152
2162
  const is = this.keyboard.execShortcut({
@@ -2156,6 +2166,7 @@ let NativeInput = class NativeInput extends Input {
2156
2166
  ctrlKey: this.isMac ? ev.metaKey : ev.ctrlKey
2157
2167
  });
2158
2168
  if (is) {
2169
+ this.ignoreComposition = true;
2159
2170
  ev.preventDefault();
2160
2171
  }
2161
2172
  }));
@@ -2163,7 +2174,9 @@ let NativeInput = class NativeInput extends Input {
2163
2174
  handleInput(input) {
2164
2175
  let startIndex = 0;
2165
2176
  let isCompositionEnd = false;
2166
- this.subscription.add(fromEvent(input, 'compositionstart').subscribe(() => {
2177
+ this.subscription.add(fromEvent(input, 'compositionstart').pipe(filter(() => {
2178
+ return !this.ignoreComposition;
2179
+ })).subscribe(() => {
2167
2180
  this.composition = true;
2168
2181
  this.compositionState = null;
2169
2182
  startIndex = this.selection.startOffset;
@@ -2172,7 +2185,9 @@ let NativeInput = class NativeInput extends Input {
2172
2185
  index: startIndex
2173
2186
  });
2174
2187
  invokeListener(startSlot.parent, 'onCompositionStart', event);
2175
- }), fromEvent(input, 'compositionupdate').subscribe(ev => {
2188
+ }), fromEvent(input, 'compositionupdate').pipe(filter(() => {
2189
+ return !this.ignoreComposition;
2190
+ })).subscribe(ev => {
2176
2191
  const startSlot = this.selection.startSlot;
2177
2192
  this.compositionState = {
2178
2193
  slot: startSlot,
@@ -2219,17 +2234,21 @@ let NativeInput = class NativeInput extends Input {
2219
2234
  return null;
2220
2235
  }), filter(text => {
2221
2236
  return text;
2222
- })), (!this.isMobileBrowser && this.isSafari) ? new Observable() : fromEvent(input, 'compositionend').pipe(filter(() => {
2223
- return this.composition;
2224
- }), map(ev => {
2225
- isCompositionEnd = true;
2226
- ev.preventDefault();
2227
- return ev.data;
2228
- }), filter(() => {
2229
- const b = this.isSougouPinYin;
2230
- this.isSougouPinYin = false;
2231
- return !b;
2232
- }))).subscribe(text => {
2237
+ })), (!this.isMobileBrowser && this.isSafari) ?
2238
+ new Observable() :
2239
+ fromEvent(input, 'compositionend').pipe(filter(() => {
2240
+ return !this.ignoreComposition;
2241
+ })).pipe(filter(() => {
2242
+ return this.composition;
2243
+ }), map(ev => {
2244
+ isCompositionEnd = true;
2245
+ ev.preventDefault();
2246
+ return ev.data;
2247
+ }), filter(() => {
2248
+ const b = this.ignoreComposition;
2249
+ this.ignoreComposition = false;
2250
+ return !b;
2251
+ }))).subscribe(text => {
2233
2252
  this.composition = false;
2234
2253
  this.compositionState = null;
2235
2254
  if (text) {
package/bundles/index.js CHANGED
@@ -1620,7 +1620,7 @@ exports.MagicInput = class MagicInput extends Input {
1620
1620
  this.textarea = null;
1621
1621
  this.isFocus = false;
1622
1622
  this.nativeFocus = false;
1623
- this.isSougouPinYin = false; // 有 bug 版本搜狗拼音
1623
+ this.ignoreComposition = false; // 有 bug 版本搜狗拼音
1624
1624
  this.onReady = new Promise(resolve => {
1625
1625
  this.subscription.add(stream.fromEvent(this.container, 'load').subscribe(() => {
1626
1626
  const doc = this.container.contentDocument;
@@ -1777,13 +1777,13 @@ exports.MagicInput = class MagicInput extends Input {
1777
1777
  }
1778
1778
  return !isWriting; // || !this.textarea.value
1779
1779
  })).subscribe(ev => {
1780
+ this.ignoreComposition = false;
1780
1781
  let key = ev.key;
1781
1782
  const keys = ')!@#$%^Z&*(';
1782
1783
  const b = key === 'Process' && /Digit\d/.test(ev.code) && ev.shiftKey;
1783
1784
  if (b) {
1784
1785
  // 大小写锁定为大写 + 全角 + shift + 数字键,还存在问题
1785
1786
  key = keys.charAt(+ev.code.substring(5));
1786
- this.isSougouPinYin = true;
1787
1787
  ev.preventDefault();
1788
1788
  }
1789
1789
  const is = this.keyboard.execShortcut({
@@ -1793,13 +1793,19 @@ exports.MagicInput = class MagicInput extends Input {
1793
1793
  ctrlKey: this.isMac ? ev.metaKey : ev.ctrlKey
1794
1794
  });
1795
1795
  if (is) {
1796
+ this.ignoreComposition = true;
1796
1797
  ev.preventDefault();
1797
1798
  }
1798
1799
  }));
1799
1800
  }
1800
1801
  handleInput(textarea) {
1801
1802
  let startIndex = 0;
1802
- this.subscription.add(stream.fromEvent(textarea, 'compositionstart').subscribe(() => {
1803
+ this.subscription.add(stream.fromEvent(textarea, 'compositionstart').pipe(stream.filter(() => {
1804
+ return !this.ignoreComposition;
1805
+ })).subscribe(() => {
1806
+ if (!this.selection.isCollapsed) {
1807
+ this.commander.delete();
1808
+ }
1803
1809
  this.composition = true;
1804
1810
  this.caret.compositionState = this.compositionState = null;
1805
1811
  startIndex = this.selection.startOffset;
@@ -1808,7 +1814,11 @@ exports.MagicInput = class MagicInput extends Input {
1808
1814
  index: startIndex
1809
1815
  });
1810
1816
  core.invokeListener(startSlot.parent, 'onCompositionStart', event);
1811
- }), stream.fromEvent(textarea, 'compositionupdate').subscribe(ev => {
1817
+ }), stream.fromEvent(textarea, 'compositionupdate').pipe(stream.filter(() => {
1818
+ return !this.ignoreComposition;
1819
+ })).pipe(stream.distinctUntilChanged((prev, next) => {
1820
+ return prev.data !== next.data;
1821
+ })).subscribe(ev => {
1812
1822
  if (ev.data === ' ') {
1813
1823
  // 处理搜狗五笔不符合 composition 事件预期,会意外跳光标的问题
1814
1824
  return;
@@ -1839,15 +1849,14 @@ exports.MagicInput = class MagicInput extends Input {
1839
1849
  return !ev.isComposing && !!ev.data;
1840
1850
  }), stream.map(ev => {
1841
1851
  return ev.data;
1842
- })), this.isSafari ? new stream.Observable() : stream.fromEvent(textarea, 'compositionend').pipe(stream.map(ev => {
1852
+ })), this.isSafari ? new stream.Observable() : stream.fromEvent(textarea, 'compositionend')
1853
+ .pipe(stream.filter(() => {
1854
+ return !this.ignoreComposition;
1855
+ })).pipe(stream.map(ev => {
1843
1856
  isCompositionEnd = true;
1844
1857
  ev.preventDefault();
1845
1858
  textarea.value = '';
1846
1859
  return ev.data;
1847
- }), stream.filter(() => {
1848
- const b = this.isSougouPinYin;
1849
- this.isSougouPinYin = false;
1850
- return !b;
1851
1860
  }))).subscribe(text => {
1852
1861
  var _a;
1853
1862
  this.composition = false;
@@ -2028,7 +2037,7 @@ exports.NativeInput = class NativeInput extends Input {
2028
2037
  this.isSafari = isSafari();
2029
2038
  this.isMac = isMac();
2030
2039
  this.isMobileBrowser = isMobileBrowser();
2031
- this.isSougouPinYin = false; // 有 bug 版本搜狗拼音
2040
+ this.ignoreComposition = false; // 有 bug 版本搜狗拼音
2032
2041
  this.documentView = injector.get(VIEW_DOCUMENT);
2033
2042
  if (!controller.readonly) {
2034
2043
  this.documentView.contentEditable = 'true';
@@ -2144,11 +2153,12 @@ exports.NativeInput = class NativeInput extends Input {
2144
2153
  }
2145
2154
  return !isWriting; // || !this.textarea.value
2146
2155
  })).subscribe(ev => {
2156
+ this.ignoreComposition = false;
2147
2157
  let key = ev.key;
2148
- const b = key === 'Process' && ev.code === 'Digit2';
2158
+ const keys = ')!@#$%^Z&*(';
2159
+ const b = key === 'Process' && /Digit\d/.test(ev.code) && ev.shiftKey;
2149
2160
  if (b) {
2150
- key = '@';
2151
- this.isSougouPinYin = true;
2161
+ key = keys.charAt(+ev.code.substring(5));
2152
2162
  ev.preventDefault();
2153
2163
  }
2154
2164
  const is = this.keyboard.execShortcut({
@@ -2158,6 +2168,7 @@ exports.NativeInput = class NativeInput extends Input {
2158
2168
  ctrlKey: this.isMac ? ev.metaKey : ev.ctrlKey
2159
2169
  });
2160
2170
  if (is) {
2171
+ this.ignoreComposition = true;
2161
2172
  ev.preventDefault();
2162
2173
  }
2163
2174
  }));
@@ -2165,7 +2176,9 @@ exports.NativeInput = class NativeInput extends Input {
2165
2176
  handleInput(input) {
2166
2177
  let startIndex = 0;
2167
2178
  let isCompositionEnd = false;
2168
- this.subscription.add(stream.fromEvent(input, 'compositionstart').subscribe(() => {
2179
+ this.subscription.add(stream.fromEvent(input, 'compositionstart').pipe(stream.filter(() => {
2180
+ return !this.ignoreComposition;
2181
+ })).subscribe(() => {
2169
2182
  this.composition = true;
2170
2183
  this.compositionState = null;
2171
2184
  startIndex = this.selection.startOffset;
@@ -2174,7 +2187,9 @@ exports.NativeInput = class NativeInput extends Input {
2174
2187
  index: startIndex
2175
2188
  });
2176
2189
  core.invokeListener(startSlot.parent, 'onCompositionStart', event);
2177
- }), stream.fromEvent(input, 'compositionupdate').subscribe(ev => {
2190
+ }), stream.fromEvent(input, 'compositionupdate').pipe(stream.filter(() => {
2191
+ return !this.ignoreComposition;
2192
+ })).subscribe(ev => {
2178
2193
  const startSlot = this.selection.startSlot;
2179
2194
  this.compositionState = {
2180
2195
  slot: startSlot,
@@ -2221,17 +2236,21 @@ exports.NativeInput = class NativeInput extends Input {
2221
2236
  return null;
2222
2237
  }), stream.filter(text => {
2223
2238
  return text;
2224
- })), (!this.isMobileBrowser && this.isSafari) ? new stream.Observable() : stream.fromEvent(input, 'compositionend').pipe(stream.filter(() => {
2225
- return this.composition;
2226
- }), stream.map(ev => {
2227
- isCompositionEnd = true;
2228
- ev.preventDefault();
2229
- return ev.data;
2230
- }), stream.filter(() => {
2231
- const b = this.isSougouPinYin;
2232
- this.isSougouPinYin = false;
2233
- return !b;
2234
- }))).subscribe(text => {
2239
+ })), (!this.isMobileBrowser && this.isSafari) ?
2240
+ new stream.Observable() :
2241
+ stream.fromEvent(input, 'compositionend').pipe(stream.filter(() => {
2242
+ return !this.ignoreComposition;
2243
+ })).pipe(stream.filter(() => {
2244
+ return this.composition;
2245
+ }), stream.map(ev => {
2246
+ isCompositionEnd = true;
2247
+ ev.preventDefault();
2248
+ return ev.data;
2249
+ }), stream.filter(() => {
2250
+ const b = this.ignoreComposition;
2251
+ this.ignoreComposition = false;
2252
+ return !b;
2253
+ }))).subscribe(text => {
2235
2254
  this.composition = false;
2236
2255
  this.compositionState = null;
2237
2256
  if (text) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "3.1.9",
3
+ "version": "3.1.12",
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": "fac88c46fa8c1b510b212bc53ecae95e60d4adc6"
51
+ "gitHead": "f0145a1b781944bd43d40470f0e0dd5528f47c81"
52
52
  }