@contentful/field-editor-rich-text 2.0.0-next.12 → 2.0.0-next.15

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.
Files changed (58) hide show
  1. package/dist/ContentfulEditorProvider.d.ts +6 -5
  2. package/dist/RichTextEditor.d.ts +1 -1
  3. package/dist/field-editor-rich-text.cjs.development.js +551 -370
  4. package/dist/field-editor-rich-text.cjs.development.js.map +1 -1
  5. package/dist/field-editor-rich-text.cjs.production.min.js +1 -1
  6. package/dist/field-editor-rich-text.cjs.production.min.js.map +1 -1
  7. package/dist/field-editor-rich-text.esm.js +554 -373
  8. package/dist/field-editor-rich-text.esm.js.map +1 -1
  9. package/dist/helpers/editor.d.ts +16 -18
  10. package/dist/helpers/extractNodes.d.ts +2 -3
  11. package/dist/helpers/transformers.d.ts +6 -6
  12. package/dist/plugins/EmbeddedEntityBlock/ToolbarIcon.d.ts +1 -2
  13. package/dist/plugins/EmbeddedEntityBlock/Util.d.ts +2 -1
  14. package/dist/plugins/EmbeddedEntityBlock/index.d.ts +2 -3
  15. package/dist/plugins/EmbeddedEntityInline/index.d.ts +1 -2
  16. package/dist/plugins/Hr/index.d.ts +2 -3
  17. package/dist/plugins/Hyperlink/HyperlinkModal.d.ts +3 -4
  18. package/dist/plugins/Hyperlink/index.d.ts +1 -2
  19. package/dist/plugins/Hyperlink/utils.d.ts +2 -2
  20. package/dist/plugins/List/insertListBreak.d.ts +2 -2
  21. package/dist/plugins/List/insertListFragment.d.ts +3 -2
  22. package/dist/plugins/List/transforms/insertListItem.d.ts +2 -2
  23. package/dist/plugins/List/utils.d.ts +6 -7
  24. package/dist/plugins/List/withList.d.ts +2 -1
  25. package/dist/plugins/Marks/Bold.d.ts +7 -5
  26. package/dist/plugins/Marks/Code.d.ts +7 -5
  27. package/dist/plugins/Marks/Italic.d.ts +7 -5
  28. package/dist/plugins/Marks/Underline.d.ts +7 -5
  29. package/dist/plugins/Marks/components/MarkToolbarButton.d.ts +13 -0
  30. package/dist/plugins/Marks/helpers.d.ts +4 -0
  31. package/dist/plugins/Normalizer/types.d.ts +4 -3
  32. package/dist/plugins/Normalizer/utils.d.ts +2 -2
  33. package/dist/plugins/Normalizer/withNormalizer.d.ts +2 -2
  34. package/dist/plugins/PasteHTML/createPasteHTMLPlugin.d.ts +6 -0
  35. package/dist/plugins/Quote/toggleQuote.d.ts +5 -3
  36. package/dist/plugins/Table/actions/addColumn.d.ts +3 -3
  37. package/dist/plugins/Table/actions/addRow.d.ts +3 -3
  38. package/dist/plugins/Table/actions/setHeader.d.ts +2 -2
  39. package/dist/plugins/Table/addTableTrackingEvents.d.ts +2 -3
  40. package/dist/plugins/Table/createTablePlugin.d.ts +1 -2
  41. package/dist/plugins/Table/helpers.d.ts +7 -7
  42. package/dist/plugins/Tracking/createTrackingPlugin.d.ts +10 -0
  43. package/dist/plugins/Tracking/index.d.ts +1 -0
  44. package/dist/plugins/Tracking/utils.d.ts +2 -0
  45. package/dist/plugins/TrailingParagraph/index.d.ts +2 -1
  46. package/dist/plugins/Voids/transformVoid.d.ts +2 -2
  47. package/dist/plugins/index.d.ts +2 -2
  48. package/dist/plugins/links-tracking.d.ts +1 -2
  49. package/dist/test-utils/assertOutput.d.ts +2 -2
  50. package/dist/test-utils/createEditor.d.ts +5 -6
  51. package/dist/test-utils/jsx.d.ts +1 -1
  52. package/dist/test-utils/mockPlugin.d.ts +1 -1
  53. package/dist/test-utils/setEmptyDataAttribute.d.ts +2 -2
  54. package/dist/types.d.ts +6 -2
  55. package/dist/useOnValueChanged.d.ts +7 -0
  56. package/package.json +1 -1
  57. package/CHANGELOG.md +0 -410
  58. package/dist/TrackingProvider.d.ts +0 -11
@@ -6,7 +6,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
6
6
 
7
7
  var React = require('react');
8
8
  var React__default = _interopDefault(React);
9
- var contentfulSlatejsAdapter = require('@contentful/contentful-slatejs-adapter');
10
9
  var fieldEditorReference = require('@contentful/field-editor-reference');
11
10
  var fieldEditorShared = require('@contentful/field-editor-shared');
12
11
  var Contentful = require('@contentful/rich-text-types');
@@ -14,12 +13,12 @@ var plateCore = require('@udecode/plate-core');
14
13
  var emotion = require('emotion');
15
14
  var deepEquals = _interopDefault(require('fast-deep-equal'));
16
15
  var noop = _interopDefault(require('lodash/noop'));
17
- var constate = _interopDefault(require('constate'));
18
16
  var plateSerializerDocx = require('@udecode/plate-serializer-docx');
19
17
  var plateBreak = require('@udecode/plate-break');
20
18
  var isHotkey = _interopDefault(require('is-hotkey'));
21
19
  var slate = require('slate');
22
20
  var Slate = require('slate-react');
21
+ var constate = _interopDefault(require('constate'));
23
22
  var f36Components = require('@contentful/f36-components');
24
23
  var mimetype = _interopDefault(require('@contentful/mimetype'));
25
24
  var get = _interopDefault(require('lodash/get'));
@@ -34,7 +33,10 @@ var isPlainObject = _interopDefault(require('is-plain-obj'));
34
33
  var plateParagraph = require('@udecode/plate-paragraph');
35
34
  var plateSelect = require('@udecode/plate-select');
36
35
  var plateTable = require('@udecode/plate-table');
36
+ var contentfulSlateJSAdapter = require('@contentful/contentful-slatejs-adapter');
37
+ var richTextPlainTextRenderer = require('@contentful/rich-text-plain-text-renderer');
37
38
  var plateTrailingBlock = require('@udecode/plate-trailing-block');
39
+ var debounce = _interopDefault(require('lodash/debounce'));
38
40
  var PropTypes = _interopDefault(require('prop-types'));
39
41
 
40
42
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
@@ -244,126 +246,37 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
244
246
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
245
247
  }
246
248
 
247
- var _extends2, _extends4, _inlines;
248
- var inlines = /*#__PURE__*/Object.values(Contentful.INLINES).map(function (type) {
249
- return {
250
- type: type
251
- };
252
- });
253
- var schema = {
254
- document: {
255
- nodes: [{
256
- types: /*#__PURE__*/Contentful.TOP_LEVEL_BLOCKS.map(function (type) {
257
- return {
258
- type: type
259
- };
260
- })
261
- }]
262
- },
263
- blocks: /*#__PURE__*/_extends((_extends2 = {}, _extends2[Contentful.BLOCKS.PARAGRAPH] = {
264
- nodes: [{
265
- match: /*#__PURE__*/[].concat(inlines, [{
266
- object: 'text'
267
- }])
268
- }]
269
- }, _extends2[Contentful.BLOCKS.HEADING_1] = {
270
- nodes: [{
271
- match: /*#__PURE__*/[].concat(inlines, [{
272
- object: 'text'
273
- }])
274
- }]
275
- }, _extends2[Contentful.BLOCKS.HEADING_2] = {
276
- nodes: [{
277
- match: /*#__PURE__*/[].concat(inlines, [{
278
- object: 'text'
279
- }])
280
- }]
281
- }, _extends2[Contentful.BLOCKS.HEADING_3] = {
282
- nodes: [{
283
- match: /*#__PURE__*/[].concat(inlines, [{
284
- object: 'text'
285
- }])
286
- }]
287
- }, _extends2[Contentful.BLOCKS.HEADING_4] = {
288
- nodes: [{
289
- match: /*#__PURE__*/[].concat(inlines, [{
290
- object: 'text'
291
- }])
292
- }]
293
- }, _extends2[Contentful.BLOCKS.HEADING_5] = {
294
- nodes: [{
295
- match: /*#__PURE__*/[].concat(inlines, [{
296
- object: 'text'
297
- }])
298
- }]
299
- }, _extends2[Contentful.BLOCKS.HEADING_6] = {
300
- nodes: [{
301
- match: /*#__PURE__*/[].concat(inlines, [{
302
- object: 'text'
303
- }])
304
- }]
305
- }, _extends2), /*#__PURE__*/Contentful.VOID_BLOCKS.reduce(function (blocks, nodeType) {
306
- var _extends3;
307
-
308
- return _extends({}, blocks, (_extends3 = {}, _extends3[nodeType] = {
309
- isVoid: true
310
- }, _extends3));
311
- }, {}), (_extends4 = {}, _extends4[Contentful.BLOCKS.QUOTE] = {
312
- nodes: [{
313
- match: [/*#__PURE__*/Contentful.CONTAINERS[Contentful.BLOCKS.QUOTE].map(function (type) {
314
- return {
315
- type: type
316
- };
317
- })],
318
- min: 1
319
- }],
320
- normalize: function normalize(editor, error) {
321
- if (error.code === 'child_type_invalid') {
322
- return editor.unwrapBlockByKey(error.node.key, Contentful.BLOCKS.QUOTE);
323
- }
324
- }
325
- }, _extends4)),
326
- inlines: (_inlines = {}, _inlines[Contentful.INLINES.HYPERLINK] = {
327
- nodes: [{
328
- match: [{
329
- object: 'text'
330
- }]
331
- }]
332
- }, _inlines[Contentful.INLINES.ENTRY_HYPERLINK] = {
333
- nodes: [{
334
- match: [{
335
- object: 'text'
336
- }]
337
- }]
338
- }, _inlines[Contentful.INLINES.ASSET_HYPERLINK] = {
339
- nodes: [{
340
- match: [{
341
- object: 'text'
342
- }]
343
- }]
344
- }, _inlines[Contentful.INLINES.EMBEDDED_ENTRY] = {
345
- isVoid: true
346
- }, _inlines)
347
- };
348
-
349
249
  function getContentfulEditorId(sdk) {
350
250
  var entry = sdk.entry,
351
251
  field = sdk.field;
352
252
  var sys = entry.getSys();
353
253
  return "rich-text-editor-" + sys.id + "-" + field.id + "-" + field.locale;
354
254
  }
