@textbus/platform-browser 3.1.9 → 3.1.11

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,16 @@ 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(() => {
1801
1804
  this.composition = true;
1802
1805
  this.caret.compositionState = this.compositionState = null;
1803
1806
  startIndex = this.selection.startOffset;
@@ -1806,7 +1809,11 @@ let MagicInput = class MagicInput extends Input {
1806
1809
  index: startIndex
1807
1810
  });
1808
1811
  invokeListener(startSlot.parent, 'onCompositionStart', event);
1809
- }), fromEvent(textarea, 'compositionupdate').subscribe(ev => {
1812
+ }), fromEvent(textarea, 'compositionupdate').pipe(filter(() => {
1813
+ return !this.ignoreComposition;
1814
+ })).pipe(distinctUntilChanged((prev, next) => {
1815
+ return prev.data !== next.data;
1816
+ })).subscribe(ev => {
1810
1817
  if (ev.data === ' ') {
1811
1818
  // 处理搜狗五笔不符合 composition 事件预期,会意外跳光标的问题
1812
1819
  return;
@@ -1837,15 +1844,14 @@ let MagicInput = class MagicInput extends Input {
1837
1844
  return !ev.isComposing && !!ev.data;
1838
1845
  }), map(ev => {
1839
1846
  return ev.data;
1840
- })), this.isSafari ? new Observable() : fromEvent(textarea, 'compositionend').pipe(map(ev => {
1847
+ })), this.isSafari ? new Observable() : fromEvent(textarea, 'compositionend')
1848
+ .pipe(filter(() => {
1849
+ return !this.ignoreComposition;
1850
+ })).pipe(map(ev => {
1841
1851
  isCompositionEnd = true;
1842
1852
  ev.preventDefault();
1843
1853
  textarea.value = '';
1844
1854
  return ev.data;
1845
- }), filter(() => {
1846
- const b = this.isSougouPinYin;
1847
- this.isSougouPinYin = false;
1848
- return !b;
1849
1855
  }))).subscribe(text => {
1850
1856
  var _a;
1851
1857
  this.composition = false;
@@ -2026,7 +2032,7 @@ let NativeInput = class NativeInput extends Input {
2026
2032
  this.isSafari = isSafari();
2027
2033
  this.isMac = isMac();
2028
2034
  this.isMobileBrowser = isMobileBrowser();
2029
- this.isSougouPinYin = false; // 有 bug 版本搜狗拼音
2035
+ this.ignoreComposition = false; // 有 bug 版本搜狗拼音
2030
2036
  this.documentView = injector.get(VIEW_DOCUMENT);
2031
2037
  if (!controller.readonly) {
2032
2038
  this.documentView.contentEditable = 'true';
@@ -2142,11 +2148,12 @@ let NativeInput = class NativeInput extends Input {
2142
2148
  }
2143
2149
  return !isWriting; // || !this.textarea.value
2144
2150
  })).subscribe(ev => {
2151
+ this.ignoreComposition = false;
2145
2152
  let key = ev.key;
2146
- const b = key === 'Process' && ev.code === 'Digit2';
2153
+ const keys = ')!@#$%^Z&*(';
2154
+ const b = key === 'Process' && /Digit\d/.test(ev.code) && ev.shiftKey;
2147
2155
  if (b) {
2148
- key = '@';
2149
- this.isSougouPinYin = true;
2156
+ key = keys.charAt(+ev.code.substring(5));
2150
2157
  ev.preventDefault();
2151
2158
  }
2152
2159
  const is = this.keyboard.execShortcut({
@@ -2156,6 +2163,7 @@ let NativeInput = class NativeInput extends Input {
2156
2163
  ctrlKey: this.isMac ? ev.metaKey : ev.ctrlKey
2157
2164
  });
2158
2165
  if (is) {
2166
+ this.ignoreComposition = true;
2159
2167
  ev.preventDefault();
2160
2168
  }
2161
2169
  }));
@@ -2163,7 +2171,9 @@ let NativeInput = class NativeInput extends Input {
2163
2171
  handleInput(input) {
2164
2172
  let startIndex = 0;
2165
2173
  let isCompositionEnd = false;
2166
- this.subscription.add(fromEvent(input, 'compositionstart').subscribe(() => {
2174
+ this.subscription.add(fromEvent(input, 'compositionstart').pipe(filter(() => {
2175
+ return !this.ignoreComposition;
2176
+ })).subscribe(() => {
2167
2177
  this.composition = true;
2168
2178
  this.compositionState = null;
2169
2179
  startIndex = this.selection.startOffset;
@@ -2172,7 +2182,9 @@ let NativeInput = class NativeInput extends Input {
2172
2182
  index: startIndex
2173
2183
  });
2174
2184
  invokeListener(startSlot.parent, 'onCompositionStart', event);
2175
- }), fromEvent(input, 'compositionupdate').subscribe(ev => {
2185
+ }), fromEvent(input, 'compositionupdate').pipe(filter(() => {
2186
+ return !this.ignoreComposition;
2187
+ })).subscribe(ev => {
2176
2188
  const startSlot = this.selection.startSlot;
2177
2189
  this.compositionState = {
2178
2190
  slot: startSlot,
@@ -2219,17 +2231,21 @@ let NativeInput = class NativeInput extends Input {
2219
2231
  return null;
2220
2232
  }), filter(text => {
2221
2233
  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 => {
2234
+ })), (!this.isMobileBrowser && this.isSafari) ?
2235
+ new Observable() :
2236
+ fromEvent(input, 'compositionend').pipe(filter(() => {
2237
+ return !this.ignoreComposition;
2238
+ })).pipe(filter(() => {
2239
+ return this.composition;
2240
+ }), map(ev => {
2241
+ isCompositionEnd = true;
2242
+ ev.preventDefault();
2243
+ return ev.data;
2244
+ }), filter(() => {
2245
+ const b = this.ignoreComposition;
2246
+ this.ignoreComposition = false;
2247
+ return !b;
2248
+ }))).subscribe(text => {
2233
2249
  this.composition = false;
2234
2250
  this.compositionState = null;
2235
2251
  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,16 @@ 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(() => {
1803
1806
  this.composition = true;
1804
1807
  this.caret.compositionState = this.compositionState = null;
1805
1808
  startIndex = this.selection.startOffset;
@@ -1808,7 +1811,11 @@ exports.MagicInput = class MagicInput extends Input {
1808
1811
  index: startIndex
1809
1812
  });
1810
1813
  core.invokeListener(startSlot.parent, 'onCompositionStart', event);
1811
- }), stream.fromEvent(textarea, 'compositionupdate').subscribe(ev => {
1814
+ }), stream.fromEvent(textarea, 'compositionupdate').pipe(stream.filter(() => {
1815
+ return !this.ignoreComposition;
1816
+ })).pipe(stream.distinctUntilChanged((prev, next) => {
1817
+ return prev.data !== next.data;
1818
+ })).subscribe(ev => {
1812
1819
  if (ev.data === ' ') {
1813
1820
  // 处理搜狗五笔不符合 composition 事件预期,会意外跳光标的问题
1814
1821
  return;
@@ -1839,15 +1846,14 @@ exports.MagicInput = class MagicInput extends Input {
1839
1846
  return !ev.isComposing && !!ev.data;
1840
1847
  }), stream.map(ev => {
1841
1848
  return ev.data;
1842
- })), this.isSafari ? new stream.Observable() : stream.fromEvent(textarea, 'compositionend').pipe(stream.map(ev => {
1849
+ })), this.isSafari ? new stream.Observable() : stream.fromEvent(textarea, 'compositionend')
1850
+ .pipe(stream.filter(() => {
1851
+ return !this.ignoreComposition;
1852
+ })).pipe(stream.map(ev => {
1843
1853
  isCompositionEnd = true;
1844
1854
  ev.preventDefault();
1845
1855
  textarea.value = '';
1846
1856
  return ev.data;
1847
- }), stream.filter(() => {
1848
- const b = this.isSougouPinYin;
1849
- this.isSougouPinYin = false;
1850
- return !b;
1851
1857
  }))).subscribe(text => {
1852
1858
  var _a;
1853
1859
  this.composition = false;
@@ -2028,7 +2034,7 @@ exports.NativeInput = class NativeInput extends Input {
2028
2034
  this.isSafari = isSafari();
2029
2035
  this.isMac = isMac();
2030
2036
  this.isMobileBrowser = isMobileBrowser();
2031
- this.isSougouPinYin = false; // 有 bug 版本搜狗拼音
2037
+ this.ignoreComposition = false; // 有 bug 版本搜狗拼音
2032
2038
  this.documentView = injector.get(VIEW_DOCUMENT);
2033
2039
  if (!controller.readonly) {
2034
2040
  this.documentView.contentEditable = 'true';
@@ -2144,11 +2150,12 @@ exports.NativeInput = class NativeInput extends Input {
2144
2150
  }
2145
2151
  return !isWriting; // || !this.textarea.value
2146
2152
  })).subscribe(ev => {
2153
+ this.ignoreComposition = false;
2147
2154
  let key = ev.key;
2148
- const b = key === 'Process' && ev.code === 'Digit2';
2155
+ const keys = ')!@#$%^Z&*(';
2156
+ const b = key === 'Process' && /Digit\d/.test(ev.code) && ev.shiftKey;
2149
2157
  if (b) {
2150
- key = '@';
2151
- this.isSougouPinYin = true;
2158
+ key = keys.charAt(+ev.code.substring(5));
2152
2159
  ev.preventDefault();
2153
2160
  }
2154
2161
  const is = this.keyboard.execShortcut({
@@ -2158,6 +2165,7 @@ exports.NativeInput = class NativeInput extends Input {
2158
2165
  ctrlKey: this.isMac ? ev.metaKey : ev.ctrlKey
2159
2166
  });
2160
2167
  if (is) {
2168
+ this.ignoreComposition = true;
2161
2169
  ev.preventDefault();
2162
2170
  }
2163
2171
  }));
@@ -2165,7 +2173,9 @@ exports.NativeInput = class NativeInput extends Input {
2165
2173
  handleInput(input) {
2166
2174
  let startIndex = 0;
2167
2175
  let isCompositionEnd = false;
2168
- this.subscription.add(stream.fromEvent(input, 'compositionstart').subscribe(() => {
2176
+ this.subscription.add(stream.fromEvent(input, 'compositionstart').pipe(stream.filter(() => {
2177
+ return !this.ignoreComposition;
2178
+ })).subscribe(() => {
2169
2179
  this.composition = true;
2170
2180
  this.compositionState = null;
2171
2181
  startIndex = this.selection.startOffset;
@@ -2174,7 +2184,9 @@ exports.NativeInput = class NativeInput extends Input {
2174
2184
  index: startIndex
2175
2185
  });
2176
2186
  core.invokeListener(startSlot.parent, 'onCompositionStart', event);
2177
- }), stream.fromEvent(input, 'compositionupdate').subscribe(ev => {
2187
+ }), stream.fromEvent(input, 'compositionupdate').pipe(stream.filter(() => {
2188
+ return !this.ignoreComposition;
2189
+ })).subscribe(ev => {
2178
2190
  const startSlot = this.selection.startSlot;
2179
2191
  this.compositionState = {
2180
2192
  slot: startSlot,
@@ -2221,17 +2233,21 @@ exports.NativeInput = class NativeInput extends Input {
2221
2233
  return null;
2222
2234
  }), stream.filter(text => {
2223
2235
  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 => {
2236
+ })), (!this.isMobileBrowser && this.isSafari) ?
2237
+ new stream.Observable() :
2238
+ stream.fromEvent(input, 'compositionend').pipe(stream.filter(() => {
2239
+ return !this.ignoreComposition;
2240
+ })).pipe(stream.filter(() => {
2241
+ return this.composition;
2242
+ }), stream.map(ev => {
2243
+ isCompositionEnd = true;
2244
+ ev.preventDefault();
2245
+ return ev.data;
2246
+ }), stream.filter(() => {
2247
+ const b = this.ignoreComposition;
2248
+ this.ignoreComposition = false;
2249
+ return !b;
2250
+ }))).subscribe(text => {
2235
2251
  this.composition = false;
2236
2252
  this.compositionState = null;
2237
2253
  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.11",
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": "8b0b2eb7ddc40eb9a7f31aca26f7953a80dfdfcf"
52
52
  }