@textbus/platform-browser 3.1.16 → 3.1.18

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.
@@ -21,7 +21,7 @@ export interface ComponentLoader {
21
21
  /** 识别组件的匹配方法 */
22
22
  match(element: HTMLElement): boolean;
23
23
  /** 读取组件内容的方法 */
24
- read(element: HTMLElement, context: Injector, slotParser: SlotParser): ComponentInstance | Slot;
24
+ read(element: HTMLElement, injector: Injector, slotParser: SlotParser): ComponentInstance | Slot;
25
25
  }
26
26
  export interface FormatLoaderReadResult<T extends FormatValue> {
27
27
  formatter: Formatter<T>;
@@ -1,6 +1,6 @@
1
1
  import 'reflect-metadata';
2
2
  import { InjectionToken, Injectable, Inject, Injector, Optional } from '@tanbo/di';
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';
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
4
  import { Subject, filter, fromEvent, Subscription, distinctUntilChanged, merge, map, Observable } from '@tanbo/stream';
5
5
 
6
6
  function createElement(tagName, options = {}) {
@@ -2182,44 +2182,70 @@ let NativeInput = class NativeInput extends Input {
2182
2182
  handleMobileInput(input) {
2183
2183
  let isCompositionStart = true;
2184
2184
  let startIndex;
2185
- this.subscription.add(fromEvent(input, 'beforeinput').subscribe(ev => {
2185
+ const compositionStart = () => {
2186
+ this.composition = true;
2187
+ this.compositionState = null;
2188
+ startIndex = this.selection.startOffset;
2189
+ const startSlot = this.selection.startSlot;
2190
+ const event = new Event(startSlot, {
2191
+ index: startIndex
2192
+ });
2193
+ invokeListener(startSlot.parent, 'onCompositionStart', event);
2194
+ };
2195
+ const compositionUpdate = (data) => {
2196
+ const startSlot = this.selection.startSlot;
2197
+ this.compositionState = {
2198
+ slot: startSlot,
2199
+ index: startIndex,
2200
+ data
2201
+ };
2202
+ const event = new Event(startSlot, {
2203
+ index: startIndex,
2204
+ data
2205
+ });
2206
+ invokeListener(startSlot.parent, 'onCompositionUpdate', event);
2207
+ };
2208
+ const compositionEnd = (data) => {
2209
+ this.composition = false;
2210
+ if (data) {
2211
+ this.commander.write(data);
2212
+ }
2213
+ const startSlot = this.selection.startSlot;
2214
+ if (startSlot) {
2215
+ const event = new Event(startSlot, null);
2216
+ invokeListener(startSlot.parent, 'onCompositionEnd', event);
2217
+ }
2218
+ };
2219
+ this.subscription.add(fromEvent(input, 'compositionstart').subscribe(() => {
2220
+ compositionStart();
2221
+ }), fromEvent(input, 'compositionupdate').subscribe(ev => {
2222
+ compositionUpdate(ev.data);
2223
+ }), fromEvent(input, 'compositionend').subscribe(ev => {
2224
+ compositionEnd(ev.data);
2225
+ }), fromEvent(input, 'beforeinput').subscribe(ev => {
2186
2226
  var _a;
2187
2227
  switch (ev.inputType) {
2188
2228
  case 'insertText':
2189
2229
  if (ev.data) {
2190
2230
  this.commander.write(ev.data);
2231
+ ev.preventDefault();
2191
2232
  }
2192
2233
  break;
2193
2234
  case 'insertCompositionText':
2194
2235
  if (isCompositionStart) {
2195
2236
  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);
2237
+ compositionStart();
2204
2238
  }
2205
2239
  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);
2240
+ compositionUpdate(ev.data || '');
2217
2241
  }
2218
2242
  break;
2219
2243
  case 'deleteCompositionText':
2244
+ this.composition = false;
2220
2245
  break;
2221
2246
  case 'deleteContentBackward':
2222
2247
  case 'insertReplacementText': {
2248
+ this.composition = false;
2223
2249
  const range = ev.getTargetRanges()[0];
2224
2250
  const location = this.renderer.getLocationByNativeNode(range.startContainer);
2225
2251
  const startSlot = this.selection.startSlot;
@@ -2233,17 +2259,11 @@ let NativeInput = class NativeInput extends Input {
2233
2259
  }
2234
2260
  break;
2235
2261
  }
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
- }
2262
+ //
2263
+ // case 'insertFromComposition': {
2264
+ // compositionEnd(ev.data || '')
2265
+ // break
2266
+ // }
2247
2267
  }
2248
2268
  }));
2249
2269
  }
@@ -2628,6 +2648,14 @@ class Viewer extends Starter {
2628
2648
  const rootComponentRef = this.get(RootComponentRef);
2629
2649
  return rootComponentRef.component.toJSON();
2630
2650
  }
2651
+ /**
2652
+ * 清空内容
2653
+ */
2654
+ clear() {
2655
+ this.replaceContent('');
2656
+ const history = this.get(History);
2657
+ history.clear();
2658
+ }
2631
2659
  /**
2632
2660
  * 销毁编辑器
2633
2661
  */
package/bundles/index.js CHANGED
@@ -2184,44 +2184,70 @@ exports.NativeInput = class NativeInput extends Input {
2184
2184
  handleMobileInput(input) {
2185
2185
  let isCompositionStart = true;
2186
2186
  let startIndex;
2187
- this.subscription.add(stream.fromEvent(input, 'beforeinput').subscribe(ev => {
2187
+ const compositionStart = () => {
2188
+ this.composition = true;
2189
+ this.compositionState = null;
2190
+ startIndex = this.selection.startOffset;
2191
+ const startSlot = this.selection.startSlot;
2192
+ const event = new core.Event(startSlot, {
2193
+ index: startIndex
2194
+ });
2195
+ core.invokeListener(startSlot.parent, 'onCompositionStart', event);
2196
+ };
2197
+ const compositionUpdate = (data) => {
2198
+ const startSlot = this.selection.startSlot;
2199
+ this.compositionState = {
2200
+ slot: startSlot,
2201
+ index: startIndex,
2202
+ data
2203
+ };
2204
+ const event = new core.Event(startSlot, {
2205
+ index: startIndex,
2206
+ data
2207
+ });
2208
+ core.invokeListener(startSlot.parent, 'onCompositionUpdate', event);
2209
+ };
2210
+ const compositionEnd = (data) => {
2211
+ this.composition = false;
2212
+ if (data) {
2213
+ this.commander.write(data);
2214
+ }
2215
+ const startSlot = this.selection.startSlot;
2216
+ if (startSlot) {
2217
+ const event = new core.Event(startSlot, null);
2218
+ core.invokeListener(startSlot.parent, 'onCompositionEnd', event);
2219
+ }
2220
+ };
2221
+ this.subscription.add(stream.fromEvent(input, 'compositionstart').subscribe(() => {
2222
+ compositionStart();
2223
+ }), stream.fromEvent(input, 'compositionupdate').subscribe(ev => {
2224
+ compositionUpdate(ev.data);
2225
+ }), stream.fromEvent(input, 'compositionend').subscribe(ev => {
2226
+ compositionEnd(ev.data);
2227
+ }), stream.fromEvent(input, 'beforeinput').subscribe(ev => {
2188
2228
  var _a;
2189
2229
  switch (ev.inputType) {
2190
2230
  case 'insertText':
2191
2231
  if (ev.data) {
2192
2232
  this.commander.write(ev.data);
2233
+ ev.preventDefault();
2193
2234
  }
2194
2235
  break;
2195
2236
  case 'insertCompositionText':
2196
2237
  if (isCompositionStart) {
2197
2238
  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);
2239
+ compositionStart();
2206
2240
  }
2207
2241
  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);
2242
+ compositionUpdate(ev.data || '');
2219
2243
  }
2220
2244
  break;
2221
2245
  case 'deleteCompositionText':
2246
+ this.composition = false;
2222
2247
  break;
2223
2248
  case 'deleteContentBackward':
2224
2249
  case 'insertReplacementText': {
2250
+ this.composition = false;
2225
2251
  const range = ev.getTargetRanges()[0];
2226
2252
  const location = this.renderer.getLocationByNativeNode(range.startContainer);
2227
2253
  const startSlot = this.selection.startSlot;
@@ -2235,17 +2261,11 @@ exports.NativeInput = class NativeInput extends Input {
2235
2261
  }
2236
2262
  break;
2237
2263
  }
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
- }
2264
+ //
2265
+ // case 'insertFromComposition': {
2266
+ // compositionEnd(ev.data || '')
2267
+ // break
2268
+ // }
2249
2269
  }
2250
2270
  }));
2251
2271
  }
@@ -2630,6 +2650,14 @@ class Viewer extends core.Starter {
2630
2650
  const rootComponentRef = this.get(core.RootComponentRef);
2631
2651
  return rootComponentRef.component.toJSON();
2632
2652
  }
2653
+ /**
2654
+ * 清空内容
2655
+ */
2656
+ clear() {
2657
+ this.replaceContent('');
2658
+ const history = this.get(core.History);
2659
+ history.clear();
2660
+ }
2633
2661
  /**
2634
2662
  * 销毁编辑器
2635
2663
  */
@@ -69,6 +69,10 @@ export declare class Viewer extends Starter {
69
69
  * 获取 JSON 格式的内容
70
70
  */
71
71
  getJSON(): ComponentLiteral;
72
+ /**
73
+ * 清空内容
74
+ */
75
+ clear(): void;
72
76
  /**
73
77
  * 销毁编辑器
74
78
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "3.1.16",
3
+ "version": "3.1.18",
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.16",
30
+ "@textbus/core": "^3.1.18",
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": "bb32dc210effd50d0d90c51974184477e6504bd4"
51
+ "gitHead": "b7f5adca5b1e8268bdcfa9f0358d399c8ebfcd30"
52
52
  }