255
+ var editorContext = /*#__PURE__*/React.createContext('');
256
+ var ContentfulEditorIdProvider = editorContext.Provider;
257
+ function useContentfulEditorId() {
258
+ var id = React.useContext(editorContext);
355
259
 
356
- function useContentfulEditorHook(_ref) {
357
- var sdk = _ref.sdk;
358
- var editorId = getContentfulEditorId(sdk);
260
+ if (!id) {
261
+ throw new Error('could not find editor id. Please ensure the component is wrapped in <ContentfulEditorIdProvider> ');
262
+ }
263
+
264
+ return id;
265
+ } // This hook re-renders when the value changes
266
+ // Use case: Toolbar icons, for example
267
+
268
+ function useContentfulEditor() {
269
+ var editorId = useContentfulEditorId();
270
+ var editor = plateCore.usePlateEditorState(editorId);
271
+ return editor;
272
+ } // This doesn't re-render when the value changes
273
+
274
+ function useContentfulEditorRef() {
275
+ var editorId = useContentfulEditorId();
359
276
  var editor = plateCore.usePlateEditorRef(editorId);
360
277
  return editor;
361
278
  }
362
279
 
363
- var _constate = /*#__PURE__*/constate(useContentfulEditorHook),
364
- ContentfulEditorProvider = _constate[0],
365
- useContentfulEditor = _constate[1];
366
-
367
280
  var createSoftBreakPlugin = function createSoftBreakPlugin() {
368
281
  return plateBreak.createSoftBreakPlugin({
369
282
  then: function then(editor) {
@@ -543,6 +456,10 @@ function insertLink(editor, options) {
543
456
  } // TODO: move to hyperlink plugin
544
457
 
545
458
  function isLinkActive(editor) {
459
+ if (!editor) {
460
+ return false;
461
+ }
462
+
546
463
  var _Array$from2 = Array.from(slate.Editor.nodes(editor, {
547
464
  match: function match(node) {
548
465
  return !slate.Editor.isEditor(node) && slate.Element.isElement(node) && LINK_TYPES.includes(node.type);
@@ -702,12 +619,14 @@ var focus = function focus(editor) {
702
619
  }
703
620
  };
704
621
 
705
- function withLinkTracking(tracking, Component) {
622
+ function withLinkTracking(Component) {
706
623
  return function ComponentWithTracking(props) {
624
+ var editor = useContentfulEditorRef();
625
+ var onEntityFetchComplete = React__default.useCallback(function () {
626
+ return editor.tracking.onViewportAction('linkRendered');
627
+ }, [editor]);
707
628
  return /*#__PURE__*/React__default.createElement(Component, Object.assign({}, props, {
708
- onEntityFetchComplete: function onEntityFetchComplete() {
709
- tracking.onViewportAction('linkRendered');
710
- }
629
+ onEntityFetchComplete: onEntityFetchComplete
711
630
  }));
712
631
  };
713
632
  }
@@ -721,9 +640,9 @@ function useSdk(_ref) {
721
640
  return sdkMemo;
722
641
  }
723
642
 
724
- var _constate$1 = /*#__PURE__*/constate(useSdk),
725
- SdkProvider = _constate$1[0],
726
- useSdkContext = _constate$1[1];
643
+ var _constate = /*#__PURE__*/constate(useSdk),
644
+ SdkProvider = _constate[0],
645
+ useSdkContext = _constate[1];
727
646
 
728
647
  var styles = {
729
648
  scheduleIcon: /*#__PURE__*/emotion.css({
@@ -1973,12 +1892,11 @@ function _selectEntityAndInsert() {
1973
1892
  config = _extends({}, baseConfig, {
1974
1893
  withCreate: true
1975
1894
  });
1976
- _context.prev = 5;
1977
1895
  selection = editor.selection;
1978
- _context.next = 9;
1896
+ _context.next = 8;
1979
1897
  return selectEntity(config);
1980
1898
 
1981
- case 9:
1899
+ case 8:
1982
1900
  entity = _context.sent;
1983
1901
 
1984
1902
  if (entity) {
@@ -1986,6 +1904,9 @@ function _selectEntityAndInsert() {
1986
1904
  break;
1987
1905
  }
1988
1906
 
1907
+ logAction('cancelCreateEmbedDialog', {
1908
+ nodeType: nodeType
1909
+ });
1989
1910
  return _context.abrupt("return");
1990
1911
 
1991
1912
  case 12:
@@ -1994,31 +1915,13 @@ function _selectEntityAndInsert() {
1994
1915
  logAction('insert', {
1995
1916
  nodeType: nodeType
1996
1917
  });
1997
- _context.next = 24;
1998
- break;
1999
-
2000
- case 17:
2001
- _context.prev = 17;
2002
- _context.t0 = _context["catch"](5);
2003
1918
 
2004
- if (!_context.t0) {
2005
- _context.next = 23;
2006
- break;
2007
- }
2008
-
2009
- throw _context.t0;
2010
-
2011
- case 23:
2012
- logAction('cancelCreateEmbedDialog', {
2013
- nodeType: nodeType
2014
- });
2015
-
2016
- case 24:
1919
+ case 15:
2017
1920
  case "end":
2018
1921
  return _context.stop();
2019
1922
  }
2020
1923
  }
2021
- }, _callee, null, [[5, 17]]);
1924
+ }, _callee);
2022
1925
  }));
2023
1926
  return _selectEntityAndInsert.apply(this, arguments);
2024
1927
  }
@@ -2065,7 +1968,6 @@ var styles$4 = {
2065
1968
  function EmbeddedEntityBlockToolbarIcon(_ref) {
2066
1969
  var isButton = _ref.isButton,
2067
1970
  isDisabled = _ref.isDisabled,
2068
- logAction = _ref.logAction,
2069
1971
  nodeType = _ref.nodeType,
2070
1972
  onClose = _ref.onClose;
2071
1973
  var editor = useContentfulEditor();
@@ -2074,7 +1976,7 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
2074
1976
  var handleClick = function handleClick(event) {
2075
1977
  event.preventDefault();
2076
1978
  onClose();
2077
- selectEntityAndInsert(nodeType, sdk, editor, logAction || noop);
1979
+ selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
2078
1980
  };
2079
1981
 
2080
1982
  var type = getEntityTypeFromNodeType(nodeType);
@@ -2141,20 +2043,20 @@ function getWithEmbeddedEntityEvents(nodeType, sdk) {
2141
2043
  }
2142
2044
 
2143
2045
  if (hotkey && isHotkey(hotkey, event)) {
2144
- selectEntityAndInsert(nodeType, sdk, editor, noop);
2046
+ selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onShortcutAction);
2145
2047
  }
2146
2048
  };
2147
2049
  };
2148
2050
  }
2149
2051
 
2150
2052
  var createEmbeddedEntityPlugin = function createEmbeddedEntityPlugin(nodeType, hotkey) {
2151
- return function (sdk, tracking) {
2053
+ return function (sdk) {
2152
2054
  return {
2153
2055
  key: nodeType,
2154
2056
  type: nodeType,
2155
2057
  isElement: true,
2156
2058
  isVoid: true,
2157
- component: withLinkTracking(tracking, LinkedEntityBlock),
2059
+ component: withLinkTracking(LinkedEntityBlock),
2158
2060
  options: {
2159
2061
  hotkey: hotkey
2160
2062
  },
@@ -2372,44 +2274,53 @@ function EmbeddedEntityInline(props) {
2372
2274
  })), props.children);
2373
2275
  }
2374
2276
 
2375
- function selectEntityAndInsert$1(_x, _x2) {
2277
+ function selectEntityAndInsert$1(_x, _x2, _x3) {
2376
2278
  return _selectEntityAndInsert$1.apply(this, arguments);
2377
2279
  }
2378
2280
 
2379
2281
  function _selectEntityAndInsert$1() {
2380
- _selectEntityAndInsert$1 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(editor, sdk) {
2282
+ _selectEntityAndInsert$1 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(editor, sdk, logAction) {
2381
2283
  var config, selection, entry, inlineEntryNode;
2382
2284
  return runtime_1.wrap(function _callee2$(_context2) {
2383
2285
  while (1) {
2384
2286
  switch (_context2.prev = _context2.next) {
2385
2287
  case 0:
2288
+ logAction('openCreateEmbedDialog', {
2289
+ nodeType: Contentful.INLINES.EMBEDDED_ENTRY
2290
+ });
2386
2291
  config = _extends({}, newEntitySelectorConfigFromRichTextField(sdk.field, Contentful.INLINES.EMBEDDED_ENTRY), {
2387
2292
  withCreate: true
2388
2293
  });
2389
2294
  selection = editor.selection;
2390
- _context2.next = 4;
2295
+ _context2.next = 5;
2391
2296
  return sdk.dialogs.selectSingleEntry(config);
2392
2297
 
2393
- case 4:
2298
+ case 5:
2394
2299
  entry = _context2.sent;
2395
2300
  focus(editor); // Dialog steals focus from editor, return it.
2396
2301
 
2397
2302
  if (entry) {
2398
- _context2.next = 8;
2303
+ _context2.next = 10;
2399
2304
  break;
2400
2305
  }
2401
2306
 
2307
+ logAction('cancelCreateEmbedDialog', {
2308
+ nodeType: Contentful.INLINES.EMBEDDED_ENTRY
2309
+ });
2402
2310
  return _context2.abrupt("return");
2403
2311
 
2404
- case 8:
2312
+ case 10:
2405
2313
  inlineEntryNode = createInlineEntryNode(entry.sys.id); // Got to wait until focus is really back on the editor or setSelection() won't work.
2406
2314
 
2407
2315
  setTimeout(function () {
2408
2316
  slate.Transforms.setSelection(editor, selection);
2409
2317
  slate.Transforms.insertNodes(editor, inlineEntryNode);
2410
2318
  }, 0);
2319
+ logAction('insert', {
2320
+ nodeType: Contentful.INLINES.EMBEDDED_ENTRY
2321
+ });
2411
2322
 
2412
- case 10:
2323
+ case 13:
2413
2324
  case "end":
2414
2325
  return _context2.stop();
2415
2326
  }
@@ -2423,7 +2334,7 @@ function ToolbarEmbeddedEntityInlineButton(props) {
2423
2334
  var editor = useContentfulEditor();
2424
2335
  var sdk = useSdkContext();
2425
2336
 
2426
- function handleClick(_x3) {
2337
+ function handleClick(_x4) {
2427
2338
  return _handleClick.apply(this, arguments);
2428
2339
  }
2429
2340
 
@@ -2445,7 +2356,7 @@ function ToolbarEmbeddedEntityInlineButton(props) {
2445
2356
  case 3:
2446
2357
  props.onClose();
2447
2358
  _context.next = 6;
2448
- return selectEntityAndInsert$1(editor, sdk);
2359
+ return selectEntityAndInsert$1(editor, sdk, editor.tracking.onToolbarAction);
2449
2360
 
2450
2361
  case 6:
2451
2362
  case "end":
@@ -2478,7 +2389,7 @@ function ToolbarEmbeddedEntityInlineButton(props) {
2478
2389
  className: "rich-text__embedded-entry-list-icon " + styles$6.icon
2479
2390
  }), /*#__PURE__*/React.createElement("span", null, "Inline entry")));
2480
2391
  }
2481
- function createEmbeddedEntityInlinePlugin(sdk, tracking) {
2392
+ function createEmbeddedEntityInlinePlugin(sdk) {
2482
2393
  var htmlAttributeName = 'data-embedded-entity-inline-id';
2483
2394
  return {
2484
2395
  key: Contentful.INLINES.EMBEDDED_ENTRY,
@@ -2486,7 +2397,7 @@ function createEmbeddedEntityInlinePlugin(sdk, tracking) {
2486
2397
  isElement: true,
2487
2398
  isInline: true,
2488
2399
  isVoid: true,
2489
- component: withLinkTracking(tracking, EmbeddedEntityInline),
2400
+ component: withLinkTracking(EmbeddedEntityInline),
2490
2401
  options: {
2491
2402
  hotkey: 'mod+shift+2'
2492
2403
  },
@@ -2512,7 +2423,7 @@ function getWithEmbeddedEntryInlineEvents(sdk) {
2512
2423
  if (!editor) return;
2513
2424
 
2514
2425
  if (hotkey && isHotkey(hotkey, event)) {
2515
- selectEntityAndInsert$1(editor, sdk);
2426
+ selectEntityAndInsert$1(editor, sdk, editor.tracking.onShortcutAction);
2516
2427
  }
2517
2428
  };
2518
2429
  };
@@ -2615,6 +2526,10 @@ function ToolbarHeadingButton(props) {
2615
2526
  prevOnChange.apply(void 0, arguments);
2616
2527
  };
2617
2528
 
2529
+ var isActive = isBlockSelected(editor, type);
2530
+ editor.tracking.onToolbarAction(isActive ? 'remove' : 'insert', {
2531
+ nodeType: type
2532
+ });
2618
2533
  plateCore.toggleNodeType(editor, {
2619
2534
  activeType: type,
2620
2535
  inactiveType: type
@@ -2736,6 +2651,24 @@ function createHeading(Tag, block) {
2736
2651
 
2737
2652
  var HeadingComponents = (_HeadingComponents = {}, _HeadingComponents[Contentful.BLOCKS.HEADING_1] = /*#__PURE__*/React.memo( /*#__PURE__*/createHeading('h1', Contentful.BLOCKS.HEADING_1)), _HeadingComponents[Contentful.BLOCKS.HEADING_2] = /*#__PURE__*/React.memo( /*#__PURE__*/createHeading('h2', Contentful.BLOCKS.HEADING_2)), _HeadingComponents[Contentful.BLOCKS.HEADING_3] = /*#__PURE__*/React.memo( /*#__PURE__*/createHeading('h3', Contentful.BLOCKS.HEADING_3)), _HeadingComponents[Contentful.BLOCKS.HEADING_4] = /*#__PURE__*/React.memo( /*#__PURE__*/createHeading('h4', Contentful.BLOCKS.HEADING_4)), _HeadingComponents[Contentful.BLOCKS.HEADING_5] = /*#__PURE__*/React.memo( /*#__PURE__*/createHeading('h5', Contentful.BLOCKS.HEADING_5)), _HeadingComponents[Contentful.BLOCKS.HEADING_6] = /*#__PURE__*/React.memo( /*#__PURE__*/createHeading('h6', Contentful.BLOCKS.HEADING_6)), _HeadingComponents);
2738
2653
 
2654
+ var buildHeadingEventHandler = function buildHeadingEventHandler(type) {
2655
+ return function (editor, _ref) {
2656
+ var hotkey = _ref.options.hotkey;
2657
+ return function (event) {
2658
+ if (editor.selection && hotkey && isHotkey(hotkey, event)) {
2659
+ var isActive = isBlockSelected(editor, type);
2660
+ editor.tracking.onShortcutAction(isActive ? 'remove' : 'insert', {
2661
+ nodeType: type
2662
+ });
2663
+ plateCore.toggleNodeType(editor, {
2664
+ activeType: type,
2665
+ inactiveType: Contentful.BLOCKS.PARAGRAPH
2666
+ });
2667
+ }
2668
+ };
2669
+ };
2670
+ };
2671
+
2739
2672
  var createHeadingPlugin = function createHeadingPlugin() {
2740
2673
  var _transform;
2741
2674
 
@@ -2752,8 +2685,8 @@ var createHeadingPlugin = function createHeadingPlugin() {
2752
2685
  match: {
2753
2686
  type: Contentful.HEADINGS
2754
2687
  },
2755
- validChildren: function validChildren(_, _ref) {
2756
- var node = _ref[0];
2688
+ validChildren: function validChildren(_, _ref2) {
2689
+ var node = _ref2[0];
2757
2690
  return isInlineOrText(node);
2758
2691
  },
2759
2692
  transform: (_transform = {}, _transform[Contentful.BLOCKS.PARAGRAPH] = transformUnwrap, _transform["default"] = transformLift, _transform)
@@ -2770,8 +2703,8 @@ var createHeadingPlugin = function createHeadingPlugin() {
2770
2703
  start: true,
2771
2704
  // Exclude headings inside lists as it interferes with the list's
2772
2705
  // insertBreak implementation
2773
- filter: function filter(_ref2) {
2774
- var path = _ref2[1];
2706
+ filter: function filter(_ref3) {
2707
+ var path = _ref3[1];
2775
2708
  return !plateCore.getAbove(editor, {
2776
2709
  at: path,
2777
2710
  match: {
@@ -2795,7 +2728,7 @@ var createHeadingPlugin = function createHeadingPlugin() {
2795
2728
  hotkey: ["mod+alt+" + level]
2796
2729
  },
2797
2730
  handlers: {
2798
- onKeyDown: plateCore.onKeyDownToggleElement
2731
+ onKeyDown: buildHeadingEventHandler(nodeType)
2799
2732
  },
2800
2733
  deserializeHtml: {
2801
2734
  rules: [{
@@ -2867,10 +2800,6 @@ function withHrEvents(editor) {
2867
2800
  pathToSelectedHr = _getNodeEntryFromSele[1];
2868
2801
 
2869
2802
  if (pathToSelectedHr) {
2870
- if (shouldUnwrapBlockquote(editor, Contentful.BLOCKS.HR)) {
2871
- unwrapFromRoot(editor);
2872
- }
2873
-
2874
2803
  var isBackspace = event.key === 'Backspace';
2875
2804
  var isDelete = event.key === 'Delete';
2876
2805
 
@@ -2888,11 +2817,6 @@ function ToolbarHrButton(props) {
2888
2817
 
2889
2818
  function handleOnClick() {
2890
2819
  if (!(editor != null && editor.selection)) return;
2891
-
2892
- if (shouldUnwrapBlockquote(editor, Contentful.BLOCKS.HR)) {
2893
- unwrapFromRoot(editor);
2894
- }
2895
-
2896
2820
  var hr = {
2897
2821
  type: Contentful.BLOCKS.HR,
2898
2822
  data: {},
@@ -3325,13 +3249,15 @@ function HyperlinkModal(props) {
3325
3249
  testId: "confirm-cta"
3326
3250
  }, props.linkType ? 'Update' : 'Insert'))));
3327
3251
  }
3328
- function addOrEditLink(_x, _x2) {
3252
+ function addOrEditLink(_x, _x2, _x3) {
3329
3253
  return _addOrEditLink.apply(this, arguments);
3330
3254
  }
3331
3255
 
3332
3256
  function _addOrEditLink() {
3333
- _addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk) {
3334
- var linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path, selectionBeforeBlur, currentLinkText, data, text, url, type, target;
3257
+ _addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk, logAction) {
3258
+ var _target$sys$linkType;
3259
+
3260
+ var linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path, selectionBeforeBlur, currentLinkText, isEditing, data, text, url, type, target;
3335
3261
 
3336
3262
  return runtime_1.wrap(function _callee3$(_context3) {
3337
3263
  while (1) {
@@ -3356,9 +3282,11 @@ function _addOrEditLink() {
3356
3282
 
3357
3283
  selectionBeforeBlur = _extends({}, editor.selection);
3358
3284
  currentLinkText = linkText || slate.Editor.string(editor, editor.selection);
3359
- _context3.next = 8;
3285
+ isEditing = Boolean(node && path);
3286
+ logAction(isEditing ? 'openEditHyperlinkDialog' : 'openCreateHyperlinkDialog');
3287
+ _context3.next = 10;
3360
3288
  return fieldEditorShared.ModalDialogLauncher.openDialog({
3361
- title: linkType ? 'Edit hyperlink' : 'Insert hyperlink',
3289
+ title: isEditing ? 'Edit hyperlink' : 'Insert hyperlink',
3362
3290
  width: 'large',
3363
3291
  shouldCloseOnEscapePress: true,
3364
3292
  shouldCloseOnOverlayClick: true,
@@ -3375,17 +3303,18 @@ function _addOrEditLink() {
3375
3303
  });
3376
3304
  });
3377
3305
 
3378
- case 8:
3306
+ case 10:
3379
3307
  data = _context3.sent;
3380
3308
 
3381
3309
  if (data) {
3382
- _context3.next = 11;
3310
+ _context3.next = 14;
3383
3311
  break;
3384
3312
  }
3385
3313
 
3314
+ logAction(isEditing ? 'cancelEditHyperlinkDialog' : 'cancelCreateHyperlinkDialog');
3386
3315
  return _context3.abrupt("return");
3387
3316
 
3388
- case 11:
3317
+ case 14:
3389
3318
  text = data.linkText, url = data.linkTarget, type = data.linkType, target = data.linkEntity;
3390
3319
  slate.Transforms.select(editor, selectionBeforeBlur);
3391
3320
  slate.Editor.withoutNormalizing(editor, function () {
@@ -3397,9 +3326,13 @@ function _addOrEditLink() {
3397
3326
  path: path
3398
3327
  });
3399
3328
  });
3329
+ logAction(isEditing ? 'edit' : 'insert', {
3330
+ nodeType: type,
3331
+ linkType: (_target$sys$linkType = target == null ? void 0 : target.sys.linkType) != null ? _target$sys$linkType : 'uri'
3332
+ });
3400
3333
  focus(editor);
3401
3334
 
3402
- case 15:
3335
+ case 19:
3403
3336
  case "end":
3404
3337
  return _context3.stop();
3405
3338
  }
@@ -3463,7 +3396,7 @@ function UrlHyperlink(props) {
3463
3396
  event.preventDefault();
3464
3397
  event.stopPropagation();
3465
3398
  if (!editor) return;
3466
- addOrEditLink(editor, sdk);
3399
+ addOrEditLink(editor, sdk, editor.tracking.onViewportAction);
3467
3400
  }
3468
3401
 
3469
3402
  return /*#__PURE__*/React.createElement(f36Components.Tooltip, {
@@ -3499,7 +3432,7 @@ function EntityHyperlink(props) {
3499
3432
  event.preventDefault();
3500
3433
  event.stopPropagation();
3501
3434
  if (!editor) return;
3502
- addOrEditLink(editor, sdk);
3435
+ addOrEditLink(editor, sdk, editor.tracking.onViewportAction);
3503
3436
  }
3504
3437
 
3505
3438
  return /*#__PURE__*/React.createElement(f36Components.Tooltip, {
@@ -3546,8 +3479,9 @@ function ToolbarHyperlinkButton(props) {
3546
3479
  case 2:
3547
3480
  if (isActive) {
3548
3481
  unwrapLink(editor);
3482
+ editor.tracking.onToolbarAction('unlinkHyperlinks');
3549
3483
  } else {
3550
- addOrEditLink(editor, sdk);
3484
+ addOrEditLink(editor, sdk, editor.tracking.onToolbarAction);
3551
3485
  }
3552
3486
 
3553
3487
  case 3:
@@ -3596,8 +3530,9 @@ var buildHyperlinkEventHandler = function buildHyperlinkEventHandler(sdk) {
3596
3530
 
3597
3531
  if (isLinkActive(editor)) {
3598
3532
  unwrapLink(editor);
3533
+ editor.tracking.onShortcutAction('unlinkHyperlinks');
3599
3534
  } else {
3600
- addOrEditLink(editor, sdk);
3535
+ addOrEditLink(editor, sdk, editor.tracking.onShortcutAction);
3601
3536
  }
3602
3537
  };
3603
3538
  };
@@ -3623,7 +3558,7 @@ var getNodeOfType = function getNodeOfType(type) {
3623
3558
  };
3624
3559
  };
3625
3560
 
3626
- var createHyperlinkPlugin = function createHyperlinkPlugin(sdk, tracking) {
3561
+ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
3627
3562
  var common = {
3628
3563
  isElement: true,
3629
3564
  isInline: true
@@ -3654,7 +3589,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk, tracking) {
3654
3589
  _extends({}, common, {
3655
3590
  key: Contentful.INLINES.ENTRY_HYPERLINK,
3656
3591
  type: Contentful.INLINES.ENTRY_HYPERLINK,
3657
- component: withLinkTracking(tracking, EntityHyperlink),
3592
+ component: withLinkTracking(EntityHyperlink),
3658
3593
  deserializeHtml: {
3659
3594
  rules: [{
3660
3595
  validNodeName: ['A']
@@ -3668,7 +3603,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk, tracking) {
3668
3603
  _extends({}, common, {
3669
3604
  key: Contentful.INLINES.ASSET_HYPERLINK,
3670
3605
  type: Contentful.INLINES.ASSET_HYPERLINK,
3671
- component: withLinkTracking(tracking, EntityHyperlink),
3606
+ component: withLinkTracking(EntityHyperlink),
3672
3607
  deserializeHtml: {
3673
3608
  rules: [{
3674
3609
  validNodeName: ['A']
@@ -4142,6 +4077,7 @@ var createListPlugin = function createListPlugin() {
4142
4077
  }, _overrideByKey[plateList.ELEMENT_LI] = {
4143
4078
  type: Contentful.BLOCKS.LIST_ITEM,
4144
4079
  component: ListItem,
4080
+ // @ts-expect-error
4145
4081
  normalizer: [{
4146
4082
  validNode: hasListAsDirectParent,
4147
4083
  transform: normalizeOrphanedListItem
@@ -4194,26 +4130,62 @@ function ToolbarListButton(props) {
4194
4130
  }, /*#__PURE__*/React.createElement(f36Icons.ListNumberedIcon, null)));
4195
4131
  }
4196
4132
 
4197
- function ToolbarBoldButton(props) {
4198
- var editor = useContentfulEditor();
4133
+ var createMarkToolbarButton = function createMarkToolbarButton(_ref) {
4134
+ var mark = _ref.mark,
4135
+ title = _ref.title,
4136
+ icon = _ref.icon;
4199
4137
 
4200
- function handleClick() {
4201
- if (!(editor != null && editor.selection)) return;
4202
- plateCore.toggleMark(editor, {
4203
- key: Contentful.MARKS.BOLD
4204
- });
4205
- focus(editor);
4206
- }
4138
+ var Mark = function Mark(_ref2) {
4139
+ var isDisabled = _ref2.isDisabled;
4140
+ var editor = useContentfulEditor();
4141
+ var handleClick = React.useCallback(function () {
4142
+ if (!(editor != null && editor.selection)) return;
4143
+ var isActive = plateCore.isMarkActive(editor, mark);
4144
+ editor.tracking.onToolbarAction(isActive ? 'unmark' : 'mark', {
4145
+ markType: mark
4146
+ });
4147
+ plateCore.toggleMark(editor, {
4148
+ key: mark
4149
+ });
4150
+ focus(editor);
4151
+ }, [editor]);
4152
+ if (!editor) return null;
4153
+ return /*#__PURE__*/React.createElement(ToolbarButton, {
4154
+ title: title,
4155
+ testId: mark + "-toolbar-button",
4156
+ onClick: handleClick,
4157
+ isActive: plateCore.isMarkActive(editor, mark),
4158
+ isDisabled: isDisabled
4159
+ }, icon);
4160
+ };
4207
4161
 
4208
- if (!editor) return null;
4209
- return /*#__PURE__*/React.createElement(ToolbarButton, {
4210
- title: "Bold",
4211
- testId: "bold-toolbar-button",
4212
- onClick: handleClick,
4213
- isActive: plateCore.isMarkActive(editor, Contentful.MARKS.BOLD),
4214
- isDisabled: props.isDisabled
4215
- }, /*#__PURE__*/React.createElement(f36Icons.FormatBoldIcon, null));
4216
- }
4162
+ Mark.displayName = mark;
4163
+ return Mark;
4164
+ };
4165
+
4166
+ var buildMarkEventHandler = function buildMarkEventHandler(type) {
4167
+ return function (editor, _ref) {
4168
+ var hotkey = _ref.options.hotkey;
4169
+ return function (event) {
4170
+ if (editor.selection && hotkey && isHotkey(hotkey, event)) {
4171
+ event.preventDefault();
4172
+ var isActive = plateCore.isMarkActive(editor, type);
4173
+ editor.tracking.onShortcutAction(isActive ? 'unmark' : 'mark', {
4174
+ markType: type
4175
+ });
4176
+ plateCore.toggleMark(editor, {
4177
+ key: type
4178
+ });
4179
+ }
4180
+ };
4181
+ };
4182
+ };
4183
+
4184
+ var ToolbarBoldButton = /*#__PURE__*/createMarkToolbarButton({
4185
+ title: 'Bold',
4186
+ mark: Contentful.MARKS.BOLD,
4187
+ icon: /*#__PURE__*/React.createElement(f36Icons.FormatBoldIcon, null)
4188
+ });
4217
4189
  var styles$e = {
4218
4190
  bold: /*#__PURE__*/emotion.css({
4219
4191
  fontWeight: 600
@@ -4236,6 +4208,9 @@ var createBoldPlugin = function createBoldPlugin() {
4236
4208
  options: {
4237
4209
  hotkey: ['mod+b']
4238
4210
  },
4211
+ handlers: {
4212
+ onKeyDown: buildMarkEventHandler(Contentful.MARKS.BOLD)
4213
+ },
4239
4214
  deserializeHtml: {
4240
4215
  rules: [{
4241
4216
  validNodeName: ['STRONG', 'B']
@@ -4253,26 +4228,11 @@ var createBoldPlugin = function createBoldPlugin() {
4253
4228
  });
4254
4229
  };
4255
4230
 
4256
- function ToolbarCodeButton(props) {
4257
- var editor = useContentfulEditor();
4258
-
4259
- function handleClick() {
4260
- if (!(editor != null && editor.selection)) return;
4261
- plateCore.toggleMark(editor, {
4262
- key: Contentful.MARKS.CODE
4263
- });
4264
- focus(editor);
4265
- }
4266
-
4267
- if (!editor) return null;
4268
- return /*#__PURE__*/React.createElement(ToolbarButton, {
4269
- title: "Code",
4270
- testId: "code-toolbar-button",
4271
- onClick: handleClick,
4272
- isActive: plateCore.isMarkActive(editor, Contentful.MARKS.CODE),
4273
- isDisabled: props.isDisabled
4274
- }, /*#__PURE__*/React.createElement(f36Icons.CodeIcon, null));
4275
- }
4231
+ var ToolbarCodeButton = /*#__PURE__*/createMarkToolbarButton({
4232
+ title: 'Code',
4233
+ mark: Contentful.MARKS.CODE,
4234
+ icon: /*#__PURE__*/React.createElement(f36Icons.CodeIcon, null)
4235
+ });
4276
4236
  var styles$f = {
4277
4237
  code: /*#__PURE__*/emotion.css({
4278
4238
  fontFamily: 'monospace',
@@ -4291,6 +4251,9 @@ var createCodePlugin = function createCodePlugin() {
4291
4251
  options: {
4292
4252
  hotkey: ['mod+/']
4293
4253
  },
4254
+ handlers: {
4255
+ onKeyDown: buildMarkEventHandler(Contentful.MARKS.CODE)
4256
+ },
4294
4257
  deserializeHtml: {
4295
4258
  rules: [{
4296
4259
  validNodeName: ['CODE', 'PRE']
@@ -4303,26 +4266,11 @@ var createCodePlugin = function createCodePlugin() {
4303
4266
  });
4304
4267
  };
4305
4268
 
4306
- function ToolbarItalicButton(props) {
4307
- var editor = useContentfulEditor();
4308
-
4309
- function handleClick() {
4310
- if (!(editor != null && editor.selection)) return;
4311
- plateCore.toggleMark(editor, {
4312
- key: Contentful.MARKS.ITALIC
4313
- });
4314
- focus(editor);
4315
- }
4316
-
4317
- if (!editor) return null;
4318
- return /*#__PURE__*/React.createElement(ToolbarButton, {
4319
- title: "Italic",
4320
- testId: "italic-toolbar-button",
4321
- onClick: handleClick,
4322
- isActive: plateCore.isMarkActive(editor, Contentful.MARKS.ITALIC),
4323
- isDisabled: props.isDisabled
4324
- }, /*#__PURE__*/React.createElement(f36Icons.FormatItalicIcon, null));
4325
- }
4269
+ var ToolbarItalicButton = /*#__PURE__*/createMarkToolbarButton({
4270
+ title: 'Italic',
4271
+ mark: Contentful.MARKS.ITALIC,
4272
+ icon: /*#__PURE__*/React.createElement(f36Icons.FormatItalicIcon, null)
4273
+ });
4326
4274
  var styles$g = {
4327
4275
  italic: /*#__PURE__*/emotion.css({
4328
4276
  fontStyle: 'italic'
@@ -4340,6 +4288,9 @@ var createItalicPlugin = function createItalicPlugin() {
4340
4288
  options: {
4341
4289
  hotkey: ['mod+i']
4342
4290
  },
4291
+ handlers: {
4292
+ onKeyDown: buildMarkEventHandler(Contentful.MARKS.ITALIC)
4293
+ },
4343
4294
  deserializeHtml: {
4344
4295
  rules: [{
4345
4296
  validNodeName: ['I', 'EM']
@@ -4357,26 +4308,11 @@ var createItalicPlugin = function createItalicPlugin() {
4357
4308
  });
4358
4309
  };
4359
4310
 
4360
- function ToolbarUnderlineButton(props) {
4361
- var editor = useContentfulEditor();
4362
-
4363
- function handleClick() {
4364
- if (!(editor != null && editor.selection)) return;
4365
- plateCore.toggleMark(editor, {
4366
- key: Contentful.MARKS.UNDERLINE
4367
- });
4368
- focus(editor);
4369
- }
4370
-
4371
- if (!editor) return null;
4372
- return /*#__PURE__*/React.createElement(ToolbarButton, {
4373
- title: "Underline",
4374
- testId: "underline-toolbar-button",
4375
- onClick: handleClick,
4376
- isActive: plateCore.isMarkActive(editor, Contentful.MARKS.UNDERLINE),
4377
- isDisabled: props.isDisabled
4378
- }, /*#__PURE__*/React.createElement(f36Icons.FormatUnderlinedIcon, null));
4379
- }
4311
+ var ToolbarUnderlineButton = /*#__PURE__*/createMarkToolbarButton({
4312
+ title: 'Underline',
4313
+ mark: Contentful.MARKS.UNDERLINE,
4314
+ icon: /*#__PURE__*/React.createElement(f36Icons.FormatUnderlinedIcon, null)
4315
+ });
4380
4316
  function Underline(props) {
4381
4317
  return /*#__PURE__*/React.createElement("u", Object.assign({}, props.attributes), props.children);
4382
4318
  }
@@ -4387,6 +4323,9 @@ var createUnderlinePlugin = function createUnderlinePlugin() {
4387
4323
  options: {
4388
4324
  hotkey: ['mod+u']
4389
4325
  },
4326
+ handlers: {
4327
+ onKeyDown: buildMarkEventHandler(Contentful.MARKS.UNDERLINE)
4328
+ },
4390
4329
  deserializeHtml: {
4391
4330
  rules: [{
4392
4331
  validNodeName: ['U']
@@ -4609,6 +4548,7 @@ var withNormalizer = function withNormalizer(editor) {
4609
4548
  var createNormalizerPlugin = function createNormalizerPlugin() {
4610
4549
  return {
4611
4550
  key: 'NormalizerPlugin',
4551
+ // @ts-expect-error
4612
4552
  withOverrides: withNormalizer
4613
4553
  };
4614
4554
  };
@@ -4752,11 +4692,54 @@ var sanitizeHTML = function sanitizeHTML(html) {
4752
4692
  return doc.body.innerHTML.replace(/>\s+</g, '><');
4753
4693
  };
4754
4694
 
4695
+ /**
4696
+ * Get x-slate-fragment attribute from data-slate-fragment
4697
+ */
4698
+
4699
+ var catchSlateFragment = /data-slate-fragment="(.+?)"/m;
4700
+ var getSlateFragmentAttribute = function getSlateFragmentAttribute(dataTransfer) {
4701
+ var htmlData = dataTransfer.getData('text/html');
4702
+
4703
+ var _ref = htmlData.match(catchSlateFragment) || [],
4704
+ fragment = _ref[1];
4705
+
4706
+ return fragment;
4707
+ };
4708
+ /**
4709
+ * Get the x-slate-fragment attribute that exist in text/html data
4710
+ * and append it to the DataTransfer object
4711
+ */
4712
+
4713
+ var ensureXSlateFragment = function ensureXSlateFragment(dataTransfer) {
4714
+ if (!dataTransfer.getData('application/x-slate-fragment')) {
4715
+ var fragment = getSlateFragmentAttribute(dataTransfer);
4716
+
4717
+ if (fragment) {
4718
+ var clipboardData = new DataTransfer();
4719
+ dataTransfer.types.forEach(function (type) {
4720
+ clipboardData.setData(type, dataTransfer.getData(type));
4721
+ });
4722
+ clipboardData.setData('application/x-slate-fragment', fragment);
4723
+ return clipboardData;
4724
+ }
4725
+ }
4726
+
4727
+ return dataTransfer;
4728
+ };
4755
4729
  var createPasteHTMLPlugin = function createPasteHTMLPlugin() {
4756
4730
  var _pluginsByKey;
4757
4731
 
4758
4732
  return {
4759
4733
  key: 'PasteHTMLPlugin',
4734
+ withOverrides: function withOverrides(editor) {
4735
+ var insertData = editor.insertData;
4736
+
4737
+ editor.insertData = function (data) {
4738
+ return insertData(ensureXSlateFragment(data));
4739
+ };
4740
+
4741
+ return editor;
4742
+ },
4760
4743
  inject: {
4761
4744
  pluginsByKey: (_pluginsByKey = {}, _pluginsByKey[plateCore.KEY_DESERIALIZE_HTML] = {
4762
4745
  editor: {
@@ -4786,9 +4769,12 @@ function Quote(props) {
4786
4769
  }), props.children);
4787
4770
  }
4788
4771
 
4789
- function toggleQuote(editor) {
4772
+ function toggleQuote(editor, logAction) {
4790
4773
  if (!editor.selection) return;
4791
4774
  var isActive = isBlockSelected(editor, Contentful.BLOCKS.QUOTE);
4775
+ logAction(isActive ? 'remove' : 'insert', {
4776
+ nodeType: Contentful.BLOCKS.QUOTE
4777
+ });
4792
4778
  slate.Editor.withoutNormalizing(editor, function () {
4793
4779
  if (!editor.selection) return;
4794
4780
  slate.Transforms.unwrapNodes(editor, {
@@ -4820,7 +4806,7 @@ var onKeyDownToggleQuote = function onKeyDownToggleQuote(editor, plugin) {
4820
4806
 
4821
4807
  if (hotkey && isHotkey(hotkey, event)) {
4822
4808
  event.preventDefault();
4823
- toggleQuote(editor);
4809
+ toggleQuote(editor, editor.tracking.onShortcutAction);
4824
4810
  }
4825
4811
  };
4826
4812
  };
@@ -4847,7 +4833,54 @@ function createQuotePlugin() {
4847
4833
  normalizer: [{
4848
4834
  validChildren: Contentful.CONTAINERS[Contentful.BLOCKS.QUOTE],
4849
4835
  transform: (_transform = {}, _transform[Contentful.BLOCKS.QUOTE] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_1] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_2] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_3] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_4] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_5] = transformUnwrap, _transform[Contentful.BLOCKS.HEADING_6] = transformUnwrap, _transform["default"] = transformLift, _transform)
4850
- }]
4836
+ }],
4837
+ withOverrides: function withOverrides(editor) {
4838
+ var insertFragment = editor.insertFragment;
4839
+
4840
+ editor.insertFragment = function (fragment) {
4841
+ var startingNode = fragment.length && fragment[0];
4842
+ var startsWithBlockquote = slate.Element.isElement(startingNode) && startingNode.type === Contentful.BLOCKS.QUOTE;
4843
+ var containerEntry = plateCore.getAbove(editor, {
4844
+ match: {
4845
+ type: Contentful.TEXT_CONTAINERS
4846
+ }
4847
+ });
4848
+ var containerIsNotEmpty = containerEntry && slate.Node.string(containerEntry[0]) !== '';
4849
+
4850
+ if (startsWithBlockquote && containerIsNotEmpty) {
4851
+ var selection = editor.selection;
4852
+
4853
+ var isContentSelected = function isContentSelected(selection) {
4854
+ return !!selection && slate.Point.compare(selection.anchor, selection.focus) !== 0;
4855
+ }; // if something is selected (highlighted) we replace the selection
4856
+
4857
+
4858
+ if (isContentSelected(selection)) {
4859
+ slate.Transforms["delete"](editor, {
4860
+ at: selection
4861
+ });
4862
+ } // get the cursor entry again, it may be different after deletion
4863
+
4864
+
4865
+ var _containerEntry = plateCore.getAbove(editor, {
4866
+ match: {
4867
+ type: Contentful.TEXT_CONTAINERS
4868
+ }
4869
+ });
4870
+
4871
+ var _containerIsNotEmpty = _containerEntry && slate.Node.string(_containerEntry[0]) !== '';
4872
+
4873
+ if (_containerIsNotEmpty) {
4874
+ slate.Transforms.insertNodes(editor, fragment);
4875
+ return;
4876
+ }
4877
+ }
4878
+
4879
+ insertFragment(fragment);
4880
+ };
4881
+
4882
+ return editor;
4883
+ }
4851
4884
  };
4852
4885
  }
4853
4886
 
@@ -4856,7 +4889,7 @@ function ToolbarQuoteButton(props) {
4856
4889
 
4857
4890
  function handleOnClick() {
4858
4891
  if (!editor) return;
4859
- toggleQuote(editor);
4892
+ toggleQuote(editor, editor.tracking.onToolbarAction);
4860
4893
  focus(editor);
4861
4894
  }
4862
4895
 
@@ -4905,8 +4938,7 @@ function hasHeadersOutsideFirstRow(nodes) {
4905
4938
  });
4906
4939
  }
4907
4940
 
4908
- function addTableTrackingEvents(editor, _ref6) {
4909
- var onViewportAction = _ref6.onViewportAction;
4941
+ function addTableTrackingEvents(editor) {
4910
4942
  var insertData = editor.insertData;
4911
4943
 
4912
4944
  editor.insertData = function (data) {
@@ -4920,7 +4952,7 @@ function addTableTrackingEvents(editor, _ref6) {
4920
4952
  if (hasTables(markupBefore)) return;
4921
4953
 
4922
4954
  if (hasTables(markupAfter)) {
4923
- onViewportAction('paste', {
4955
+ editor.tracking.onViewportAction('paste', {
4924
4956
  tablePasted: true,
4925
4957
  hasHeadersOutsideFirstRow: hasHeadersOutsideFirstRow(markupAfter)
4926
4958
  });
@@ -4932,29 +4964,6 @@ function addTableTrackingEvents(editor, _ref6) {
4932
4964
  };
4933
4965
  }
4934
4966
 
4935
- function useTracking(_ref) {
4936
- var onAction = _ref.onAction;
4937
- var trackingMemo = React.useMemo(function () {
4938
- return {
4939
- onViewportAction: function onViewportAction(actionName, data) {
4940
- if (data === void 0) {
4941
- data = {};
4942
- }
4943
-
4944
- return onAction(actionName, _extends({
4945
- origin: 'viewport-interaction'
4946
- }, data));
4947
- }
4948
- };
4949
- }, [] // eslint-disable-line
4950
- );
4951
- return trackingMemo;
4952
- }
4953
-
4954
- var _constate$2 = /*#__PURE__*/constate(useTracking),
4955
- TrackingProvider = _constate$2[0],
4956
- useTrackingContext = _constate$2[1];
4957
-
4958
4967
  var addRow = function addRow(editor, getNextRowPath) {
4959
4968
  if (plateCore.someNode(editor, {
4960
4969
  match: {
@@ -5200,9 +5209,6 @@ var TableActions = function TableActions() {
5200
5209
  var editor = useContentfulEditor();
5201
5210
  var isDisabled = Slate.useReadOnly();
5202
5211
 
5203
- var _useTrackingContext = useTrackingContext(),
5204
- onViewportAction = _useTrackingContext.onViewportAction;
5205
-
5206
5212
  var _React$useState = React__default.useState(false),
5207
5213
  isOpen = _React$useState[0],
5208
5214
  setOpen = _React$useState[1];
@@ -5252,11 +5258,11 @@ var TableActions = function TableActions() {
5252
5258
  }); // Tracking
5253
5259
 
5254
5260
  var actionName = type + "Table" + (element === 'Table' ? '' : element);
5255
- onViewportAction(actionName, {
5261
+ editor.tracking.onViewportAction(actionName, {
5256
5262
  tableSize: tableSize
5257
5263
  });
5258
5264
  };
5259
- }, [editor, isHeaderEnabled, close, onViewportAction]);
5265
+ }, [editor, isHeaderEnabled, close]);
5260
5266
 
5261
5267
  if (isDisabled) {
5262
5268
  return null;
@@ -5347,7 +5353,7 @@ var createTableOnKeyDown = function createTableOnKeyDown(editor, plugin) {
5347
5353
  };
5348
5354
  };
5349
5355
 
5350
- var createTablePlugin = function createTablePlugin(tracking) {
5356
+ var createTablePlugin = function createTablePlugin() {
5351
5357
  var _overrideByKey;
5352
5358
 
5353
5359
  return plateTable.createTablePlugin({
@@ -5356,7 +5362,7 @@ var createTablePlugin = function createTablePlugin(tracking) {
5356
5362
  onKeyDown: createTableOnKeyDown
5357
5363
  },
5358
5364
  withOverrides: function withOverrides(editor) {
5359
- addTableTrackingEvents(editor, tracking);
5365
+ addTableTrackingEvents(editor);
5360
5366
  var insertFragment = editor.insertFragment;
5361
5367
 
5362
5368
  editor.insertFragment = function (fragments) {
@@ -5456,10 +5462,6 @@ var createTablePlugin = function createTablePlugin(tracking) {
5456
5462
 
5457
5463
  function ToolbarTableButton(props) {
5458
5464
  var editor = useContentfulEditor();
5459
-
5460
- var _useTrackingContext = useTrackingContext(),
5461
- onViewportAction = _useTrackingContext.onViewportAction;
5462
-
5463
5465
  var isActive = editor && isTableActive(editor);
5464
5466
 
5465
5467
  function handleClick() {
@@ -5480,7 +5482,7 @@ function ToolbarTableButton(props) {
5480
5482
  return _context.abrupt("return");
5481
5483
 
5482
5484
  case 2:
5483
- onViewportAction('insertTable');
5485
+ editor.tracking.onToolbarAction('insertTable');
5484
5486
  insertTableAndFocusFirstCell(editor);
5485
5487
  focus(editor);
5486
5488
 
@@ -5585,35 +5587,199 @@ function deleteEmptyParagraph(unit, editor, deleteFunction) {
5585
5587
  }
5586
5588
  }
5587
5589
 
5588
- var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
5589
- return plateTrailingBlock.createTrailingBlockPlugin({
5590
- options: {
5591
- type: Contentful.BLOCKS.PARAGRAPH,
5592
- level: 0
5590
+ var _extends2, _extends4, _inlines;
5591
+ var inlines = /*#__PURE__*/Object.values(Contentful.INLINES).map(function (type) {
5592
+ return {
5593
+ type: type
5594
+ };
5595
+ });
5596
+ var schema = {
5597
+ document: {
5598
+ nodes: [{
5599
+ types: /*#__PURE__*/Contentful.TOP_LEVEL_BLOCKS.map(function (type) {
5600
+ return {
5601
+ type: type
5602
+ };
5603
+ })
5604
+ }]
5605
+ },
5606
+ blocks: /*#__PURE__*/_extends((_extends2 = {}, _extends2[Contentful.BLOCKS.PARAGRAPH] = {
5607
+ nodes: [{
5608
+ match: /*#__PURE__*/[].concat(inlines, [{
5609
+ object: 'text'
5610
+ }])
5611
+ }]
5612
+ }, _extends2[Contentful.BLOCKS.HEADING_1] = {
5613
+ nodes: [{
5614
+ match: /*#__PURE__*/[].concat(inlines, [{
5615
+ object: 'text'
5616
+ }])
5617
+ }]
5618
+ }, _extends2[Contentful.BLOCKS.HEADING_2] = {
5619
+ nodes: [{
5620
+ match: /*#__PURE__*/[].concat(inlines, [{
5621
+ object: 'text'
5622
+ }])
5623
+ }]
5624
+ }, _extends2[Contentful.BLOCKS.HEADING_3] = {
5625
+ nodes: [{
5626
+ match: /*#__PURE__*/[].concat(inlines, [{
5627
+ object: 'text'
5628
+ }])
5629
+ }]
5630
+ }, _extends2[Contentful.BLOCKS.HEADING_4] = {
5631
+ nodes: [{
5632
+ match: /*#__PURE__*/[].concat(inlines, [{
5633
+ object: 'text'
5634
+ }])
5635
+ }]
5636
+ }, _extends2[Contentful.BLOCKS.HEADING_5] = {
5637
+ nodes: [{
5638
+ match: /*#__PURE__*/[].concat(inlines, [{
5639
+ object: 'text'
5640
+ }])
5641
+ }]
5642
+ }, _extends2[Contentful.BLOCKS.HEADING_6] = {
5643
+ nodes: [{
5644
+ match: /*#__PURE__*/[].concat(inlines, [{
5645
+ object: 'text'
5646
+ }])
5647
+ }]
5648
+ }, _extends2), /*#__PURE__*/Contentful.VOID_BLOCKS.reduce(function (blocks, nodeType) {
5649
+ var _extends3;
5650
+
5651
+ return _extends({}, blocks, (_extends3 = {}, _extends3[nodeType] = {
5652
+ isVoid: true
5653
+ }, _extends3));
5654
+ }, {}), (_extends4 = {}, _extends4[Contentful.BLOCKS.QUOTE] = {
5655
+ nodes: [{
5656
+ match: [/*#__PURE__*/Contentful.CONTAINERS[Contentful.BLOCKS.QUOTE].map(function (type) {
5657
+ return {
5658
+ type: type
5659
+ };
5660
+ })],
5661
+ min: 1
5662
+ }],
5663
+ normalize: function normalize(editor, error) {
5664
+ if (error.code === 'child_type_invalid') {
5665
+ return editor.unwrapBlockByKey(error.node.key, Contentful.BLOCKS.QUOTE);
5666
+ }
5593
5667
  }
5668
+ }, _extends4)),
5669
+ inlines: (_inlines = {}, _inlines[Contentful.INLINES.HYPERLINK] = {
5670
+ nodes: [{
5671
+ match: [{
5672
+ object: 'text'
5673
+ }]
5674
+ }]
5675
+ }, _inlines[Contentful.INLINES.ENTRY_HYPERLINK] = {
5676
+ nodes: [{
5677
+ match: [{
5678
+ object: 'text'
5679
+ }]
5680
+ }]
5681
+ }, _inlines[Contentful.INLINES.ASSET_HYPERLINK] = {
5682
+ nodes: [{
5683
+ match: [{
5684
+ object: 'text'
5685
+ }]
5686
+ }]
5687
+ }, _inlines[Contentful.INLINES.EMBEDDED_ENTRY] = {
5688
+ isVoid: true
5689
+ }, _inlines)
5690
+ };
5691
+
5692
+ function getCharacterCount(editor) {
5693
+ var document = contentfulSlateJSAdapter.toContentfulDocument({
5694
+ document: editor.children,
5695
+ schema: schema
5594
5696
  });
5697
+ return richTextPlainTextRenderer.documentToPlainTextString(document).length;
5698
+ }
5699
+
5700
+ var actionOrigin = {
5701
+ TOOLBAR: 'toolbar-icon',
5702
+ SHORTCUT: 'shortcut',
5703
+ VIEWPORT: 'viewport-interaction',
5704
+ COMMAND_PALETTE: 'command-palette'
5595
5705
  };
5706
+ var createTrackingPlugin = function createTrackingPlugin(onAction) {
5707
+ var trackingActions = {
5708
+ onViewportAction: function onViewportAction(actionName, data) {
5709
+ if (data === void 0) {
5710
+ data = {};
5711
+ }
5596
5712
 
5597
- /**
5598
- * Re-creates a void node with valid children.
5599
- */
5713
+ return onAction(actionName, _extends({
5714
+ origin: actionOrigin.VIEWPORT
5715
+ }, data));
5716
+ },
5717
+ onShortcutAction: function onShortcutAction(actionName, data) {
5718
+ if (data === void 0) {
5719
+ data = {};
5720
+ }
5600
5721
 
5601
- var transformVoid = function transformVoid(editor, _ref) {
5602
- var node = _ref[0],
5603
- path = _ref[1];
5722
+ return onAction(actionName, _extends({
5723
+ origin: actionOrigin.SHORTCUT
5724
+ }, data));
5725
+ },
5726
+ onToolbarAction: function onToolbarAction(actionName, data) {
5727
+ if (data === void 0) {
5728
+ data = {};
5729
+ }
5604
5730
 
5605
- var validVoid = _extends({}, node, {
5606
- children: [{
5607
- text: ''
5608
- }]
5609
- }); // A workaround because Slate doesn't allow adjusting void nodes children
5731
+ return onAction(actionName, _extends({
5732
+ origin: actionOrigin.TOOLBAR
5733
+ }, data));
5734
+ },
5735
+ onCommandPaletteAction: function onCommandPaletteAction(actionName, data) {
5736
+ if (data === void 0) {
5737
+ data = {};
5738
+ }
5610
5739
 
5740
+ return onAction(actionName, _extends({
5741
+ origin: actionOrigin.COMMAND_PALETTE
5742
+ }, data));
5743
+ }
5744
+ };
5745
+ return {
5746
+ key: 'TrackingPlugin',
5747
+ withOverrides: function withOverrides(editor) {
5748
+ var insertData = editor.insertData;
5749
+ editor.tracking = trackingActions;
5750
+
5751
+ editor.insertData = function (data) {
5752
+ var isCopyAndPaste = data.types.length !== 0;
5753
+
5754
+ if (isCopyAndPaste) {
5755
+ var _window$getSelection;
5756
+
5757
+ var characterCountSelection = (_window$getSelection = window.getSelection()) == null ? void 0 : _window$getSelection.toString().length;
5758
+ var characterCountBefore = getCharacterCount(editor);
5759
+ setTimeout(function () {
5760
+ var characterCountAfter = getCharacterCount(editor);
5761
+ trackingActions.onShortcutAction('paste', {
5762
+ characterCountAfter: characterCountAfter,
5763
+ characterCountBefore: characterCountBefore,
5764
+ characterCountSelection: characterCountSelection
5765
+ });
5766
+ });
5767
+ }
5611
5768
 
5612
- slate.Transforms.removeNodes(editor, {
5613
- at: path
5614
- });
5615
- slate.Transforms.insertNodes(editor, [validVoid], {
5616
- at: path
5769
+ insertData(data);
5770
+ };
5771
+
5772
+ return editor;
5773
+ }
5774
+ };
5775
+ };
5776
+
5777
+ var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
5778
+ return plateTrailingBlock.createTrailingBlockPlugin({
5779
+ options: {
5780
+ type: Contentful.BLOCKS.PARAGRAPH,
5781
+ level: 0
5782
+ }
5617
5783
  });
5618
5784
  };
5619
5785
 
@@ -5645,34 +5811,17 @@ var createVoidsPlugin = function createVoidsPlugin() {
5645
5811
  return !(isRootLevel(path) && plateCore.isFirstChild(path)) && !!node.isVoid;
5646
5812
  }
5647
5813
  }
5648
- }],
5649
- normalizer: [{
5650
- match: {
5651
- isVoid: true
5652
- },
5653
- validNode: function validNode(editor, _ref3) {
5654
- var path = _ref3[1];
5655
- var children = Array.from(slate.Node.children(editor, path));
5656
-
5657
- if (children.length !== 1) {
5658
- return false;
5659
- }
5660
-
5661
- var _children$ = children[0],
5662
- textNode = _children$[0];
5663
- return slate.Text.isText(textNode) && textNode.text === '';
5664
- },
5665
- transform: transformVoid
5666
5814
  }]
5667
5815
  };
5668
5816
  };
5669
5817
 
5670
- var getPlugins = function getPlugins(sdk, tracking) {
5818
+ var getPlugins = function getPlugins(sdk, onAction) {
5671
5819
  return [// AST must come after the HTML deserializer
5672
- plateCore.createDeserializeHtmlPlugin(), plateCore.createDeserializeAstPlugin(), plateSerializerDocx.createDeserializeDocxPlugin(), // Global shortcuts
5820
+ plateCore.createDeserializeHtmlPlugin(), plateCore.createDeserializeAstPlugin(), plateSerializerDocx.createDeserializeDocxPlugin(), // Tracking - This should come first so all plugins below will have access to `editor.tracking`
5821
+ createTrackingPlugin(onAction), // Global / Global shortcuts
5673
5822
  createDragAndDropPlugin(), // Block Elements
5674
- createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk, tracking), createEmbeddedAssetBlockPlugin(sdk, tracking), // Inline elements
5675
- createHyperlinkPlugin(sdk, tracking), createEmbeddedEntityInlinePlugin(sdk, tracking), // Marks
5823
+ createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
5824
+ createHyperlinkPlugin(sdk), createEmbeddedEntityInlinePlugin(sdk), // Marks
5676
5825
  createMarksPlugin(), // Other
5677
5826
  createTrailingParagraphPlugin(), createTextPlugin(), createVoidsPlugin(), createSelectOnBackspacePlugin(), // Pasting content from other sources
5678
5827
  createPasteHTMLPlugin(), // These plugins drive their configurations from the list of plugins
@@ -5894,10 +6043,10 @@ var Toolbar = function Toolbar(_ref) {
5894
6043
  isDisabled: isDisabled
5895
6044
  })), validationInfo.isAnyBlockFormattingEnabled && /*#__PURE__*/React__default.createElement("span", {
5896
6045
  className: styles$k.divider
5897
- }), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.QUOTE) && /*#__PURE__*/React__default.createElement(ToolbarQuoteButton, {
5898
- isDisabled: isDisabled || !canInsertBlocks
5899
6046
  }), /*#__PURE__*/React__default.createElement(ToolbarListButton, {
5900
6047
  isDisabled: isDisabled || !canInsertBlocks
6048
+ }), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.QUOTE) && /*#__PURE__*/React__default.createElement(ToolbarQuoteButton, {
6049
+ isDisabled: isDisabled || !canInsertBlocks
5901
6050
  }), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.HR) && /*#__PURE__*/React__default.createElement(ToolbarHrButton, {
5902
6051
  isDisabled: isDisabled || !canInsertBlocks
5903
6052
  }), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.TABLE) && /*#__PURE__*/React__default.createElement(ToolbarTableButton, {
@@ -5967,7 +6116,7 @@ var useNormalizedSlateValue = function useNormalizedSlateValue(_ref) {
5967
6116
  plugins: plugins,
5968
6117
  disableCorePlugins: disableCorePlugins
5969
6118
  });
5970
- var doc = contentfulSlatejsAdapter.toSlatejsDocument({
6119
+ var doc = contentfulSlateJSAdapter.toSlatejsDocument({
5971
6120
  document: hasContent(incomingDoc) ? incomingDoc : Contentful.EMPTY_DOCUMENT,
5972
6121
  schema: schema
5973
6122
  }); // Sets editor value & kicks normalization
@@ -5981,18 +6130,56 @@ var useNormalizedSlateValue = function useNormalizedSlateValue(_ref) {
5981
6130
  }, [id, plugins, incomingDoc]);
5982
6131
  };
5983
6132
 
6133
+ /**
6134
+ * Returns whether a given operation is relevant enough to trigger a save.
6135
+ */
6136
+
6137
+ var isRelevantOperation = function isRelevantOperation(op) {
6138
+ if (op.type === 'set_selection') {
6139
+ return false;
6140
+ }
6141
+
6142
+ return true;
6143
+ };
6144
+
6145
+ var useOnValueChanged = function useOnValueChanged(_ref) {
6146
+ var editor = _ref.editor,
6147
+ handler = _ref.handler;
6148
+ var onChange = React.useMemo(function () {
6149
+ return debounce(function (document) {
6150
+ handler == null ? void 0 : handler(contentfulSlateJSAdapter.toContentfulDocument({
6151
+ document: document,
6152
+ schema: schema
6153
+ }));
6154
+ }, 500);
6155
+ }, [handler]);
6156
+ return React.useCallback(function (value) {
6157
+ var operations = editor.operations.filter(isRelevantOperation);
6158
+
6159
+ if (operations.length > 0) {
6160
+ onChange(value);
6161
+ }
6162
+ }, [editor, onChange]);
6163
+ };
6164
+
5984
6165
  var _excluded = ["sdk", "isInitiallyDisabled", "onAction"];
5985
6166
  var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
5986
- var id = getContentfulEditorId(props.sdk);
5987
- var tracking = useTrackingContext();
6167
+ var id = useContentfulEditorId();
6168
+ var editor = useContentfulEditor();
5988
6169
  var plugins = React__default.useMemo(function () {
5989
- return getPlugins(props.sdk, tracking);
5990
- }, [props.sdk, tracking]);
6170
+ var _props$onAction;
6171
+
6172
+ return getPlugins(props.sdk, (_props$onAction = props.onAction) != null ? _props$onAction : noop);
6173
+ }, [props.sdk, props.onAction]);
5991
6174
  var initialValue = useNormalizedSlateValue({
5992
6175
  id: id,
5993
6176
  incomingDoc: props.value,
5994
6177
  plugins: plugins
5995
6178
  });
6179
+ var onValueChanged = useOnValueChanged({
6180
+ editor: editor,
6181
+ handler: props.onChange
6182
+ });
5996
6183
  var classNames = emotion.cx(styles$j.editor, props.minHeight !== undefined ? emotion.css({
5997
6184
  minHeight: props.minHeight
5998
6185
  }) : undefined, props.isDisabled ? styles$j.disabled : styles$j.enabled, props.isToolbarHidden && styles$j.hiddenToolbar);
@@ -6008,12 +6195,7 @@ var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
6008
6195
  className: classNames,
6009
6196
  readOnly: props.isDisabled
6010
6197
  },
6011
- onChange: function onChange(document) {
6012
- props.onChange == null ? void 0 : props.onChange(contentfulSlatejsAdapter.toContentfulDocument({
6013
- document: document,
6014
- schema: schema
6015
- }));
6016
- }
6198
+ onChange: onValueChanged
6017
6199
  }, !props.isToolbarHidden && /*#__PURE__*/React__default.createElement(StickyToolbarWrapper, {
6018
6200
  isDisabled: props.isDisabled
6019
6201
  }, /*#__PURE__*/React__default.createElement(Toolbar, {
@@ -6030,12 +6212,11 @@ var RichTextEditor = function RichTextEditor(props) {
6030
6212
  var isEmptyValue = React.useCallback(function (value) {
6031
6213
  return !value || deepEquals(value, Contentful.EMPTY_DOCUMENT);
6032
6214
  }, []);
6215
+ var editorId = getContentfulEditorId(sdk);
6033
6216
  return /*#__PURE__*/React__default.createElement(fieldEditorReference.EntityProvider, {
6034
6217
  sdk: sdk
6035
6218
  }, /*#__PURE__*/React__default.createElement(SdkProvider, {
6036
6219
  sdk: sdk
6037
- }, /*#__PURE__*/React__default.createElement(TrackingProvider, {
6038
- onAction: onAction || noop
6039
6220
  }, /*#__PURE__*/React__default.createElement(fieldEditorShared.FieldConnector, {
6040
6221
  throttle: 0,
6041
6222
  field: sdk.field,
@@ -6047,17 +6228,17 @@ var RichTextEditor = function RichTextEditor(props) {
6047
6228
  disabled = _ref.disabled,
6048
6229
  setValue = _ref.setValue,
6049
6230
  externalReset = _ref.externalReset;
6050
- return /*#__PURE__*/React__default.createElement(ContentfulEditorProvider, {
6051
- sdk: sdk
6231
+ return /*#__PURE__*/React__default.createElement(ContentfulEditorIdProvider, {
6232
+ value: editorId
6052
6233
  }, /*#__PURE__*/React__default.createElement(ConnectedRichTextEditor, Object.assign({}, otherProps, {
6053
6234
  key: "rich-text-editor-" + externalReset,
6054
6235
  value: lastRemoteValue,
6055
6236
  sdk: sdk,
6056
- onAction: onAction || noop,
6237
+ onAction: onAction,
6057
6238
  isDisabled: disabled,
6058
6239
  onChange: setValue
6059
6240
  })));
6060
- }))));
6241
+ })));
6061
6242
  };
6062
6243
 
6063
6244
  var LINK_TYPES$1 = {