@textbus/platform-browser 3.5.0 → 3.5.3

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.
@@ -86,17 +86,17 @@ export declare class Parser {
86
86
  attributeLoaders: AttributeLoader<any>[];
87
87
  constructor(options: ViewOptions, injector: Injector);
88
88
  /**
89
- * 使用指定的组件加载器解析一段 HTML 字符串
89
+ * 使用指定的组件加载器解析一段 HTML 字符串或 DOM 元素
90
90
  * @param html
91
91
  * @param rootComponentLoader
92
92
  */
93
- parseDoc(html: string, rootComponentLoader: ComponentLoader): void | Slot<any> | ComponentInstance<import("@textbus/core").ComponentExtends, any, unknown>;
93
+ parseDoc(html: string | HTMLElement, rootComponentLoader: ComponentLoader): void | Slot<any> | ComponentInstance<import("@textbus/core").ComponentExtends, any, unknown>;
94
94
  /**
95
- * 将一段 HTML 解析到指定插槽
95
+ * 将一段 HTML 或 DOM 元素解析到指定插槽
96
96
  * @param html
97
97
  * @param rootSlot
98
98
  */
99
- parse(html: string, rootSlot: Slot): Slot<any>;
99
+ parse(html: string | HTMLElement, rootSlot: Slot): Slot<any>;
100
100
  private readComponent;
101
101
  private readText;
102
102
  private readFormats;
@@ -1239,23 +1239,23 @@ let Parser = Parser_1 = class Parser {
1239
1239
  this.attributeLoaders = attributeLoaders;
1240
1240
  }
1241
1241
  /**
1242
- * 使用指定的组件加载器解析一段 HTML 字符串
1242
+ * 使用指定的组件加载器解析一段 HTML 字符串或 DOM 元素
1243
1243
  * @param html
1244
1244
  * @param rootComponentLoader
1245
1245
  */
1246
1246
  parseDoc(html, rootComponentLoader) {
1247
- const element = Parser_1.parseHTML(html);
1247
+ const element = typeof html === 'string' ? Parser_1.parseHTML(html) : html;
1248
1248
  return rootComponentLoader.read(element, this.injector, (childSlot, slotRootElement, slotContentHostElement = slotRootElement) => {
1249
1249
  return this.readSlot(childSlot, slotRootElement, slotContentHostElement);
1250
1250
  });
1251
1251
  }
1252
1252
  /**
1253
- * 将一段 HTML 解析到指定插槽
1253
+ * 将一段 HTML 或 DOM 元素解析到指定插槽
1254
1254
  * @param html
1255
1255
  * @param rootSlot
1256
1256
  */
1257
1257
  parse(html, rootSlot) {
1258
- const element = Parser_1.parseHTML(html);
1258
+ const element = typeof html === 'string' ? Parser_1.parseHTML(html) : html;
1259
1259
  return this.readFormats(element, rootSlot);
1260
1260
  }
1261
1261
  readComponent(el, slot) {
@@ -1739,17 +1739,14 @@ let MagicInput = class MagicInput extends Input {
1739
1739
  this.doc.body.appendChild(div);
1740
1740
  div.focus();
1741
1741
  setTimeout(() => {
1742
- let html = div.innerHTML;
1743
- if (!html && text && this.isFirefox) {
1744
- html = text;
1745
- }
1746
- this.handlePaste(html, text);
1747
1742
  this.doc.body.removeChild(div);
1743
+ div.style.cssText = '';
1744
+ this.handlePaste(div, text);
1748
1745
  });
1749
1746
  }));
1750
1747
  }
