@contentful/field-editor-rich-text 2.0.0-next.32 → 2.0.0-next.35
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.
- package/dist/field-editor-rich-text.cjs.development.js +249 -236
- package/dist/field-editor-rich-text.cjs.development.js.map +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js.map +1 -1
- package/dist/field-editor-rich-text.esm.js +250 -237
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/plugins/Tracking/createTrackingPlugin.d.ts +1 -0
- package/dist/test-utils/jsx.d.ts +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import React__default, { createContext, useContext, useMemo, createElement, useE
|
|
|
2
2
|
import { useEntities, ScheduledIconWithTooltip, MissingEntityCard, AssetThumbnail, EntityProvider, getScheduleTooltipContent } from '@contentful/field-editor-reference';
|
|
3
3
|
import { entityHelpers, shortenStorageUnit, isValidImage, ModalDialogLauncher, FieldConnector } from '@contentful/field-editor-shared';
|
|
4
4
|
import { BLOCKS, INLINES, TEXT_CONTAINERS, HEADINGS, LIST_ITEM_BLOCKS, MARKS, CONTAINERS, TOP_LEVEL_BLOCKS, VOID_BLOCKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
|
|
5
|
-
import { usePlateEditorRef, usePlateEditorState, getNodes, toggleNodeType, getText, getAbove, setNodes, isAncestorEmpty, match, getLastChildPath, wrapNodes, getPluginType, unwrapNodes, isCollapsed, isRangeAcrossBlocks, ELEMENT_DEFAULT, findNode, getParent, getBlockAbove, isSelectionAtBlockStart, isSelectionAtBlockEnd, isFirstChild, insertNodes, moveChildren, isBlockAboveEmpty, mockPlugin, deleteFragment, isMarkActive, toggleMark, someHtmlElement, KEY_DESERIALIZE_HTML, hasSingleChild, isLastChild, someNode, getChildren as getChildren$1, createDeserializeHtmlPlugin, createDeserializeAstPlugin, createPlateEditor, getPlateSelectors, getPlateActions, Plate } from '@udecode/plate-core';
|
|
5
|
+
import { usePlateEditorRef, usePlateEditorState, getNodes, toggleNodeType, getText, getAbove, setNodes, isAncestorEmpty, match, getLastChildPath, wrapNodes, getPluginType, unwrapNodes, isCollapsed, isRangeAcrossBlocks, ELEMENT_DEFAULT, findNode, getParent, getBlockAbove, isSelectionAtBlockStart, isSelectionAtBlockEnd, isFirstChild, insertNodes, moveChildren, isBlockAboveEmpty, mockPlugin, deleteFragment, isMarkActive, toggleMark, someHtmlElement, KEY_DESERIALIZE_HTML, hasSingleChild, isLastChild, someNode, getChildren as getChildren$1, queryNode, createDeserializeHtmlPlugin, createDeserializeAstPlugin, createPlateEditor, getPlateSelectors, getPlateActions, Plate } from '@udecode/plate-core';
|
|
6
6
|
import { css, cx } from 'emotion';
|
|
7
7
|
import deepEquals from 'fast-deep-equal';
|
|
8
8
|
import noop from 'lodash-es/noop';
|
|
@@ -5436,7 +5436,8 @@ var createSelectOnBackspacePlugin = function createSelectOnBackspacePlugin() {
|
|
|
5436
5436
|
return createSelectOnBackspacePlugin$1({
|
|
5437
5437
|
options: {
|
|
5438
5438
|
query: {
|
|
5439
|
-
|
|
5439
|
+
// `createTextPlugin` is taking care of block elements
|
|
5440
|
+
allow: [INLINES.EMBEDDED_ENTRY]
|
|
5440
5441
|
}
|
|
5441
5442
|
}
|
|
5442
5443
|
});
|
|
@@ -6120,6 +6121,229 @@ var onKeyDownTable = function onKeyDownTable(editor, plugin) {
|
|
|
6120
6121
|
};
|
|
6121
6122
|
};
|
|
6122
6123
|
|
|
6124
|
+
var _extends2, _extends4, _inlines;
|
|
6125
|
+
var inlines = /*#__PURE__*/Object.values(INLINES).map(function (type) {
|
|
6126
|
+
return {
|
|
6127
|
+
type: type
|
|
6128
|
+
};
|
|
6129
|
+
});
|
|
6130
|
+
var schema = {
|
|
6131
|
+
document: {
|
|
6132
|
+
nodes: [{
|
|
6133
|
+
types: /*#__PURE__*/TOP_LEVEL_BLOCKS.map(function (type) {
|
|
6134
|
+
return {
|
|
6135
|
+
type: type
|
|
6136
|
+
};
|
|
6137
|
+
})
|
|
6138
|
+
}]
|
|
6139
|
+
},
|
|
6140
|
+
blocks: /*#__PURE__*/_extends((_extends2 = {}, _extends2[BLOCKS.PARAGRAPH] = {
|
|
6141
|
+
nodes: [{
|
|
6142
|
+
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6143
|
+
object: 'text'
|
|
6144
|
+
}])
|
|
6145
|
+
}]
|
|
6146
|
+
}, _extends2[BLOCKS.HEADING_1] = {
|
|
6147
|
+
nodes: [{
|
|
6148
|
+
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6149
|
+
object: 'text'
|
|
6150
|
+
}])
|
|
6151
|
+
}]
|
|
6152
|
+
}, _extends2[BLOCKS.HEADING_2] = {
|
|
6153
|
+
nodes: [{
|
|
6154
|
+
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6155
|
+
object: 'text'
|
|
6156
|
+
}])
|
|
6157
|
+
}]
|
|
6158
|
+
}, _extends2[BLOCKS.HEADING_3] = {
|
|
6159
|
+
nodes: [{
|
|
6160
|
+
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6161
|
+
object: 'text'
|
|
6162
|
+
}])
|
|
6163
|
+
}]
|
|
6164
|
+
}, _extends2[BLOCKS.HEADING_4] = {
|
|
6165
|
+
nodes: [{
|
|
6166
|
+
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6167
|
+
object: 'text'
|
|
6168
|
+
}])
|
|
6169
|
+
}]
|
|
6170
|
+
}, _extends2[BLOCKS.HEADING_5] = {
|
|
6171
|
+
nodes: [{
|
|
6172
|
+
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6173
|
+
object: 'text'
|
|
6174
|
+
}])
|
|
6175
|
+
}]
|
|
6176
|
+
}, _extends2[BLOCKS.HEADING_6] = {
|
|
6177
|
+
nodes: [{
|
|
6178
|
+
match: /*#__PURE__*/[].concat(inlines, [{
|
|
6179
|
+
object: 'text'
|
|
6180
|
+
}])
|
|
6181
|
+
}]
|
|
6182
|
+
}, _extends2), /*#__PURE__*/VOID_BLOCKS.reduce(function (blocks, nodeType) {
|
|
6183
|
+
var _extends3;
|
|
6184
|
+
|
|
6185
|
+
return _extends({}, blocks, (_extends3 = {}, _extends3[nodeType] = {
|
|
6186
|
+
isVoid: true
|
|
6187
|
+
}, _extends3));
|
|
6188
|
+
}, {}), (_extends4 = {}, _extends4[BLOCKS.QUOTE] = {
|
|
6189
|
+
nodes: [{
|
|
6190
|
+
match: [/*#__PURE__*/CONTAINERS[BLOCKS.QUOTE].map(function (type) {
|
|
6191
|
+
return {
|
|
6192
|
+
type: type
|
|
6193
|
+
};
|
|
6194
|
+
})],
|
|
6195
|
+
min: 1
|
|
6196
|
+
}],
|
|
6197
|
+
normalize: function normalize(editor, error) {
|
|
6198
|
+
if (error.code === 'child_type_invalid') {
|
|
6199
|
+
return editor.unwrapBlockByKey(error.node.key, BLOCKS.QUOTE);
|
|
6200
|
+
}
|
|
6201
|
+
}
|
|
6202
|
+
}, _extends4)),
|
|
6203
|
+
inlines: (_inlines = {}, _inlines[INLINES.HYPERLINK] = {
|
|
6204
|
+
nodes: [{
|
|
6205
|
+
match: [{
|
|
6206
|
+
object: 'text'
|
|
6207
|
+
}]
|
|
6208
|
+
}]
|
|
6209
|
+
}, _inlines[INLINES.ENTRY_HYPERLINK] = {
|
|
6210
|
+
nodes: [{
|
|
6211
|
+
match: [{
|
|
6212
|
+
object: 'text'
|
|
6213
|
+
}]
|
|
6214
|
+
}]
|
|
6215
|
+
}, _inlines[INLINES.ASSET_HYPERLINK] = {
|
|
6216
|
+
nodes: [{
|
|
6217
|
+
match: [{
|
|
6218
|
+
object: 'text'
|
|
6219
|
+
}]
|
|
6220
|
+
}]
|
|
6221
|
+
}, _inlines[INLINES.EMBEDDED_ENTRY] = {
|
|
6222
|
+
isVoid: true
|
|
6223
|
+
}, _inlines)
|
|
6224
|
+
};
|
|
6225
|
+
|
|
6226
|
+
function getCharacterCount(editor) {
|
|
6227
|
+
var document = toContentfulDocument({
|
|
6228
|
+
document: editor.children,
|
|
6229
|
+
schema: schema
|
|
6230
|
+
});
|
|
6231
|
+
return documentToPlainTextString(document).length;
|
|
6232
|
+
}
|
|
6233
|
+
|
|
6234
|
+
var actionOrigin = {
|
|
6235
|
+
TOOLBAR: 'toolbar-icon',
|
|
6236
|
+
SHORTCUT: 'shortcut',
|
|
6237
|
+
VIEWPORT: 'viewport-interaction',
|
|
6238
|
+
COMMAND_PALETTE: 'command-palette'
|
|
6239
|
+
};
|
|
6240
|
+
function getPastingSource(data) {
|
|
6241
|
+
var textHtml = data.getData('text/html');
|
|
6242
|
+
var doc = new DOMParser().parseFromString(textHtml, 'text/html');
|
|
6243
|
+
|
|
6244
|
+
if (doc.querySelector('[id*="docs-internal-guid"]')) {
|
|
6245
|
+
return 'Google Docs';
|
|
6246
|
+
}
|
|
6247
|
+
|
|
6248
|
+
if (doc.querySelector('google-sheets-html-origin') || doc.querySelector('[data-sheets-value]')) {
|
|
6249
|
+
return 'Google Spreadsheets';
|
|
6250
|
+
}
|
|
6251
|
+
|
|
6252
|
+
if (doc.querySelector('meta[content*="Microsoft Excel"]')) {
|
|
6253
|
+
return 'Microsoft Excel';
|
|
6254
|
+
}
|
|
6255
|
+
|
|
6256
|
+
if (doc.querySelector('meta[content*="Microsoft Word"]')) {
|
|
6257
|
+
return 'Microsoft Word';
|
|
6258
|
+
} // 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
|
|
6259
|
+
|
|
6260
|
+
|
|
6261
|
+
if (doc.querySelector('[style*="Arial_MSFontService"]') && (doc.querySelector('.TextRun') || doc.querySelector('.OutlineElement'))) {
|
|
6262
|
+
return 'Microsoft Word Online';
|
|
6263
|
+
}
|
|
6264
|
+
|
|
6265
|
+
if (doc.querySelector('meta[content="Cocoa HTML Writer"]')) {
|
|
6266
|
+
return 'Apple Notes';
|
|
6267
|
+
}
|
|
6268
|
+
|
|
6269
|
+
if (doc.querySelector('[style*="Slack-Lato, Slack-Fractions"]')) {
|
|
6270
|
+
return 'Slack';
|
|
6271
|
+
}
|
|
6272
|
+
|
|
6273
|
+
return 'Unknown';
|
|
6274
|
+
}
|
|
6275
|
+
var createTrackingPlugin = function createTrackingPlugin(onAction) {
|
|
6276
|
+
var trackingActions = {
|
|
6277
|
+
onViewportAction: function onViewportAction(actionName, data) {
|
|
6278
|
+
if (data === void 0) {
|
|
6279
|
+
data = {};
|
|
6280
|
+
}
|
|
6281
|
+
|
|
6282
|
+
return onAction(actionName, _extends({
|
|
6283
|
+
origin: actionOrigin.VIEWPORT
|
|
6284
|
+
}, data));
|
|
6285
|
+
},
|
|
6286
|
+
onShortcutAction: function onShortcutAction(actionName, data) {
|
|
6287
|
+
if (data === void 0) {
|
|
6288
|
+
data = {};
|
|
6289
|
+
}
|
|
6290
|
+
|
|
6291
|
+
return onAction(actionName, _extends({
|
|
6292
|
+
origin: actionOrigin.SHORTCUT
|
|
6293
|
+
}, data));
|
|
6294
|
+
},
|
|
6295
|
+
onToolbarAction: function onToolbarAction(actionName, data) {
|
|
6296
|
+
if (data === void 0) {
|
|
6297
|
+
data = {};
|
|
6298
|
+
}
|
|
6299
|
+
|
|
6300
|
+
return onAction(actionName, _extends({
|
|
6301
|
+
origin: actionOrigin.TOOLBAR
|
|
6302
|
+
}, data));
|
|
6303
|
+
},
|
|
6304
|
+
onCommandPaletteAction: function onCommandPaletteAction(actionName, data) {
|
|
6305
|
+
if (data === void 0) {
|
|
6306
|
+
data = {};
|
|
6307
|
+
}
|
|
6308
|
+
|
|
6309
|
+
return onAction(actionName, _extends({
|
|
6310
|
+
origin: actionOrigin.COMMAND_PALETTE
|
|
6311
|
+
}, data));
|
|
6312
|
+
}
|
|
6313
|
+
};
|
|
6314
|
+
return {
|
|
6315
|
+
key: 'TrackingPlugin',
|
|
6316
|
+
withOverrides: function withOverrides(editor) {
|
|
6317
|
+
var insertData = editor.insertData;
|
|
6318
|
+
editor.tracking = trackingActions;
|
|
6319
|
+
|
|
6320
|
+
editor.insertData = function (data) {
|
|
6321
|
+
var isCopyAndPaste = data.types.length !== 0;
|
|
6322
|
+
|
|
6323
|
+
if (isCopyAndPaste) {
|
|
6324
|
+
var _window$getSelection;
|
|
6325
|
+
|
|
6326
|
+
var characterCountSelection = (_window$getSelection = window.getSelection()) == null ? void 0 : _window$getSelection.toString().length;
|
|
6327
|
+
var characterCountBefore = getCharacterCount(editor);
|
|
6328
|
+
setTimeout(function () {
|
|
6329
|
+
var characterCountAfter = getCharacterCount(editor);
|
|
6330
|
+
trackingActions.onShortcutAction('paste', {
|
|
6331
|
+
characterCountAfter: characterCountAfter,
|
|
6332
|
+
characterCountBefore: characterCountBefore,
|
|
6333
|
+
characterCountSelection: characterCountSelection,
|
|
6334
|
+
source: getPastingSource(data)
|
|
6335
|
+
});
|
|
6336
|
+
});
|
|
6337
|
+
}
|
|
6338
|
+
|
|
6339
|
+
insertData(data);
|
|
6340
|
+
};
|
|
6341
|
+
|
|
6342
|
+
return editor;
|
|
6343
|
+
}
|
|
6344
|
+
};
|
|
6345
|
+
};
|
|
6346
|
+
|
|
6123
6347
|
function hasTables(nodes) {
|
|
6124
6348
|
return nodes.some(function (_ref) {
|
|
6125
6349
|
var type = _ref.type;
|
|
@@ -6161,6 +6385,7 @@ function addTableTrackingEvents(editor) {
|
|
|
6161
6385
|
if (hasTables(markupAfter)) {
|
|
6162
6386
|
editor.tracking.onViewportAction('paste', {
|
|
6163
6387
|
tablePasted: true,
|
|
6388
|
+
source: getPastingSource(data),
|
|
6164
6389
|
hasHeadersOutsideFirstRow: hasHeadersOutsideFirstRow(markupAfter)
|
|
6165
6390
|
});
|
|
6166
6391
|
}
|
|
@@ -6375,11 +6600,11 @@ function createTextPlugin() {
|
|
|
6375
6600
|
deleteBackward = editor.deleteBackward;
|
|
6376
6601
|
|
|
6377
6602
|
editor.deleteBackward = function (unit) {
|
|
6378
|
-
|
|
6603
|
+
deleteEmptyParagraph(unit, editor, deleteBackward);
|
|
6379
6604
|
};
|
|
6380
6605
|
|
|
6381
6606
|
editor.deleteForward = function (unit) {
|
|
6382
|
-
|
|
6607
|
+
deleteEmptyParagraph(unit, editor, deleteForward);
|
|
6383
6608
|
};
|
|
6384
6609
|
|
|
6385
6610
|
return editor;
|
|
@@ -6387,7 +6612,7 @@ function createTextPlugin() {
|
|
|
6387
6612
|
};
|
|
6388
6613
|
}
|
|
6389
6614
|
|
|
6390
|
-
function
|
|
6615
|
+
function deleteEmptyParagraph(unit, editor, deleteFunction) {
|
|
6391
6616
|
var entry = getAbove(editor, {
|
|
6392
6617
|
match: {
|
|
6393
6618
|
type: TEXT_CONTAINERS
|
|
@@ -6402,10 +6627,29 @@ function deleteFirstEmptyParagraph(unit, editor, deleteFunction) {
|
|
|
6402
6627
|
var isRootLevel = path.length === 1;
|
|
6403
6628
|
var hasSiblings = editor.children.length > 1; // prevent editor from losing focus
|
|
6404
6629
|
|
|
6405
|
-
if (isTextEmpty && isRootLevel &&
|
|
6630
|
+
if (isTextEmpty && isRootLevel && hasSiblings) {
|
|
6406
6631
|
Transforms.removeNodes(editor, {
|
|
6407
6632
|
at: path
|
|
6408
6633
|
});
|
|
6634
|
+
var prevNode = Editor.before(editor, editor.selection, {
|
|
6635
|
+
unit: unit
|
|
6636
|
+
});
|
|
6637
|
+
|
|
6638
|
+
if (prevNode) {
|
|
6639
|
+
var _Editor$nodes = Editor.nodes(editor, {
|
|
6640
|
+
match: function match(node) {
|
|
6641
|
+
return queryNode([node, prevNode.path], {
|
|
6642
|
+
allow: [BLOCKS.EMBEDDED_ASSET, BLOCKS.EMBEDDED_ENTRY, BLOCKS.HR]
|
|
6643
|
+
});
|
|
6644
|
+
},
|
|
6645
|
+
at: prevNode
|
|
6646
|
+
}),
|
|
6647
|
+
prevCell = _Editor$nodes[0];
|
|
6648
|
+
|
|
6649
|
+
if (prevCell) {
|
|
6650
|
+
Transforms.select(editor, prevNode);
|
|
6651
|
+
}
|
|
6652
|
+
}
|
|
6409
6653
|
} else {
|
|
6410
6654
|
deleteFunction(unit);
|
|
6411
6655
|
}
|
|
@@ -6414,237 +6658,6 @@ function deleteFirstEmptyParagraph(unit, editor, deleteFunction) {
|
|
|
6414
6658
|
}
|
|
6415
6659
|
}
|
|
6416
6660
|
|
|
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
6661
|
var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
|
|
6649
6662
|
return createTrailingBlockPlugin({
|
|
6650
6663
|
options: {
|