@textbus/platform-browser 3.0.1 → 3.0.2

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.
@@ -28,7 +28,8 @@ export declare class DomRenderer implements NativeRenderer {
28
28
  xlinktype: string;
29
29
  'xlink:type': string;
30
30
  };
31
- formElement: Record<string, string[]>;
31
+ booleanProps: Record<string, string[]>;
32
+ valueProps: Record<string, string[]>;
32
33
  listen<T = any>(node: NativeNode, type: string, callback: (ev: T) => any): void;
33
34
  unListen(node: NativeNode, type: string, callback: (ev: any) => any): void;
34
35
  createTextNode(textContent: string): NativeNode;
@@ -1,6 +1,6 @@
1
1
  import { Injector } from '@tanbo/di';
2
2
  import { Observable } from '@tanbo/stream';
3
- import { Commander, Controller, Keyboard, Scheduler, Selection } from '@textbus/core';
3
+ import { Commander, Controller, Keyboard, Renderer, Scheduler, Selection } from '@textbus/core';
4
4
  import { Caret, CaretPosition, CompositionState, Input, Scroller } from './types';
5
5
  import { Parser } from '../dom-support/parser';
6
6
  declare class NativeCaret implements Caret {
@@ -29,6 +29,7 @@ export declare class NativeInput extends Input {
29
29
  private scheduler;
30
30
  private selection;
31
31
  private keyboard;
32
+ private renderer;
32
33
  private commander;
33
34
  private controller;
34
35
  caret: NativeCaret;
@@ -45,7 +46,7 @@ export declare class NativeInput extends Input {
45
46
  private isSafari;
46
47
  private isMac;
47
48
  private isSougouPinYin;
48
- constructor(injector: Injector, parser: Parser, scheduler: Scheduler, selection: Selection, keyboard: Keyboard, commander: Commander, controller: Controller);
49
+ constructor(injector: Injector, parser: Parser, scheduler: Scheduler, selection: Selection, keyboard: Keyboard, renderer: Renderer, commander: Commander, controller: Controller);
49
50
  focus(nativeRange: Range): void;
50
51
  blur(): void;
51
52
  destroy(): void;
@@ -1118,14 +1118,20 @@ let DomRenderer = DomRenderer_1 = class DomRenderer {
1118
1118
  xlinktype: 'xlink:type',
1119
1119
  'xlink:type': 'xlink:type'
1120
1120
  };
1121
- this.formElement = {
1122
- input: ['disabled', 'readonly', 'value'],
1121
+ this.booleanProps = {
1122
+ input: ['disabled', 'readonly'],
1123
1123
  select: ['disabled', 'readonly'],
1124
- option: ['disabled', 'selected', 'value'],
1124
+ option: ['disabled', 'selected'],
1125
1125
  button: ['disabled'],
1126
1126
  video: ['controls', 'autoplay', 'loop', 'muted'],
1127
1127
  audio: ['controls', 'autoplay', 'loop', 'muted'],
1128
1128
  };
1129
+ this.valueProps = {
1130
+ input: ['value'],
1131
+ option: ['value'],
1132
+ video: ['src'],
1133
+ audio: ['src']
1134
+ };
1129
1135
  }
1130
1136
  listen(node, type, callback) {
1131
1137
  node.addEventListener(type, callback);
@@ -1179,20 +1185,30 @@ let DomRenderer = DomRenderer_1 = class DomRenderer {
1179
1185
  return;
1180
1186
  }
1181
1187
  target.setAttribute(key, value);
1182
- const propNames = this.formElement[target.tagName.toLowerCase()];
1183
- if (propNames && propNames.includes(key)) {
1188
+ const tag = target.tagName.toLowerCase();
1189
+ const booleanTagNames = this.booleanProps[tag];
1190
+ const valueTagNames = this.valueProps[tag];
1191
+ if (booleanTagNames && booleanTagNames.includes(key)) {
1184
1192
  target[key] = Boolean(value);
1185
1193
  }
1194
+ if (valueTagNames && valueTagNames.includes(key)) {
1195
+ target[key] = value;
1196
+ }
1186
1197
  }
1187
1198
  removeAttribute(target, key) {
1188
1199
  if (this.possibleXlinkNames[key]) {
1189
1200
  this.removeXlinkAttribute(target, this.possibleXlinkNames[key]);
1190
1201
  }
1191
1202
  target.removeAttribute(key);
1192
- const propNames = this.formElement[target.tagName.toLowerCase()];
1193
- if (propNames && propNames.includes(key)) {
1203
+ const tag = target.tagName.toLowerCase();
1204
+ const booleanTagNames = this.booleanProps[tag];
1205
+ const valueTagNames = this.valueProps[tag];
1206
+ if (booleanTagNames && booleanTagNames.includes(key)) {
1194
1207
  target[key] = false;
1195
1208
  }
1209
+ if (valueTagNames && valueTagNames.includes(key)) {
1210
+ target[key] = '';
1211
+ }
1196
1212
  }
1197
1213
  setXlinkAttribute(target, key, value) {
1198
1214
  target.setAttributeNS(this.xlinkNameSpace, key, value);
@@ -1986,13 +2002,14 @@ let NativeInput = class NativeInput extends Input {
1986
2002
  get disabled() {
1987
2003
  return this._disabled;
1988
2004
  }
1989
- constructor(injector, parser, scheduler, selection, keyboard, commander, controller) {
2005
+ constructor(injector, parser, scheduler, selection, keyboard, renderer, commander, controller) {
1990
2006
  super();
1991
2007
  this.injector = injector;
1992
2008
  this.parser = parser;
1993
2009
  this.scheduler = scheduler;
1994
2010
  this.selection = selection;
1995
2011
  this.keyboard = keyboard;
2012
+ this.renderer = renderer;
1996
2013
  this.commander = commander;
1997
2014
  this.controller = controller;
1998
2015
  this.caret = new NativeCaret(this.scheduler);
@@ -2163,15 +2180,35 @@ let NativeInput = class NativeInput extends Input {
2163
2180
  data: ev.data
2164
2181
  });
2165
2182
  invokeListener(startSlot.parent, 'onCompositionUpdate', event);
2166
- }), merge(fromEvent(input, 'beforeinput').pipe(filter(ev => {
2183
+ }), merge(fromEvent(input, 'beforeinput').pipe(map(ev => {
2184
+ var _a;
2167
2185
  ev.preventDefault();
2186
+ if (ev.inputType === 'insertCompositionText') {
2187
+ return null;
2188
+ }
2189
+ if (ev.inputType === 'insertReplacementText') {
2190
+ const range = ev.getTargetRanges()[0];
2191
+ const location = this.renderer.getLocationByNativeNode(range.startContainer);
2192
+ const startSlot = this.selection.startSlot;
2193
+ this.selection.setBaseAndExtent(startSlot, location.startIndex + range.startOffset, startSlot, location.startIndex + range.endOffset);
2194
+ this.commander.delete();
2195
+ return ((_a = ev.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData('text')) || ev.data || null;
2196
+ }
2197
+ isCompositionEnd = ev.inputType === 'insertFromComposition';
2198
+ if (isCompositionEnd && this.composition) {
2199
+ return null;
2200
+ }
2168
2201
  if (this.isSafari) {
2169
- isCompositionEnd = ev.inputType === 'insertFromComposition';
2170
- return ev.inputType === 'insertText' || ev.inputType === 'insertFromComposition';
2202
+ if (ev.inputType === 'insertText' || isCompositionEnd) {
2203
+ return ev.data;
2204
+ }
2171
2205
  }
2172
- return !ev.isComposing && !!ev.data;
2173
- }), map(ev => {
2174
- return ev.data;
2206
+ if (!ev.isComposing && !!ev.data) {
2207
+ return ev.data;
2208
+ }
2209
+ return null;
2210
+ }), filter(text => {
2211
+ return text;
2175
2212
  })), this.isSafari ? new Observable() : fromEvent(input, 'compositionend').pipe(map(ev => {
2176
2213
  isCompositionEnd = true;
2177
2214
  ev.preventDefault();
@@ -2204,6 +2241,7 @@ NativeInput = __decorate([
2204
2241
  Scheduler,
2205
2242
  Selection,
2206
2243
  Keyboard,
2244
+ Renderer,
2207
2245
  Commander,
2208
2246
  Controller])
2209
2247
  ], NativeInput);
package/bundles/index.js CHANGED
@@ -1120,14 +1120,20 @@ exports.DomRenderer = DomRenderer_1 = class DomRenderer {
1120
1120
  xlinktype: 'xlink:type',
1121
1121
  'xlink:type': 'xlink:type'
1122
1122
  };
1123
- this.formElement = {
1124
- input: ['disabled', 'readonly', 'value'],
1123
+ this.booleanProps = {
1124
+ input: ['disabled', 'readonly'],
1125
1125
  select: ['disabled', 'readonly'],
1126
- option: ['disabled', 'selected', 'value'],
1126
+ option: ['disabled', 'selected'],
1127
1127
  button: ['disabled'],
1128
1128
  video: ['controls', 'autoplay', 'loop', 'muted'],
1129
1129
  audio: ['controls', 'autoplay', 'loop', 'muted'],
1130
1130
  };
1131
+ this.valueProps = {
1132
+ input: ['value'],
1133
+ option: ['value'],
1134
+ video: ['src'],
1135
+ audio: ['src']
1136
+ };
1131
1137
  }
1132
1138
  listen(node, type, callback) {
1133
1139
  node.addEventListener(type, callback);
@@ -1181,20 +1187,30 @@ exports.DomRenderer = DomRenderer_1 = class DomRenderer {
1181
1187
  return;
1182
1188
  }
1183
1189
  target.setAttribute(key, value);
1184
- const propNames = this.formElement[target.tagName.toLowerCase()];
1185
- if (propNames && propNames.includes(key)) {
1190
+ const tag = target.tagName.toLowerCase();
1191
+ const booleanTagNames = this.booleanProps[tag];
1192
+ const valueTagNames = this.valueProps[tag];
1193
+ if (booleanTagNames && booleanTagNames.includes(key)) {
1186
1194
  target[key] = Boolean(value);
1187
1195
  }
1196
+ if (valueTagNames && valueTagNames.includes(key)) {
1197
+ target[key] = value;
1198
+ }
1188
1199
  }
1189
1200
  removeAttribute(target, key) {
1190
1201
  if (this.possibleXlinkNames[key]) {
1191
1202
  this.removeXlinkAttribute(target, this.possibleXlinkNames[key]);
1192
1203
  }
1193
1204
  target.removeAttribute(key);
1194
- const propNames = this.formElement[target.tagName.toLowerCase()];
1195
- if (propNames && propNames.includes(key)) {
1205
+ const tag = target.tagName.toLowerCase();
1206
+ const booleanTagNames = this.booleanProps[tag];
1207
+ const valueTagNames = this.valueProps[tag];
1208
+ if (booleanTagNames && booleanTagNames.includes(key)) {
1196
1209
  target[key] = false;
1197
1210
  }
1211
+ if (valueTagNames && valueTagNames.includes(key)) {
1212
+ target[key] = '';
1213
+ }
1198
1214
  }
1199
1215
  setXlinkAttribute(target, key, value) {
1200
1216
  target.setAttributeNS(this.xlinkNameSpace, key, value);
@@ -1988,13 +2004,14 @@ exports.NativeInput = class NativeInput extends Input {
1988
2004
  get disabled() {
1989
2005
  return this._disabled;
1990
2006
  }
1991
- constructor(injector, parser, scheduler, selection, keyboard, commander, controller) {
2007
+ constructor(injector, parser, scheduler, selection, keyboard, renderer, commander, controller) {
1992
2008
  super();
1993
2009
  this.injector = injector;
1994
2010
  this.parser = parser;
1995
2011
  this.scheduler = scheduler;
1996
2012
  this.selection = selection;
1997
2013
  this.keyboard = keyboard;
2014
+ this.renderer = renderer;
1998
2015
  this.commander = commander;
1999
2016
  this.controller = controller;
2000
2017
  this.caret = new NativeCaret(this.scheduler);
@@ -2165,15 +2182,35 @@ exports.NativeInput = class NativeInput extends Input {
2165
2182
  data: ev.data
2166
2183
  });
2167
2184
  core.invokeListener(startSlot.parent, 'onCompositionUpdate', event);
2168
- }), stream.merge(stream.fromEvent(input, 'beforeinput').pipe(stream.filter(ev => {
2185
+ }), stream.merge(stream.fromEvent(input, 'beforeinput').pipe(stream.map(ev => {
2186
+ var _a;
2169
2187
  ev.preventDefault();
2188
+ if (ev.inputType === 'insertCompositionText') {
2189
+ return null;
2190
+ }
2191
+ if (ev.inputType === 'insertReplacementText') {
2192
+ const range = ev.getTargetRanges()[0];
2193
+ const location = this.renderer.getLocationByNativeNode(range.startContainer);
2194
+ const startSlot = this.selection.startSlot;
2195
+ this.selection.setBaseAndExtent(startSlot, location.startIndex + range.startOffset, startSlot, location.startIndex + range.endOffset);
2196
+ this.commander.delete();
2197
+ return ((_a = ev.dataTransfer) === null || _a === void 0 ? void 0 : _a.getData('text')) || ev.data || null;
2198
+ }
2199
+ isCompositionEnd = ev.inputType === 'insertFromComposition';
2200
+ if (isCompositionEnd && this.composition) {
2201
+ return null;
2202
+ }
2170
2203
  if (this.isSafari) {
2171
- isCompositionEnd = ev.inputType === 'insertFromComposition';
2172
- return ev.inputType === 'insertText' || ev.inputType === 'insertFromComposition';
2204
+ if (ev.inputType === 'insertText' || isCompositionEnd) {
2205
+ return ev.data;
2206
+ }
2173
2207
  }
2174
- return !ev.isComposing && !!ev.data;
2175
- }), stream.map(ev => {
2176
- return ev.data;
2208
+ if (!ev.isComposing && !!ev.data) {
2209
+ return ev.data;
2210
+ }
2211
+ return null;
2212
+ }), stream.filter(text => {
2213
+ return text;
2177
2214
  })), this.isSafari ? new stream.Observable() : stream.fromEvent(input, 'compositionend').pipe(stream.map(ev => {
2178
2215
  isCompositionEnd = true;
2179
2216
  ev.preventDefault();
@@ -2206,6 +2243,7 @@ exports.NativeInput = __decorate([
2206
2243
  core.Scheduler,
2207
2244
  core.Selection,
2208
2245
  core.Keyboard,
2246
+ core.Renderer,
2209
2247
  core.Commander,
2210
2248
  core.Controller])
2211
2249
  ], exports.NativeInput);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
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": "a74f952c6e72e51005208e0b79921007e11bb6b0"
51
+ "gitHead": "01d6397297fa0999b4ef6ffef3ae36b37118ad44"
52
52
  }