1751
- handlePaste(html, text) {
1752
- const slot = this.parser.parse(html, new Slot([
1748
+ handlePaste(dom, text) {
1749
+ const slot = this.parser.parse(dom, new Slot([
1753
1750
  ContentType.BlockComponent,
1754
1751
  ContentType.InlineComponent,
1755
1752
  ContentType.Text
@@ -2118,14 +2115,14 @@ let NativeInput = class NativeInput extends Input {
2118
2115
  document.body.appendChild(div);
2119
2116
  div.focus();
2120
2117
  setTimeout(() => {
2121
- const html = div.innerHTML;
2122
- this.handlePaste(html, text);
2123
2118
  document.body.removeChild(div);
2119
+ div.style.cssText = '';
2120
+ this.handlePaste(div, text);
2124
2121
  });
2125
2122
  }));
2126
2123
  }
2127
- handlePaste(html, text) {
2128
- const slot = this.parser.parse(html, new Slot([
2124
+ handlePaste(dom, text) {
2125
+ const slot = this.parser.parse(dom, new Slot([
2129
2126
  ContentType.BlockComponent,
2130
2127
  ContentType.InlineComponent,
2131
2128
  ContentType.Text
@@ -2516,16 +2513,18 @@ class Viewer extends Starter {
2516
2513
  }, {
2517
2514
  provide: Viewer,
2518
2515
  useFactory: () => this
2519
- }];
2520
- super(Object.assign(Object.assign({}, options), { plugins: options.plugins || [], providers: [
2521
- ...(options.providers || []),
2522
- ...staticProviders,
2523
- DomRenderer,
2524
- Parser,
2525
- SelectionBridge,
2526
- OutputTranslator,
2527
- CollaborateCursor
2528
- ], setup: options.setup }));
2516
+ },
2517
+ DomRenderer,
2518
+ Parser,
2519
+ SelectionBridge,
2520
+ OutputTranslator,
2521
+ CollaborateCursor
2522
+ ];
2523
+ options.imports = options.imports || [];
2524
+ options.imports.push({
2525
+ providers: staticProviders
2526
+ });
2527
+ super(Object.assign(Object.assign({}, options), { plugins: options.plugins || [], providers: options.providers, setup: options.setup }));
2529
2528
  this.rootComponent = rootComponent;
2530
2529
  this.rootComponentLoader = rootComponentLoader;
2531
2530
  this.options = options;
package/bundles/index.js CHANGED
@@ -1241,23 +1241,23 @@ exports.Parser = Parser_1 = class Parser {
1241
1241
  this.attributeLoaders = attributeLoaders;
1242
1242
  }
1243
1243
  /**
1244
- * 使用指定的组件加载器解析一段 HTML 字符串
1244
+ * 使用指定的组件加载器解析一段 HTML 字符串或 DOM 元素
1245
1245
  * @param html
1246
1246
  * @param rootComponentLoader
1247
1247
  */
1248
1248
  parseDoc(html, rootComponentLoader) {
1249
- const element = Parser_1.parseHTML(html);
1249
+ const element = typeof html === 'string' ? Parser_1.parseHTML(html) : html;
1250
1250
  return rootComponentLoader.read(element, this.injector, (childSlot, slotRootElement, slotContentHostElement = slotRootElement) => {
1251
1251
  return this.readSlot(childSlot, slotRootElement, slotContentHostElement);
1252
1252
  });
1253
1253
  }
1254
1254
  /**
1255
- * 将一段 HTML 解析到指定插槽
1255
+ * 将一段 HTML 或 DOM 元素解析到指定插槽
1256
1256
  * @param html
1257
1257
  * @param rootSlot
1258
1258
  */
1259
1259
  parse(html, rootSlot) {
1260
- const element = Parser_1.parseHTML(html);
1260
+ const element = typeof html === 'string' ? Parser_1.parseHTML(html) : html;
1261
1261
  return this.readFormats(element, rootSlot);
1262
1262
  }
1263
1263
  readComponent(el, slot) {
@@ -1741,17 +1741,14 @@ exports.MagicInput = class MagicInput extends Input {
1741
1741
  this.doc.body.appendChild(div);
1742
1742
  div.focus();
1743
1743
  setTimeout(() => {
1744
- let html = div.innerHTML;
1745
- if (!html && text && this.isFirefox) {
1746
- html = text;
1747
- }
1748
- this.handlePaste(html, text);
1749
1744
  this.doc.body.removeChild(div);
1745
+ div.style.cssText = '';
1746
+ this.handlePaste(div, text);
1750
1747
  });
1751
1748
  }));
1752
1749
  }
1753
- handlePaste(html, text) {
1754
- const slot = this.parser.parse(html, new core.Slot([
1750
+ handlePaste(dom, text) {
1751
+ const slot = this.parser.parse(dom, new core.Slot([
1755
1752
  core.ContentType.BlockComponent,
1756
1753
  core.ContentType.InlineComponent,
1757
1754
  core.ContentType.Text
@@ -2120,14 +2117,14 @@ exports.NativeInput = class NativeInput extends Input {
2120
2117
  document.body.appendChild(div);
2121
2118
  div.focus();
2122
2119
  setTimeout(() => {
2123
- const html = div.innerHTML;
2124
- this.handlePaste(html, text);
2125
2120
  document.body.removeChild(div);
2121
+ div.style.cssText = '';
2122
+ this.handlePaste(div, text);
2126
2123
  });
2127
2124
  }));
2128
2125
  }
2129
- handlePaste(html, text) {
2130
- const slot = this.parser.parse(html, new core.Slot([
2126
+ handlePaste(dom, text) {
2127
+ const slot = this.parser.parse(dom, new core.Slot([
2131
2128
  core.ContentType.BlockComponent,
2132
2129
  core.ContentType.InlineComponent,
2133
2130
  core.ContentType.Text
@@ -2518,16 +2515,18 @@ class Viewer extends core.Starter {
2518
2515
  }, {
2519
2516
  provide: Viewer,
2520
2517
  useFactory: () => this
2521
- }];
2522
- super(Object.assign(Object.assign({}, options), { plugins: options.plugins || [], providers: [
2523
- ...(options.providers || []),
2524
- ...staticProviders,
2525
- exports.DomRenderer,
2526
- exports.Parser,
2527
- exports.SelectionBridge,
2528
- exports.OutputTranslator,
2529
- exports.CollaborateCursor
2530
- ], setup: options.setup }));
2518
+ },
2519
+ exports.DomRenderer,
2520
+ exports.Parser,
2521
+ exports.SelectionBridge,
2522
+ exports.OutputTranslator,
2523
+ exports.CollaborateCursor
2524
+ ];
2525
+ options.imports = options.imports || [];
2526
+ options.imports.push({
2527
+ providers: staticProviders
2528
+ });
2529
+ super(Object.assign(Object.assign({}, options), { plugins: options.plugins || [], providers: options.providers, setup: options.setup }));
2531
2530
  this.rootComponent = rootComponent;
2532
2531
  this.rootComponentLoader = rootComponentLoader;
2533
2532
  this.options = options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "3.5.0",
3
+ "version": "3.5.3",
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.5",
29
29
  "@tanbo/stream": "^1.2.0",
30
- "@textbus/core": "^3.5.0",
30
+ "@textbus/core": "^3.5.3",
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": "8792e92aa4b3dd1cc6f190a6585bdd4cfb933779"
51
+ "gitHead": "054ef00184c90bbef8632a892ee3d5a06bb67d46"
52
52
  }