@textbus/platform-browser 3.0.0-alpha.41 → 3.0.0-alpha.42

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.
@@ -52,5 +52,4 @@ export declare class Parser {
52
52
  private readComponent;
53
53
  private readFormats;
54
54
  private readSlot;
55
- private applyFormats;
56
55
  }
@@ -1250,11 +1250,9 @@ let Parser = Parser_1 = class Parser {
1250
1250
  }
1251
1251
  parse(html, rootSlot) {
1252
1252
  const element = Parser_1.parseHTML(html);
1253
- const formatItems = this.readFormats(element, rootSlot, []);
1254
- this.applyFormats(rootSlot, formatItems);
1255
- return rootSlot;
1253
+ return this.readFormats(element, rootSlot);
1256
1254
  }
1257
- readComponent(el, slot, formatItems) {
1255
+ readComponent(el, slot) {
1258
1256
  if (el.nodeType === Node.ELEMENT_NODE) {
1259
1257
  if (el.tagName === 'BR') {
1260
1258
  slot.insert('\n');
@@ -1273,7 +1271,7 @@ let Parser = Parser_1 = class Parser {
1273
1271
  return;
1274
1272
  }
1275
1273
  }
1276
- this.readFormats(el, slot, formatItems);
1274
+ this.readFormats(el, slot);
1277
1275
  }
1278
1276
  else if (el.nodeType === Node.TEXT_NODE) {
1279
1277
  const textContent = el.textContent;
@@ -1283,26 +1281,21 @@ let Parser = Parser_1 = class Parser {
1283
1281
  slot.insert(textContent);
1284
1282
  }
1285
1283
  }
1286
- readFormats(el, slot, formatItems) {
1287
- const formats = this.formatLoaders.filter(f => {
1284
+ readFormats(el, slot) {
1285
+ this.formatLoaders.filter(f => {
1288
1286
  return f.match(el);
1289
- }).map(f => {
1290
- return f.read(el);
1287
+ }).forEach(f => {
1288
+ const v = f.read(el);
1289
+ slot.applyFormat(v.formatter, {
1290
+ startIndex: 0,
1291
+ endIndex: slot.length,
1292
+ value: v.value
1293
+ });
1291
1294
  });
1292
- const startIndex = slot.index;
1293
1295
  Array.from(el.childNodes).forEach(child => {
1294
- this.readComponent(child, slot, formatItems);
1296
+ this.readComponent(child, slot);
1295
1297
  });
1296
- const endIndex = slot.index;
1297
- formatItems.unshift(...formats.map(i => {
1298
- return {
1299
- formatter: i.formatter,
1300
- value: i.value,
1301
- startIndex,
1302
- endIndex
1303
- };
1304
- }));
1305
- return formatItems;
1298
+ return slot;
1306
1299
  }
1307
1300
  readSlot(childSlot, slotRootElement, slotContentElement) {
1308
1301
  this.attributeLoaders.filter(a => {
@@ -1311,15 +1304,7 @@ let Parser = Parser_1 = class Parser {
1311
1304
  const r = a.read(slotRootElement);
1312
1305
  childSlot.setAttribute(r.attribute, r.value);
1313
1306
  });
1314
- const childFormatItems = this.readFormats(slotContentElement, childSlot, []);
1315
- this.applyFormats(childSlot, childFormatItems);
1316
- return childSlot;
1317
- }
1318
- applyFormats(slot, formatItems) {
1319
- formatItems.forEach(i => {
1320
- slot.retain(i.startIndex);
1321
- slot.retain(i.endIndex - i.startIndex, i.formatter, i.value);
1322
- });
1307
+ return this.readFormats(slotContentElement, childSlot);
1323
1308
  }
1324
1309
  };
1325
1310
  Parser = Parser_1 = __decorate([
package/bundles/index.js CHANGED
@@ -1252,11 +1252,9 @@ exports.Parser = Parser_1 = class Parser {
1252
1252
  }
1253
1253
  parse(html, rootSlot) {
1254
1254
  const element = Parser_1.parseHTML(html);
1255
- const formatItems = this.readFormats(element, rootSlot, []);
1256
- this.applyFormats(rootSlot, formatItems);
1257
- return rootSlot;
1255
+ return this.readFormats(element, rootSlot);
1258
1256
  }
1259
- readComponent(el, slot, formatItems) {
1257
+ readComponent(el, slot) {
1260
1258
  if (el.nodeType === Node.ELEMENT_NODE) {
1261
1259
  if (el.tagName === 'BR') {
1262
1260
  slot.insert('\n');
@@ -1275,7 +1273,7 @@ exports.Parser = Parser_1 = class Parser {
1275
1273
  return;
1276
1274
  }
1277
1275
  }
1278
- this.readFormats(el, slot, formatItems);
1276
+ this.readFormats(el, slot);
1279
1277
  }
1280
1278
  else if (el.nodeType === Node.TEXT_NODE) {
1281
1279
  const textContent = el.textContent;
@@ -1285,26 +1283,21 @@ exports.Parser = Parser_1 = class Parser {
1285
1283
  slot.insert(textContent);
1286
1284
  }
1287
1285
  }
1288
- readFormats(el, slot, formatItems) {
1289
- const formats = this.formatLoaders.filter(f => {
1286
+ readFormats(el, slot) {
1287
+ this.formatLoaders.filter(f => {
1290
1288
  return f.match(el);
1291
- }).map(f => {
1292
- return f.read(el);
1289
+ }).forEach(f => {
1290
+ const v = f.read(el);
1291
+ slot.applyFormat(v.formatter, {
1292
+ startIndex: 0,
1293
+ endIndex: slot.length,
1294
+ value: v.value
1295
+ });
1293
1296
  });
1294
- const startIndex = slot.index;
1295
1297
  Array.from(el.childNodes).forEach(child => {
1296
- this.readComponent(child, slot, formatItems);
1298
+ this.readComponent(child, slot);
1297
1299
  });
1298
- const endIndex = slot.index;
1299
- formatItems.unshift(...formats.map(i => {
1300
- return {
1301
- formatter: i.formatter,
1302
- value: i.value,
1303
- startIndex,
1304
- endIndex
1305
- };
1306
- }));
1307
- return formatItems;
1300
+ return slot;
1308
1301
  }
1309
1302
  readSlot(childSlot, slotRootElement, slotContentElement) {
1310
1303
  this.attributeLoaders.filter(a => {
@@ -1313,15 +1306,7 @@ exports.Parser = Parser_1 = class Parser {
1313
1306
  const r = a.read(slotRootElement);
1314
1307
  childSlot.setAttribute(r.attribute, r.value);
1315
1308
  });
1316
- const childFormatItems = this.readFormats(slotContentElement, childSlot, []);
1317
- this.applyFormats(childSlot, childFormatItems);
1318
- return childSlot;
1319
- }
1320
- applyFormats(slot, formatItems) {
1321
- formatItems.forEach(i => {
1322
- slot.retain(i.startIndex);
1323
- slot.retain(i.endIndex - i.startIndex, i.formatter, i.value);
1324
- });
1309
+ return this.readFormats(slotContentElement, childSlot);
1325
1310
  }
1326
1311
  };
1327
1312
  exports.Parser = Parser_1 = __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "3.0.0-alpha.41",
3
+ "version": "3.0.0-alpha.42",
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": "646cc933c5ab2f0fe0d4f28c4fb95d8a11b88891"
51
+ "gitHead": "5ac4dfb4ae18393afc93ffac9df4012d68adeffa"
52
52
  }