@textbus/platform-browser 3.4.5 → 3.4.9

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.
@@ -34,7 +34,7 @@ export interface ComponentLoader {
34
34
  /** 识别组件的匹配方法 */
35
35
  match(element: HTMLElement): boolean;
36
36
  /** 读取组件内容的方法 */
37
- read(element: HTMLElement, injector: Injector, slotParser: SlotParser): ComponentInstance | Slot;
37
+ read(element: HTMLElement, injector: Injector, slotParser: SlotParser): ComponentInstance | Slot | void;
38
38
  }
39
39
  export interface FormatLoaderReadResult<T extends FormatValue> {
40
40
  formatter: Formatter<T>;
@@ -90,7 +90,7 @@ export declare class Parser {
90
90
  * @param html
91
91
  * @param rootComponentLoader
92
92
  */
93
- parseDoc(html: string, rootComponentLoader: ComponentLoader): Slot<any> | ComponentInstance<import("@textbus/core").ComponentExtends, any, unknown>;
93
+ parseDoc(html: string, rootComponentLoader: ComponentLoader): void | Slot<any> | ComponentInstance<import("@textbus/core").ComponentExtends, any, unknown>;
94
94
  /**
95
95
  * 将一段 HTML 解析到指定插槽
96
96
  * @param html
@@ -98,6 +98,7 @@ export declare class Parser {
98
98
  */
99
99
  parse(html: string, rootSlot: Slot): Slot<any>;
100
100
  private readComponent;
101
+ private readText;
101
102
  private readFormats;
102
103
  private readSlot;
103
104
  private applyFormats;
@@ -1269,6 +1269,9 @@ let Parser = Parser_1 = class Parser {
1269
1269
  const result = t.read(el, this.injector, (childSlot, slotRootElement, slotContentHostElement = slotRootElement) => {
1270
1270
  return this.readSlot(childSlot, slotRootElement, slotContentHostElement);
1271
1271
  });
1272
+ if (!result) {
1273
+ return;
1274
+ }
1272
1275
  if (result instanceof Slot) {
1273
1276
  result.toDelta().forEach(i => slot.insert(i.insert, i.formats));
1274
1277
  return;
@@ -1280,12 +1283,15 @@ let Parser = Parser_1 = class Parser {
1280
1283
  this.readFormats(el, slot);
1281
1284
  }
1282
1285
  else if (el.nodeType === Node.TEXT_NODE) {
1283
- const textContent = el.textContent;
1284
- if (/^\s*[\r\n\u200b]+\s*$/.test(textContent)) {
1285
- return;
1286
- }
1287
- slot.insert(textContent);
1286
+ this.readText(slot, el);
1287
+ }
1288
+ }
1289
+ readText(slot, el) {
1290
+ const textContent = el.textContent;
1291
+ if (/^\s*[\r\n\u200b]+\s*$/.test(textContent)) {
1292
+ return;
1288
1293
  }
1294
+ slot.insert(textContent);
1289
1295
  }
1290
1296
  readFormats(el, slot) {
1291
1297
  const formats = this.formatLoaders.filter(f => {
@@ -1312,13 +1318,20 @@ let Parser = Parser_1 = class Parser {
1312
1318
  return slot;
1313
1319
  }
1314
1320
  readSlot(childSlot, slotRootElement, slotContentElement) {
1315
- this.attributeLoaders.filter(a => {
1316
- return a.match(slotRootElement);
1317
- }).forEach(a => {
1318
- const r = a.read(slotRootElement);
1319
- childSlot.setAttribute(r.attribute, r.value);
1320
- });
1321
- this.readFormats(slotContentElement, childSlot);
1321
+ if (slotRootElement.nodeType === Node.ELEMENT_NODE) {
1322
+ this.attributeLoaders.filter(a => {
1323
+ return a.match(slotRootElement);
1324
+ }).forEach(a => {
1325
+ const r = a.read(slotRootElement);
1326
+ childSlot.setAttribute(r.attribute, r.value);
1327
+ });
1328
+ }
1329
+ if (slotContentElement.nodeType === Node.ELEMENT_NODE) {
1330
+ this.readFormats(slotContentElement, childSlot);
1331
+ }
1332
+ else {
1333
+ this.readText(childSlot, slotContentElement);
1334
+ }
1322
1335
  return childSlot;
1323
1336
  }
1324
1337
  applyFormats(slot, formatItems) {
package/bundles/index.js CHANGED
@@ -1271,6 +1271,9 @@ exports.Parser = Parser_1 = class Parser {
1271
1271
  const result = t.read(el, this.injector, (childSlot, slotRootElement, slotContentHostElement = slotRootElement) => {
1272
1272
  return this.readSlot(childSlot, slotRootElement, slotContentHostElement);
1273
1273
  });
1274
+ if (!result) {
1275
+ return;
1276
+ }
1274
1277
  if (result instanceof core.Slot) {
1275
1278
  result.toDelta().forEach(i => slot.insert(i.insert, i.formats));
1276
1279
  return;
@@ -1282,12 +1285,15 @@ exports.Parser = Parser_1 = class Parser {
1282
1285
  this.readFormats(el, slot);
1283
1286
  }
1284
1287
  else if (el.nodeType === Node.TEXT_NODE) {
1285
- const textContent = el.textContent;
1286
- if (/^\s*[\r\n\u200b]+\s*$/.test(textContent)) {
1287
- return;
1288
- }
1289
- slot.insert(textContent);
1288
+ this.readText(slot, el);
1289
+ }
1290
+ }
1291
+ readText(slot, el) {
1292
+ const textContent = el.textContent;
1293
+ if (/^\s*[\r\n\u200b]+\s*$/.test(textContent)) {
1294
+ return;
1290
1295
  }
1296
+ slot.insert(textContent);
1291
1297
  }
1292
1298
  readFormats(el, slot) {
1293
1299
  const formats = this.formatLoaders.filter(f => {
@@ -1314,13 +1320,20 @@ exports.Parser = Parser_1 = class Parser {
1314
1320
  return slot;
1315
1321
  }
1316
1322
  readSlot(childSlot, slotRootElement, slotContentElement) {
1317
- this.attributeLoaders.filter(a => {
1318
- return a.match(slotRootElement);
1319
- }).forEach(a => {
1320
- const r = a.read(slotRootElement);
1321
- childSlot.setAttribute(r.attribute, r.value);
1322
- });
1323
- this.readFormats(slotContentElement, childSlot);
1323
+ if (slotRootElement.nodeType === Node.ELEMENT_NODE) {
1324
+ this.attributeLoaders.filter(a => {
1325
+ return a.match(slotRootElement);
1326
+ }).forEach(a => {
1327
+ const r = a.read(slotRootElement);
1328
+ childSlot.setAttribute(r.attribute, r.value);
1329
+ });
1330
+ }
1331
+ if (slotContentElement.nodeType === Node.ELEMENT_NODE) {
1332
+ this.readFormats(slotContentElement, childSlot);
1333
+ }
1334
+ else {
1335
+ this.readText(childSlot, slotContentElement);
1336
+ }
1324
1337
  return childSlot;
1325
1338
  }
1326
1339
  applyFormats(slot, formatItems) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "3.4.5",
3
+ "version": "3.4.9",
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": "81634d5c7c1439e514895dba49a4d1c73f2fd7ff"
51
+ "gitHead": "fe0b65d7da3ddadb9a6d311572c3e497154dcc86"
52
52
  }