@contentful/field-editor-rich-text 2.0.0-next.32 → 2.0.0-next.33

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.
@@ -6120,6 +6120,229 @@ var onKeyDownTable = function onKeyDownTable(editor, plugin) {
6120
6120
  };
6121
6121
  };
6122
6122
 
6123
+ var _extends2, _extends4, _inlines;
6124
+ var inlines = /*#__PURE__*/Object.values(INLINES).map(function (type) {
6125
+ return {
6126
+ type: type
6127
+ };
6128
+ });
6129
+ var schema = {
6130
+ document: {
6131
+ nodes: [{
6132
+ types: /*#__PURE__*/TOP_LEVEL_BLOCKS.map(function (type) {
6133
+ return {
6134
+ type: type
6135
+ };
6136
+ })
6137
+ }]
6138
+ },
6139
+ blocks: /*#__PURE__*/_extends((_extends2 = {}, _extends2[BLOCKS.PARAGRAPH] = {
6140
+ nodes: [{
6141
+ match: /*#__PURE__*/[].concat(inlines, [{
6142
+ object: 'text'
6143
+ }])
6144
+ }]
6145
+ }, _extends2[BLOCKS.HEADING_1] = {
6146
+ nodes: [{
6147
+ match: /*#__PURE__*/[].concat(inlines, [{
6148
+ object: 'text'
6149
+ }])
6150
+ }]
6151
+ }, _extends2[BLOCKS.HEADING_2] = {
6152
+ nodes: [{
6153
+ match: /*#__PURE__*/[].concat(inlines, [{
6154
+ object: 'text'
6155
+ }])
6156
+ }]
6157
+ }, _extends2[BLOCKS.HEADING_3] = {
6158
+ nodes: [{
6159
+ match: /*#__PURE__*/[].concat(inlines, [{
6160
+ object: 'text'
6161
+ }])
6162
+ }]
6163
+ }, _extends2[BLOCKS.HEADING_4] = {
6164
+ nodes: [{
6165
+ match: /*#__PURE__*/[].concat(inlines, [{
6166
+ object: 'text'
6167
+ }])
6168
+ }]
6169
+ }, _extends2[BLOCKS.HEADING_5] = {
6170
+ nodes: [{
6171
+ match: /*#__PURE__*/[].concat(inlines, [{
6172
+ object: 'text'
6173
+ }])
6174
+ }]
6175
+ }, _extends2[BLOCKS.HEADING_6] = {
6176
+ nodes: [{
6177
+ match: /*#__PURE__*/[].concat(inlines, [{
6178
+ object: 'text'
6179
+ }])
6180
+ }]
6181
+ }, _extends2), /*#__PURE__*/VOID_BLOCKS.reduce(function (blocks, nodeType) {
6182
+ var _extends3;
6183
+
6184
+ return _extends({}, blocks, (_extends3 = {}, _extends3[nodeType] = {
6185
+ isVoid: true
6186
+ }, _extends3));
6187
+ }, {}), (_extends4 = {}, _extends4[BLOCKS.QUOTE] = {
6188
+ nodes: [{
6189
+ match: [/*#__PURE__*/CONTAINERS[BLOCKS.QUOTE].map(function (type) {
6190
+ return {
6191
+ type: type
6192
+ };
6193
+ })],
6194
+ min: 1
6195
+ }],
6196
+ normalize: function normalize(editor, error) {
6197
+ if (error.code === 'child_type_invalid') {
6198
+ return editor.unwrapBlockByKey(error.node.key, BLOCKS.QUOTE);
6199
+ }
6200
+ }
6201
+ }, _extends4)),
6202
+ inlines: (_inlines = {}, _inlines[INLINES.HYPERLINK] = {
6203
+ nodes: [{
6204
+ match: [{
6205
+ object: 'text'
6206
+ }]
6207
+ }]
6208
+ }, _inlines[INLINES.ENTRY_HYPERLINK] = {
6209
+ nodes: [{
6210
+ match: [{
6211
+ object: 'text'
6212
+ }]
6213
+ }]
6214
+ }, _inlines[INLINES.ASSET_HYPERLINK] = {
6215
+ nodes: [{
6216
+ match: [{
6217
+ object: 'text'
6218
+ }]
6219
+ }]
6220
+ }, _inlines[INLINES.EMBEDDED_ENTRY] = {
6221
+ isVoid: true
6222
+ }, _inlines)
6223
+ };
6224
+
6225
+ function getCharacterCount(editor) {
6226
+ var document = toContentfulDocument({
6227
+ document: editor.children,
6228
+ schema: schema
6229
+ });
6230
+ return documentToPlainTextString(document).length;
6231
+ }
6232
+
6233
+ var actionOrigin = {
6234
+ TOOLBAR: 'toolbar-icon',
6235
+ SHORTCUT: 'shortcut',
6236
+ VIEWPORT: 'viewport-interaction',
6237
+ COMMAND_PALETTE: 'command-palette'
6238
+ };
6239
+ function getPastingSource(data) {
6240
+ var textHtml = data.getData('text/html');
6241
+ var doc = new DOMParser().parseFromString(textHtml, 'text/html');
6242
+
6243
+ if (doc.querySelector('[id*="docs-internal-guid"]')) {
6244
+ return 'Google Docs';
6245
+ }
6246
+
6247
+ if (doc.querySelector('google-sheets-html-origin') || doc.querySelector('[data-sheets-value]')) {
6248
+ return 'Google Spreadsheets';
6249
+ }
6250
+
6251
+ if (doc.querySelector('meta[content*="Microsoft Excel"]')) {
6252
+ return 'Microsoft Excel';
6253
+ }
6254
+
6255
+ if (doc.querySelector('meta[content*="Microsoft Word"]')) {
6256
+ return 'Microsoft Word';
6257
+ } // TODO: MS Word Online doesn't give us specific tags, we might need to have a closer look at its tracking result since we are using generic values to identify it
6258
+
6259
+
6260
+ if (doc.querySelector('[style*="Arial_MSFontService"]') && (doc.querySelector('.TextRun') || doc.querySelector('.OutlineElement'))) {
6261
+ return 'Microsoft Word Online';
6262
+ }
6263
+
6264
+ if (doc.querySelector('meta[content="Cocoa HTML Writer"]')) {
6265
+ return 'Apple Notes';
6266
+ }
6267
+
6268
+ if (doc.querySelector('[style*="Slack-Lato, Slack-Fractions"]')) {
6269
+ return 'Slack';
6270
+ }
6271
+
6272
+ return 'Unknown';
6273
+ }
6274
+ var createTrackingPlugin = function createTrackingPlugin(onAction) {
6275
+ var trackingActions = {
6276
+ onViewportAction: function onViewportAction(actionName, data) {
6277
+ if (data === void 0) {
6278
+ data = {};
6279
+ }
6280
+
6281
+ return onAction(actionName, _extends({
6282
+ origin: actionOrigin.VIEWPORT
6283
+ }, data));
6284
+ },
6285
+ onShortcutAction: function onShortcutAction(actionName, data) {
6286
+ if (data === void 0) {
6287
+ data = {};
6288
+ }
6289
+
6290
+ return onAction(actionName, _extends({
6291
+ origin: actionOrigin.SHORTCUT
6292
+ }, data));
6293
+ },
6294
+ onToolbarAction: function onToolbarAction(actionName, data) {
6295
+ if (data === void 0) {
6296
+ data = {};
6297
+ }
6298
+
6299
+ return onAction(actionName, _extends({
6300
+ origin: actionOrigin.TOOLBAR
6301
+ }, data));
6302
+ },
6303
+ onCommandPaletteAction: function onCommandPaletteAction(actionName, data) {
6304
+ if (data === void 0) {
6305
+ data = {};
6306
+ }
6307
+
6308
+ return onAction(actionName, _extends({
6309
+ origin: actionOrigin.COMMAND_PALETTE
6310
+ }, data));
6311
+ }
6312
+ };
6313
+ return {
6314
+ key: 'TrackingPlugin',
6315
+ withOverrides: function withOverrides(editor) {
6316
+ var insertData = editor.insertData;
6317
+ editor.tracking = trackingActions;
6318
+
6319
+ editor.insertData = function (data) {
6320
+ var isCopyAndPaste = data.types.length !== 0;
6321
+
6322
+ if (isCopyAndPaste) {
6323
+ var _window$getSelection;
6324
+
6325
+ var characterCountSelection = (_window$getSelection = window.getSelection()) == null ? void 0 : _window$getSelection.toString().length;
6326
+ var characterCountBefore = getCharacterCount(editor);
6327
+ setTimeout(function () {
6328
+ var characterCountAfter = getCharacterCount(editor);
6329
+ trackingActions.onShortcutAction('paste', {
6330
+ characterCountAfter: characterCountAfter,
6331
+ characterCountBefore: characterCountBefore,
6332
+ characterCountSelection: characterCountSelection,
6333
+ source: getPastingSource(data)
6334
+ });
6335
+ });
6336
+ }
6337
+
6338
+ insertData(data);
6339
+ };
6340
+
6341
+ return editor;
6342
+ }
6343
+ };
6344
+ };
6345
+
6123
6346
  function hasTables(nodes) {
6124
6347
  return nodes.some(function (_ref) {
6125
6348
  var type = _ref.type;
@@ -6161,6 +6384,7 @@ function addTableTrackingEvents(editor) {
6161
6384
  if (hasTables(markupAfter)) {
6162
6385
  editor.tracking.onViewportAction('paste', {
6163
6386
  tablePasted: true,
6387
+ source: getPastingSource(data),
6164
6388
  hasHeadersOutsideFirstRow: hasHeadersOutsideFirstRow(markupAfter)
6165
6389
  });
6166
6390
  }
@@ -6414,237 +6638,6 @@ function deleteFirstEmptyParagraph(unit, editor, deleteFunction) {
6414
6638
  }
6415
6639
  }
6416
6640
 
6417
- var _extends2, _extends4, _inlines;
6418
- var inlines = /*#__PURE__*/Object.values(INLINES).map(function (type) {
6419
- return {
6420
- type: type
6421
- };
6422
- });
6423
- var schema = {
6424
- document: {
6425
- nodes: [{
6426
- types: /*#__PURE__*/TOP_LEVEL_BLOCKS.map(function (type) {
6427
- return {
6428
- type: type
6429
- };
6430
- })
6431
- }]
6432
- },
6433
- blocks: /*#__PURE__*/_extends((_extends2 = {}, _extends2[BLOCKS.PARAGRAPH] = {
6434
- nodes: [{
6435
- match: /*#__PURE__*/[].concat(inlines, [{
6436
- object: 'text'
6437
- }])
6438
- }]
6439
- }, _extends2[BLOCKS.HEADING_1] = {
6440
- nodes: [{
6441
- match: /*#__PURE__*/[].concat(inlines, [{
6442
- object: 'text'
6443
- }])
6444
- }]
6445
- }, _extends2[BLOCKS.HEADING_2] = {
6446
- nodes: [{
6447
- match: /*#__PURE__*/[].concat(inlines, [{
6448
- object: 'text'
6449
- }])
6450
- }]
6451
- }, _extends2[BLOCKS.HEADING_3] = {
6452
- nodes: [{
6453
- match: /*#__PURE__*/[].concat(inlines, [{
6454
- object: 'text'
6455
- }])
6456
- }]
6457
- }, _extends2[BLOCKS.HEADING_4] = {
6458
- nodes: [{
6459
- match: /*#__PURE__*/[].concat(inlines, [{
6460
- object: 'text'
6461
- }])
6462
- }]
6463
- }, _extends2[BLOCKS.HEADING_5] = {
6464
- nodes: [{
6465
- match: /*#__PURE__*/[].concat(inlines, [{
6466
- object: 'text'
6467
- }])
6468
- }]
6469
- }, _extends2[BLOCKS.HEADING_6] = {
6470
- nodes: [{
6471
- match: /*#__PURE__*/[].concat(inlines, [{
6472
- object: 'text'
6473
- }])
6474
- }]
6475
- }, _extends2), /*#__PURE__*/VOID_BLOCKS.reduce(function (blocks, nodeType) {
6476
- var _extends3;
6477
-
6478
- return _extends({}, blocks, (_extends3 = {}, _extends3[nodeType] = {
6479
- isVoid: true
6480
- }, _extends3));
6481
- }, {}), (_extends4 = {}, _extends4[BLOCKS.QUOTE] = {
6482
- nodes: [{
6483
- match: [/*#__PURE__*/CONTAINERS[BLOCKS.QUOTE].map(function (type) {
6484
- return {
6485
- type: type
6486
- };
6487
- })],
6488
- min: 1
6489
- }],
6490
- normalize: function normalize(editor, error) {
6491
- if (error.code === 'child_type_invalid') {
6492
- return editor.unwrapBlockByKey(error.node.key, BLOCKS.QUOTE);
6493
- }
6494
- }
6495
- }, _extends4)),
6496
- inlines: (_inlines = {}, _inlines[INLINES.HYPERLINK] = {
6497
- nodes: [{
6498
- match: [{
6499
- object: 'text'
6500
- }]
6501
- }]
6502
- }, _inlines[INLINES.ENTRY_HYPERLINK] = {
6503
- nodes: [{
6504
- match: [{
6505
- object: 'text'
6506
- }]
6507
- }]
6508
- }, _inlines[INLINES.ASSET_HYPERLINK] = {
6509
- nodes: [{
6510
- match: [{
6511
- object: 'text'
6512
- }]
6513
- }]
6514
- }, _inlines[INLINES.EMBEDDED_ENTRY] = {
6515
- isVoid: true
6516
- }, _inlines)
6517
- };
6518
-
6519
- function getCharacterCount(editor) {
6520
- var document = toContentfulDocument({
6521
- document: editor.children,
6522
- schema: schema
6523
- });
6524
- return documentToPlainTextString(document).length;
6525
- }
6526
-
6527
- var actionOrigin = {
6528
- TOOLBAR: 'toolbar-icon',
6529
- SHORTCUT: 'shortcut',
6530
- VIEWPORT: 'viewport-interaction',
6531
- COMMAND_PALETTE: 'command-palette'
6532
- };
6533
-
6534
- function getPastingSource(data) {
6535
- var textHtml = data.getData('text/html');
6536
- var doc = new DOMParser().parseFromString(textHtml, 'text/html');
6537
-
6538
- if (doc.querySelector('[id*="docs-internal-guid"]')) {
6539
- return 'Google Docs';
6540
- }
6541
-
6542
- if (doc.querySelector('google-sheets-html-origin') || doc.querySelector('[data-sheets-value]')) {
6543
- return 'Google Spreadsheets';
6544
- }
6545
-
6546
- if (doc.querySelector('meta[content*="Microsoft Excel"]')) {
6547
- return 'Microsoft Excel';
6548
- }
6549
-
6550
- if (doc.querySelector('meta[content*="Microsoft Word"]')) {
6551
- return 'Microsoft Word';
6552
- } // TODO: MS Word Online doesn't give us specific tags, we might need to have a closer look at its tracking result since we are using generic values to identify it
6553
-
6554
-
6555
- if (doc.querySelector('[style*="Arial_MSFontService"]') && (doc.querySelector('.TextRun') || doc.querySelector('.OutlineElement'))) {
6556
- return 'Microsoft Word Online';
6557
- }
6558
-
6559
- if (doc.querySelector('meta[content="Cocoa HTML Writer"]')) {
6560
- return 'Apple Notes';
6561
- }
6562
-
6563
- if (doc.querySelector('[style*="Slack-Lato, Slack-Fractions"]')) {
6564
- return 'Slack';
6565
- }
6566
-
6567
- return '';
6568
- }
6569
-
6570
- var createTrackingPlugin = function createTrackingPlugin(onAction) {
6571
- var trackingActions = {
6572
- onViewportAction: function onViewportAction(actionName, data) {
6573
- if (data === void 0) {
6574
- data = {};
6575
- }
6576
-
6577
- return onAction(actionName, _extends({
6578
- origin: actionOrigin.VIEWPORT
6579
- }, data));
6580
- },
6581
- onShortcutAction: function onShortcutAction(actionName, data) {
6582
- if (data === void 0) {
6583
- data = {};
6584
- }
6585
-
6586
- return onAction(actionName, _extends({
6587
- origin: actionOrigin.SHORTCUT
6588
- }, data));
6589
- },
6590
- onToolbarAction: function onToolbarAction(actionName, data) {
6591
- if (data === void 0) {
6592
- data = {};
6593
- }
6594
-
6595
- return onAction(actionName, _extends({
6596
- origin: actionOrigin.TOOLBAR
6597
- }, data));
6598
- },
6599
- onCommandPaletteAction: function onCommandPaletteAction(actionName, data) {
6600
- if (data === void 0) {
6601
- data = {};
6602
- }
6603
-
6604
- return onAction(actionName, _extends({
6605
- origin: actionOrigin.COMMAND_PALETTE
6606
- }, data));
6607
- }
6608
- };
6609
- return {
6610
- key: 'TrackingPlugin',
6611
- withOverrides: function withOverrides(editor) {
6612
- var insertData = editor.insertData;
6613
- editor.tracking = trackingActions;
6614
-
6615
- editor.insertData = function (data) {
6616
- var isCopyAndPaste = data.types.length !== 0;
6617
-
6618
- if (isCopyAndPaste) {
6619
- var _window$getSelection;
6620
-
6621
- var characterCountSelection = (_window$getSelection = window.getSelection()) == null ? void 0 : _window$getSelection.toString().length;
6622
- var characterCountBefore = getCharacterCount(editor);
6623
- setTimeout(function () {
6624
- var characterCountAfter = getCharacterCount(editor);
6625
- var payload = {
6626
- characterCountAfter: characterCountAfter,
6627
- characterCountBefore: characterCountBefore,
6628
- characterCountSelection: characterCountSelection
6629
- };
6630
- var source = getPastingSource(data);
6631
-
6632
- if (source) {
6633
- payload.source = source;
6634
- }
6635
-
6636
- trackingActions.onShortcutAction('paste', payload);
6637
- });
6638
- }
6639
-
6640
- insertData(data);
6641
- };
6642
-
6643
- return editor;
6644
- }
6645
- };
6646
- };
6647
-
6648
6641
  var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
6649
6642
  return createTrailingBlockPlugin({
6650
6643
  options: {