@textbus/platform-browser 3.1.13 → 3.1.15

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.
@@ -50,5 +50,7 @@ export declare class NativeInput extends Input {
50
50
  private handlePaste;
51
51
  private handleShortcut;
52
52
  private handleInput;
53
+ private handleMobileInput;
54
+ private handlePCInput;
53
55
  }
54
56
  export {};
@@ -2172,6 +2172,82 @@ let NativeInput = class NativeInput extends Input {
2172
2172
  }));
2173
2173
  }
2174
2174
  handleInput(input) {
2175
+ if (this.isMobileBrowser) {
2176
+ this.handleMobileInput(input);
2177
+ }
2178
+ else {
2179
+ this.handlePCInput(input);
2180
+ }
2181
+ }
2182
+ handleMobileInput(input) {
2183
+ let isCompositionStart = true;
2184
+ let startIndex;
2185
+ this.subscription.add(fromEvent(input, 'beforeinput').subscribe(ev => {
2186
+ var _a;
2187
+ switch (ev.inputType) {
2188
+ case 'insertText':
2189
+ if (ev.data) {
2190
+ this.commander.write(ev.data);
2191
+ }
2192
+ break;
2193
+ case 'insertCompositionText':
2194
+ if (isCompositionStart) {
2195
+ isCompositionStart = false;
2196
+ this.composition = true;
2197
+ this.compositionState = null;
2198
+ startIndex = this.selection.startOffset;
2199
+ const startSlot = this.selection.startSlot;
2200
+ const event = new Event(startSlot, {
2201
+ index: startIndex
2202
+ });
2203
+ invokeListener(startSlot.parent, 'onCompositionStart', event);
2204
+ }
2205
+ else {
2206
+ const startSlot = this.selection.startSlot;
2207
+ this.compositionState = {
2208
+ slot: startSlot,
2209
+ index: startIndex,
2210
+ data: ev.data
2211
+ };
2212
+ const event = new Event(startSlot, {
2213
+ index: startIndex,
2214
+ data: ev.data
2215
+ });
2216
+ invokeListener(startSlot.parent, 'onCompositionUpdate', event);
2217
+ }
2218
+ break;
2219
+ case 'deleteCompositionText':
2220
+ break;
2221
+ case 'deleteContentBackward':
2222
+ case 'insertReplacementText': {
2223
+ const range = ev.getTargetRanges()[0];
2224
+ const location = this.renderer.getLocationByNativeNode(range.startContainer);
2225
+ const startSlot = this.selection.startSlot;
2226
+ this.selection.setBaseAndExtent(startSlot, location.startIndex + range.startOffset, startSlot, location.startIndex + range.endOffset);
2227
+ this.commander.delete();
2228
+ if (ev.inputType === 'insertReplacementText') {
2229
+ const text = ((_a = ev.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData('text')) || ev.data || null;
2230
+ if (text) {
2231
+ this.commander.write(text);
2232
+ }
2233
+ }
2234
+ break;
2235
+ }
2236
+ case 'insertFromComposition': {
2237
+ if (ev.data) {
2238
+ this.commander.write(ev.data);
2239
+ }
2240
+ const startSlot = this.selection.startSlot;
2241
+ if (startSlot) {
2242
+ const event = new Event(startSlot, null);
2243
+ invokeListener(startSlot.parent, 'onCompositionEnd', event);
2244
+ }
2245
+ break;
2246
+ }
2247
+ }
2248
+ }));
2249
+ }
2250
+ handlePCInput(input) {
2175
2251
  let startIndex = 0;
2176
2252
  let isCompositionEnd = false;
2177
2253
  this.subscription.add(fromEvent(input, 'compositionstart').pipe(filter(() => {
@@ -2215,13 +2291,7 @@ let NativeInput = class NativeInput extends Input {
2215
2291
  }
2216
2292
  isCompositionEnd = ev.inputType === 'insertFromComposition';
2217
2293
  if (isCompositionEnd && this.composition) {
2218
- if (this.isMobileBrowser) {
2219
- this.composition = false;
2220
- this.compositionState = null;
2221
- }
2222
- else {
2223
- return null;
2224
- }
2294
+ return null;
2225
2295
  }
2226
2296
  if (this.isSafari) {
2227
2297
  if (ev.inputType === 'insertText' || isCompositionEnd) {
@@ -2234,8 +2304,7 @@ let NativeInput = class NativeInput extends Input {
2234
2304
  return null;
2235
2305
  }), filter(text => {
2236
2306
  return text;
2237
- })), (!this.isMobileBrowser && this.isSafari) ?
2238
- new Observable() :
2307
+ })), this.isSafari ? new Observable() :
2239
2308
  fromEvent(input, 'compositionend').pipe(filter(() => {
2240
2309
  return !this.ignoreComposition;
2241
2310
  })).pipe(filter(() => {
package/bundles/index.js CHANGED
@@ -2174,6 +2174,82 @@ exports.NativeInput = class NativeInput extends Input {
2174
2174
  }));
2175
2175
  }
2176
2176
  handleInput(input) {
2177
+ if (this.isMobileBrowser) {
2178
+ this.handleMobileInput(input);
2179
+ }
2180
+ else {
2181
+ this.handlePCInput(input);
2182
+ }
2183
+ }
2184
+ handleMobileInput(input) {
2185
+ let isCompositionStart = true;
2186
+ let startIndex;
2187
+ this.subscription.add(stream.fromEvent(input, 'beforeinput').subscribe(ev => {
2188
+ var _a;
2189
+ switch (ev.inputType) {
2190
+ case 'insertText':
2191
+ if (ev.data) {
2192
+ this.commander.write(ev.data);
2193
+ }
2194
+ break;
2195
+ case 'insertCompositionText':
2196
+ if (isCompositionStart) {
2197
+ isCompositionStart = false;
2198
+ this.composition = true;
2199
+ this.compositionState = null;
2200
+ startIndex = this.selection.startOffset;
2201
+ const startSlot = this.selection.startSlot;
2202
+ const event = new core.Event(startSlot, {
2203
+ index: startIndex
2204
+ });
2205
+ core.invokeListener(startSlot.parent, 'onCompositionStart', event);
2206
+ }
2207
+ else {
2208
+ const startSlot = this.selection.startSlot;
2209
+ this.compositionState = {
2210
+ slot: startSlot,
2211
+ index: startIndex,
2212
+ data: ev.data
2213
+ };
2214
+ const event = new core.Event(startSlot, {
2215
+ index: startIndex,
2216
+ data: ev.data
2217
+ });
2218
+ core.invokeListener(startSlot.parent, 'onCompositionUpdate', event);
2219
+ }
2220
+ break;
2221
+ case 'deleteCompositionText':
2222
+ break;
2223
+ case 'deleteContentBackward':
2224
+ case 'insertReplacementText': {
2225
+ const range = ev.getTargetRanges()[0];
2226
+ const location = this.renderer.getLocationByNativeNode(range.startContainer);
2227
+ const startSlot = this.selection.startSlot;
2228
+ this.selection.setBaseAndExtent(startSlot, location.startIndex + range.startOffset, startSlot, location.startIndex + range.endOffset);
2229
+ this.commander.delete();
2230
+ if (ev.inputType === 'insertReplacementText') {
2231
+ const text = ((_a = ev.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData('text')) || ev.data || null;
2232
+ if (text) {
2233
+ this.commander.write(text);
2234
+ }
2235
+ }
2236
+ break;
2237
+ }
2238
+ case 'insertFromComposition': {
2239
+ if (ev.data) {
2240
+ this.commander.write(ev.data);
2241
+ }
2242
+ const startSlot = this.selection.startSlot;
2243
+ if (startSlot) {
2244
+ const event = new core.Event(startSlot, null);
2245
+ core.invokeListener(startSlot.parent, 'onCompositionEnd', event);
2246
+ }
2247
+ break;
2248
+ }
2249
+ }
2250
+ }));
2251
+ }
2252
+ handlePCInput(input) {
2177
2253
  let startIndex = 0;
2178
2254
  let isCompositionEnd = false;
2179
2255
  this.subscription.add(stream.fromEvent(input, 'compositionstart').pipe(stream.filter(() => {
@@ -2217,13 +2293,7 @@ exports.NativeInput = class NativeInput extends Input {
2217
2293
  }
2218
2294
  isCompositionEnd = ev.inputType === 'insertFromComposition';
2219
2295
  if (isCompositionEnd && this.composition) {
2220
- if (this.isMobileBrowser) {
2221
- this.composition = false;
2222
- this.compositionState = null;
2223
- }
2224
- else {
2225
- return null;
2226
- }
2296
+ return null;
2227
2297
  }
2228
2298
  if (this.isSafari) {
2229
2299
  if (ev.inputType === 'insertText' || isCompositionEnd) {
@@ -2236,8 +2306,7 @@ exports.NativeInput = class NativeInput extends Input {
2236
2306
  return null;
2237
2307
  }), stream.filter(text => {
2238
2308
  return text;
2239
- })), (!this.isMobileBrowser && this.isSafari) ?
2240
- new stream.Observable() :
2309
+ })), this.isSafari ? new stream.Observable() :
2241
2310
  stream.fromEvent(input, 'compositionend').pipe(stream.filter(() => {
2242
2311
  return !this.ignoreComposition;
2243
2312
  })).pipe(stream.filter(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "3.1.13",
3
+ "version": "3.1.15",
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.4",
29
29
  "@tanbo/stream": "^1.1.9",
30
- "@textbus/core": "^3.1.13",
30
+ "@textbus/core": "^3.1.15",
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": "55f6225a13070e5dd341cff13a3afc9e43dc104e"
51
+ "gitHead": "8d233f9dec8ad9a268197a39f7840f368322f063"
52
52
  }