@contentful/field-editor-rich-text 2.0.0-next.11 → 2.0.0-next.14

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 +555 -425
  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 +558 -428
  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/Quote/toggleQuote.d.ts +5 -3
  35. package/dist/plugins/Table/actions/addColumn.d.ts +3 -3
  36. package/dist/plugins/Table/actions/addRow.d.ts +3 -3
  37. package/dist/plugins/Table/actions/setHeader.d.ts +2 -2
  38. package/dist/plugins/Table/addTableTrackingEvents.d.ts +2 -3
  39. package/dist/plugins/Table/createTablePlugin.d.ts +1 -2
  40. package/dist/plugins/Table/helpers.d.ts +7 -7
  41. package/dist/plugins/Tracking/createTrackingPlugin.d.ts +10 -0
  42. package/dist/plugins/Tracking/index.d.ts +1 -0
  43. package/dist/plugins/Tracking/utils.d.ts +2 -0
  44. package/dist/plugins/TrailingParagraph/index.d.ts +2 -1
  45. package/dist/plugins/Voids/transformVoid.d.ts +2 -2
  46. package/dist/plugins/index.d.ts +2 -2
  47. package/dist/plugins/links-tracking.d.ts +1 -2
  48. package/dist/test-utils/assertOutput.d.ts +2 -2
  49. package/dist/test-utils/createEditor.d.ts +5 -6
  50. package/dist/test-utils/jsx.d.ts +1 -1
  51. package/dist/test-utils/mockPlugin.d.ts +1 -1
  52. package/dist/test-utils/setEmptyDataAttribute.d.ts +2 -2
  53. package/dist/types.d.ts +6 -2
  54. package/dist/useNormalizedSlateValue.d.ts +7 -0
  55. package/dist/useOnValueChanged.d.ts +7 -0
  56. package/package.json +1 -1
  57. package/dist/TrackingProvider.d.ts +0 -11
  58. package/dist/helpers/sanitizeSlateDoc.d.ts +0 -5
@@ -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 slate = require('slate');
18
- var constate = _interopDefault(require('constate'));
19
16
  var plateSerializerDocx = require('@udecode/plate-serializer-docx');
20
17
  var plateBreak = require('@udecode/plate-break');
21
18
  var isHotkey = _interopDefault(require('is-hotkey'));
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,159 +246,35 @@ 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);
359
- var editor = plateCore.usePlateEditorRef(editorId);
360
- return editor;
361
- }
362
-
363
- var _constate = /*#__PURE__*/constate(useContentfulEditorHook),
364
- ContentfulEditorProvider = _constate[0],
365
- useContentfulEditor = _constate[1];
366
-
367
- var isTextElement = function isTextElement(node) {
368
- return 'text' in node;
369
- };
370
- /**
371
- * Ensures incoming void nodes have a child leaf text element.
372
- */
373
-
374
-
375
- function sanitizeIncomingSlateDoc(nodes) {
376
- if (nodes === void 0) {
377
- nodes = [];
260
+ if (!id) {
261
+ throw new Error('could not find editor id. Please ensure the component is wrapped in <ContentfulEditorIdProvider> ');
378
262
  }
379
263
 
380
- return nodes.map(function (node) {
381
- var _node$children;
264
+ return id;
265
+ } // This hook re-renders when the value changes
266
+ // Use case: Toolbar icons, for example
382
267
 
383
- if (isTextElement(node)) {
384
- return node;
385
- }
386
-
387
- if (node.isVoid && ((_node$children = node.children) == null ? void 0 : _node$children.length) === 0) {
388
- return _extends({}, node, {
389
- children: [{
390
- text: '',
391
- data: {}
392
- }]
393
- });
394
- }
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
395
273
 
396
- return _extends({}, node, {
397
- children: sanitizeIncomingSlateDoc(node.children)
398
- });
399
- });
274
+ function useContentfulEditorRef() {
275
+ var editorId = useContentfulEditorId();
276
+ var editor = plateCore.usePlateEditorRef(editorId);
277
+ return editor;
400
278
  }
401
279
 
402
280
  var createSoftBreakPlugin = function createSoftBreakPlugin() {
@@ -578,6 +456,10 @@ function insertLink(editor, options) {
578
456
  } // TODO: move to hyperlink plugin
579
457
 
580
458
  function isLinkActive(editor) {
459
+ if (!editor) {
460
+ return false;
461
+ }
462
+
581
463
  var _Array$from2 = Array.from(slate.Editor.nodes(editor, {
582
464
  match: function match(node) {
583
465
  return !slate.Editor.isEditor(node) && slate.Element.isElement(node) && LINK_TYPES.includes(node.type);
@@ -737,12 +619,14 @@ var focus = function focus(editor) {
737
619
  }
738
620
  };
739
621
 
740
- function withLinkTracking(tracking, Component) {
622
+ function withLinkTracking(Component) {
741
623
  return function ComponentWithTracking(props) {
624
+ var editor = useContentfulEditorRef();
625
+ var onEntityFetchComplete = React__default.useCallback(function () {
626
+ return editor.tracking.onViewportAction('linkRendered');
627
+ }, [editor]);
742
628
  return /*#__PURE__*/React__default.createElement(Component, Object.assign({}, props, {
743
- onEntityFetchComplete: function onEntityFetchComplete() {
744
- tracking.onViewportAction('linkRendered');
745
- }
629
+ onEntityFetchComplete: onEntityFetchComplete
746
630
  }));
747
631
  };
748
632
  }
@@ -756,9 +640,9 @@ function useSdk(_ref) {
756
640
  return sdkMemo;
757
641
  }
758
642
 
759
- var _constate$1 = /*#__PURE__*/constate(useSdk),
760
- SdkProvider = _constate$1[0],
761
- useSdkContext = _constate$1[1];
643
+ var _constate = /*#__PURE__*/constate(useSdk),
644
+ SdkProvider = _constate[0],
645
+ useSdkContext = _constate[1];
762
646
 
763
647
  var styles = {
764
648
  scheduleIcon: /*#__PURE__*/emotion.css({
@@ -2008,12 +1892,11 @@ function _selectEntityAndInsert() {
2008
1892
  config = _extends({}, baseConfig, {
2009
1893
  withCreate: true
2010
1894
  });
2011
- _context.prev = 5;
2012
1895
  selection = editor.selection;
2013
- _context.next = 9;
1896
+ _context.next = 8;
2014
1897
  return selectEntity(config);
2015
1898
 
2016
- case 9:
1899
+ case 8:
2017
1900
  entity = _context.sent;
2018
1901
 
2019
1902
  if (entity) {
@@ -2021,6 +1904,9 @@ function _selectEntityAndInsert() {
2021
1904
  break;
2022
1905
  }
2023
1906
 
1907
+ logAction('cancelCreateEmbedDialog', {
1908
+ nodeType: nodeType
1909
+ });
2024
1910
  return _context.abrupt("return");
2025
1911
 
2026
1912
  case 12:
@@ -2029,31 +1915,13 @@ function _selectEntityAndInsert() {
2029
1915
  logAction('insert', {
2030
1916
  nodeType: nodeType
2031
1917
  });
2032
- _context.next = 24;
2033
- break;
2034
-
2035
- case 17:
2036
- _context.prev = 17;
2037
- _context.t0 = _context["catch"](5);
2038
-
2039
- if (!_context.t0) {
2040
- _context.next = 23;
2041
- break;
2042
- }
2043
-
2044
- throw _context.t0;
2045
-
2046
- case 23:
2047
- logAction('cancelCreateEmbedDialog', {
2048
- nodeType: nodeType
2049
- });
2050
1918
 
2051
- case 24:
1919
+ case 15:
2052
1920
  case "end":
2053
1921
  return _context.stop();
2054
1922
  }
2055
1923
  }
2056
- }, _callee, null, [[5, 17]]);
1924
+ }, _callee);
2057
1925
  }));
2058
1926
  return _selectEntityAndInsert.apply(this, arguments);
2059
1927
  }
@@ -2100,7 +1968,6 @@ var styles$4 = {
2100
1968
  function EmbeddedEntityBlockToolbarIcon(_ref) {
2101
1969
  var isButton = _ref.isButton,
2102
1970
  isDisabled = _ref.isDisabled,
2103
- logAction = _ref.logAction,
2104
1971
  nodeType = _ref.nodeType,
2105
1972
  onClose = _ref.onClose;
2106
1973
  var editor = useContentfulEditor();
@@ -2109,7 +1976,7 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
2109
1976
  var handleClick = function handleClick(event) {
2110
1977
  event.preventDefault();
2111
1978
  onClose();
2112
- selectEntityAndInsert(nodeType, sdk, editor, logAction || noop);
1979
+ selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onToolbarAction);
2113
1980
  };
2114
1981
 
2115
1982
  var type = getEntityTypeFromNodeType(nodeType);
@@ -2176,20 +2043,20 @@ function getWithEmbeddedEntityEvents(nodeType, sdk) {
2176
2043
  }
2177
2044
 
2178
2045
  if (hotkey && isHotkey(hotkey, event)) {
2179
- selectEntityAndInsert(nodeType, sdk, editor, noop);
2046
+ selectEntityAndInsert(nodeType, sdk, editor, editor.tracking.onShortcutAction);
2180
2047
  }
2181
2048
  };
2182
2049
  };
2183
2050
  }
2184
2051
 
2185
2052
  var createEmbeddedEntityPlugin = function createEmbeddedEntityPlugin(nodeType, hotkey) {
2186
- return function (sdk, tracking) {
2053
+ return function (sdk) {
2187
2054
  return {
2188
2055
  key: nodeType,
2189
2056
  type: nodeType,
2190
2057
  isElement: true,
2191
2058
  isVoid: true,
2192
- component: withLinkTracking(tracking, LinkedEntityBlock),
2059
+ component: withLinkTracking(LinkedEntityBlock),
2193
2060
  options: {
2194
2061
  hotkey: hotkey
2195
2062
  },
@@ -2407,44 +2274,53 @@ function EmbeddedEntityInline(props) {
2407
2274
  })), props.children);
2408
2275
  }
2409
2276
 
2410
- function selectEntityAndInsert$1(_x, _x2) {
2277
+ function selectEntityAndInsert$1(_x, _x2, _x3) {
2411
2278
  return _selectEntityAndInsert$1.apply(this, arguments);
2412
2279
  }
2413
2280
 
2414
2281
  function _selectEntityAndInsert$1() {
2415
- _selectEntityAndInsert$1 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(editor, sdk) {
2282
+ _selectEntityAndInsert$1 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(editor, sdk, logAction) {
2416
2283
  var config, selection, entry, inlineEntryNode;
2417
2284
  return runtime_1.wrap(function _callee2$(_context2) {
2418
2285
  while (1) {
2419
2286
  switch (_context2.prev = _context2.next) {
2420
2287
  case 0:
2288
+ logAction('openCreateEmbedDialog', {
2289
+ nodeType: Contentful.INLINES.EMBEDDED_ENTRY
2290
+ });
2421
2291
  config = _extends({}, newEntitySelectorConfigFromRichTextField(sdk.field, Contentful.INLINES.EMBEDDED_ENTRY), {
2422
2292
  withCreate: true
2423
2293
  });
2424
2294
  selection = editor.selection;
2425
- _context2.next = 4;
2295
+ _context2.next = 5;
2426
2296
  return sdk.dialogs.selectSingleEntry(config);
2427
2297
 
2428
- case 4:
2298
+ case 5:
2429
2299
  entry = _context2.sent;
2430
2300
  focus(editor); // Dialog steals focus from editor, return it.
2431
2301
 
2432
2302
  if (entry) {
2433
- _context2.next = 8;
2303
+ _context2.next = 10;
2434
2304
  break;
2435
2305
  }
2436
2306
 
2307
+ logAction('cancelCreateEmbedDialog', {
2308
+ nodeType: Contentful.INLINES.EMBEDDED_ENTRY
2309
+ });
2437
2310
  return _context2.abrupt("return");
2438
2311
 
2439
- case 8:
2312
+ case 10:
2440
2313
  inlineEntryNode = createInlineEntryNode(entry.sys.id); // Got to wait until focus is really back on the editor or setSelection() won't work.
2441
2314
 
2442
2315
  setTimeout(function () {
2443
2316
  slate.Transforms.setSelection(editor, selection);
2444
2317
  slate.Transforms.insertNodes(editor, inlineEntryNode);
2445
2318
  }, 0);
2319
+ logAction('insert', {
2320
+ nodeType: Contentful.INLINES.EMBEDDED_ENTRY
2321
+ });
2446
2322
 
2447
- case 10:
2323
+ case 13:
2448
2324
  case "end":
2449
2325
  return _context2.stop();
2450
2326
  }
@@ -2458,7 +2334,7 @@ function ToolbarEmbeddedEntityInlineButton(props) {
2458
2334
  var editor = useContentfulEditor();
2459
2335
  var sdk = useSdkContext();
2460
2336
 
2461
- function handleClick(_x3) {
2337
+ function handleClick(_x4) {
2462
2338
  return _handleClick.apply(this, arguments);
2463
2339
  }
2464
2340
 
@@ -2480,7 +2356,7 @@ function ToolbarEmbeddedEntityInlineButton(props) {
2480
2356
  case 3:
2481
2357
  props.onClose();
2482
2358
  _context.next = 6;
2483
- return selectEntityAndInsert$1(editor, sdk);
2359
+ return selectEntityAndInsert$1(editor, sdk, editor.tracking.onToolbarAction);
2484
2360
 
2485
2361
  case 6:
2486
2362
  case "end":
@@ -2513,7 +2389,7 @@ function ToolbarEmbeddedEntityInlineButton(props) {
2513
2389
  className: "rich-text__embedded-entry-list-icon " + styles$6.icon
2514
2390
  }), /*#__PURE__*/React.createElement("span", null, "Inline entry")));
2515
2391
  }
2516
- function createEmbeddedEntityInlinePlugin(sdk, tracking) {
2392
+ function createEmbeddedEntityInlinePlugin(sdk) {
2517
2393
  var htmlAttributeName = 'data-embedded-entity-inline-id';
2518
2394
  return {
2519
2395
  key: Contentful.INLINES.EMBEDDED_ENTRY,
@@ -2521,7 +2397,7 @@ function createEmbeddedEntityInlinePlugin(sdk, tracking) {
2521
2397
  isElement: true,
2522
2398
  isInline: true,
2523
2399
  isVoid: true,
2524
- component: withLinkTracking(tracking, EmbeddedEntityInline),
2400
+ component: withLinkTracking(EmbeddedEntityInline),
2525
2401
  options: {
2526
2402
  hotkey: 'mod+shift+2'
2527
2403
  },
@@ -2547,7 +2423,7 @@ function getWithEmbeddedEntryInlineEvents(sdk) {
2547
2423
  if (!editor) return;
2548
2424
 
2549
2425
  if (hotkey && isHotkey(hotkey, event)) {
2550
- selectEntityAndInsert$1(editor, sdk);
2426
+ selectEntityAndInsert$1(editor, sdk, editor.tracking.onShortcutAction);
2551
2427
  }
2552
2428
  };
2553
2429
  };
@@ -2650,6 +2526,10 @@ function ToolbarHeadingButton(props) {
2650
2526
  prevOnChange.apply(void 0, arguments);
2651
2527
  };
2652
2528
 
2529
+ var isActive = isBlockSelected(editor, type);
2530
+ editor.tracking.onToolbarAction(isActive ? 'remove' : 'insert', {
2531
+ nodeType: type
2532
+ });
2653
2533
  plateCore.toggleNodeType(editor, {
2654
2534
  activeType: type,
2655
2535
  inactiveType: type
@@ -2691,7 +2571,7 @@ function extractNodes(editor, path, match) {
2691
2571
  return Array.from(plateCore.getNodes(editor, {
2692
2572
  match: match,
2693
2573
  at: path,
2694
- mode: 'all'
2574
+ mode: 'lowest'
2695
2575
  })).map(function (_ref) {
2696
2576
  var node = _ref[0];
2697
2577
  return node;
@@ -2771,6 +2651,24 @@ function createHeading(Tag, block) {
2771
2651
 
2772
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);
2773
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
+
2774
2672
  var createHeadingPlugin = function createHeadingPlugin() {
2775
2673
  var _transform;
2776
2674
 
@@ -2787,8 +2685,8 @@ var createHeadingPlugin = function createHeadingPlugin() {
2787
2685
  match: {
2788
2686
  type: Contentful.HEADINGS
2789
2687
  },
2790
- validChildren: function validChildren(_, _ref) {
2791
- var node = _ref[0];
2688
+ validChildren: function validChildren(_, _ref2) {
2689
+ var node = _ref2[0];
2792
2690
  return isInlineOrText(node);
2793
2691
  },
2794
2692
  transform: (_transform = {}, _transform[Contentful.BLOCKS.PARAGRAPH] = transformUnwrap, _transform["default"] = transformLift, _transform)
@@ -2805,8 +2703,8 @@ var createHeadingPlugin = function createHeadingPlugin() {
2805
2703
  start: true,
2806
2704
  // Exclude headings inside lists as it interferes with the list's
2807
2705
  // insertBreak implementation
2808
- filter: function filter(_ref2) {
2809
- var path = _ref2[1];
2706
+ filter: function filter(_ref3) {
2707
+ var path = _ref3[1];
2810
2708
  return !plateCore.getAbove(editor, {
2811
2709
  at: path,
2812
2710
  match: {
@@ -2830,7 +2728,7 @@ var createHeadingPlugin = function createHeadingPlugin() {
2830
2728
  hotkey: ["mod+alt+" + level]
2831
2729
  },
2832
2730
  handlers: {
2833
- onKeyDown: plateCore.onKeyDownToggleElement
2731
+ onKeyDown: buildHeadingEventHandler(nodeType)
2834
2732
  },
2835
2733
  deserializeHtml: {
2836
2734
  rules: [{
@@ -3360,13 +3258,15 @@ function HyperlinkModal(props) {
3360
3258
  testId: "confirm-cta"
3361
3259
  }, props.linkType ? 'Update' : 'Insert'))));
3362
3260
  }
3363
- function addOrEditLink(_x, _x2) {
3261
+ function addOrEditLink(_x, _x2, _x3) {
3364
3262
  return _addOrEditLink.apply(this, arguments);
3365
3263
  }
3366
3264
 
3367
3265
  function _addOrEditLink() {
3368
- _addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk) {
3369
- var linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path, selectionBeforeBlur, currentLinkText, data, text, url, type, target;
3266
+ _addOrEditLink = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(editor, sdk, logAction) {
3267
+ var _target$sys$linkType;
3268
+
3269
+ var linkType, linkText, linkTarget, linkEntity, _getNodeEntryFromSele, node, path, selectionBeforeBlur, currentLinkText, isEditing, data, text, url, type, target;
3370
3270
 
3371
3271
  return runtime_1.wrap(function _callee3$(_context3) {
3372
3272
  while (1) {
@@ -3391,9 +3291,11 @@ function _addOrEditLink() {
3391
3291
 
3392
3292
  selectionBeforeBlur = _extends({}, editor.selection);
3393
3293
  currentLinkText = linkText || slate.Editor.string(editor, editor.selection);
3394
- _context3.next = 8;
3294
+ isEditing = Boolean(node && path);
3295
+ logAction(isEditing ? 'openEditHyperlinkDialog' : 'openCreateHyperlinkDialog');
3296
+ _context3.next = 10;
3395
3297
  return fieldEditorShared.ModalDialogLauncher.openDialog({
3396
- title: linkType ? 'Edit hyperlink' : 'Insert hyperlink',
3298
+ title: isEditing ? 'Edit hyperlink' : 'Insert hyperlink',
3397
3299
  width: 'large',
3398
3300
  shouldCloseOnEscapePress: true,
3399
3301
  shouldCloseOnOverlayClick: true,
@@ -3410,17 +3312,18 @@ function _addOrEditLink() {
3410
3312
  });
3411
3313
  });
3412
3314
 
3413
- case 8:
3315
+ case 10:
3414
3316
  data = _context3.sent;
3415
3317
 
3416
3318
  if (data) {
3417
- _context3.next = 11;
3319
+ _context3.next = 14;
3418
3320
  break;
3419
3321
  }
3420
3322
 
3323
+ logAction(isEditing ? 'cancelEditHyperlinkDialog' : 'cancelCreateHyperlinkDialog');
3421
3324
  return _context3.abrupt("return");
3422
3325
 
3423
- case 11:
3326
+ case 14:
3424
3327
  text = data.linkText, url = data.linkTarget, type = data.linkType, target = data.linkEntity;
3425
3328
  slate.Transforms.select(editor, selectionBeforeBlur);
3426
3329
  slate.Editor.withoutNormalizing(editor, function () {
@@ -3432,9 +3335,13 @@ function _addOrEditLink() {
3432
3335
  path: path
3433
3336
  });
3434
3337
  });
3338
+ logAction(isEditing ? 'edit' : 'insert', {
3339
+ nodeType: type,
3340
+ linkType: (_target$sys$linkType = target == null ? void 0 : target.sys.linkType) != null ? _target$sys$linkType : 'uri'
3341
+ });
3435
3342
  focus(editor);
3436
3343
 
3437
- case 15:
3344
+ case 19:
3438
3345
  case "end":
3439
3346
  return _context3.stop();
3440
3347
  }
@@ -3498,7 +3405,7 @@ function UrlHyperlink(props) {
3498
3405
  event.preventDefault();
3499
3406
  event.stopPropagation();
3500
3407
  if (!editor) return;
3501
- addOrEditLink(editor, sdk);
3408
+ addOrEditLink(editor, sdk, editor.tracking.onViewportAction);
3502
3409
  }
3503
3410
 
3504
3411
  return /*#__PURE__*/React.createElement(f36Components.Tooltip, {
@@ -3534,7 +3441,7 @@ function EntityHyperlink(props) {
3534
3441
  event.preventDefault();
3535
3442
  event.stopPropagation();
3536
3443
  if (!editor) return;
3537
- addOrEditLink(editor, sdk);
3444
+ addOrEditLink(editor, sdk, editor.tracking.onViewportAction);
3538
3445
  }
3539
3446
 
3540
3447
  return /*#__PURE__*/React.createElement(f36Components.Tooltip, {
@@ -3581,8 +3488,9 @@ function ToolbarHyperlinkButton(props) {
3581
3488
  case 2:
3582
3489
  if (isActive) {
3583
3490
  unwrapLink(editor);
3491
+ editor.tracking.onToolbarAction('unlinkHyperlinks');
3584
3492
  } else {
3585
- addOrEditLink(editor, sdk);
3493
+ addOrEditLink(editor, sdk, editor.tracking.onToolbarAction);
3586
3494
  }
3587
3495
 
3588
3496
  case 3:
@@ -3631,8 +3539,9 @@ var buildHyperlinkEventHandler = function buildHyperlinkEventHandler(sdk) {
3631
3539
 
3632
3540
  if (isLinkActive(editor)) {
3633
3541
  unwrapLink(editor);
3542
+ editor.tracking.onShortcutAction('unlinkHyperlinks');
3634
3543
  } else {
3635
- addOrEditLink(editor, sdk);
3544
+ addOrEditLink(editor, sdk, editor.tracking.onShortcutAction);
3636
3545
  }
3637
3546
  };
3638
3547
  };
@@ -3658,7 +3567,7 @@ var getNodeOfType = function getNodeOfType(type) {
3658
3567
  };
3659
3568
  };
3660
3569
 
3661
- var createHyperlinkPlugin = function createHyperlinkPlugin(sdk, tracking) {
3570
+ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk) {
3662
3571
  var common = {
3663
3572
  isElement: true,
3664
3573
  isInline: true
@@ -3689,7 +3598,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk, tracking) {
3689
3598
  _extends({}, common, {
3690
3599
  key: Contentful.INLINES.ENTRY_HYPERLINK,
3691
3600
  type: Contentful.INLINES.ENTRY_HYPERLINK,
3692
- component: withLinkTracking(tracking, EntityHyperlink),
3601
+ component: withLinkTracking(EntityHyperlink),
3693
3602
  deserializeHtml: {
3694
3603
  rules: [{
3695
3604
  validNodeName: ['A']
@@ -3703,7 +3612,7 @@ var createHyperlinkPlugin = function createHyperlinkPlugin(sdk, tracking) {
3703
3612
  _extends({}, common, {
3704
3613
  key: Contentful.INLINES.ASSET_HYPERLINK,
3705
3614
  type: Contentful.INLINES.ASSET_HYPERLINK,
3706
- component: withLinkTracking(tracking, EntityHyperlink),
3615
+ component: withLinkTracking(EntityHyperlink),
3707
3616
  deserializeHtml: {
3708
3617
  rules: [{
3709
3618
  validNodeName: ['A']
@@ -4177,6 +4086,7 @@ var createListPlugin = function createListPlugin() {
4177
4086
  }, _overrideByKey[plateList.ELEMENT_LI] = {
4178
4087
  type: Contentful.BLOCKS.LIST_ITEM,
4179
4088
  component: ListItem,
4089
+ // @ts-expect-error
4180
4090
  normalizer: [{
4181
4091
  validNode: hasListAsDirectParent,
4182
4092
  transform: normalizeOrphanedListItem
@@ -4229,26 +4139,62 @@ function ToolbarListButton(props) {
4229
4139
  }, /*#__PURE__*/React.createElement(f36Icons.ListNumberedIcon, null)));
4230
4140
  }
4231
4141
 
4232
- function ToolbarBoldButton(props) {
4233
- var editor = useContentfulEditor();
4142
+ var createMarkToolbarButton = function createMarkToolbarButton(_ref) {
4143
+ var mark = _ref.mark,
4144
+ title = _ref.title,
4145
+ icon = _ref.icon;
4234
4146
 
4235
- function handleClick() {
4236
- if (!(editor != null && editor.selection)) return;
4237
- plateCore.toggleMark(editor, {
4238
- key: Contentful.MARKS.BOLD
4239
- });
4240
- focus(editor);
4241
- }
4147
+ var Mark = function Mark(_ref2) {
4148
+ var isDisabled = _ref2.isDisabled;
4149
+ var editor = useContentfulEditor();
4150
+ var handleClick = React.useCallback(function () {
4151
+ if (!(editor != null && editor.selection)) return;
4152
+ var isActive = plateCore.isMarkActive(editor, mark);
4153
+ editor.tracking.onToolbarAction(isActive ? 'unmark' : 'mark', {
4154
+ markType: mark
4155
+ });
4156
+ plateCore.toggleMark(editor, {
4157
+ key: mark
4158
+ });
4159
+ focus(editor);
4160
+ }, [editor]);
4161
+ if (!editor) return null;
4162
+ return /*#__PURE__*/React.createElement(ToolbarButton, {
4163
+ title: title,
4164
+ testId: mark + "-toolbar-button",
4165
+ onClick: handleClick,
4166
+ isActive: plateCore.isMarkActive(editor, mark),
4167
+ isDisabled: isDisabled
4168
+ }, icon);
4169
+ };
4242
4170
 
4243
- if (!editor) return null;
4244
- return /*#__PURE__*/React.createElement(ToolbarButton, {
4245
- title: "Bold",
4246
- testId: "bold-toolbar-button",
4247
- onClick: handleClick,
4248
- isActive: plateCore.isMarkActive(editor, Contentful.MARKS.BOLD),
4249
- isDisabled: props.isDisabled
4250
- }, /*#__PURE__*/React.createElement(f36Icons.FormatBoldIcon, null));
4251
- }
4171
+ Mark.displayName = mark;
4172
+ return Mark;
4173
+ };
4174
+
4175
+ var buildMarkEventHandler = function buildMarkEventHandler(type) {
4176
+ return function (editor, _ref) {
4177
+ var hotkey = _ref.options.hotkey;
4178
+ return function (event) {
4179
+ if (editor.selection && hotkey && isHotkey(hotkey, event)) {
4180
+ event.preventDefault();
4181
+ var isActive = plateCore.isMarkActive(editor, type);
4182
+ editor.tracking.onShortcutAction(isActive ? 'unmark' : 'mark', {
4183
+ markType: type
4184
+ });
4185
+ plateCore.toggleMark(editor, {
4186
+ key: type
4187
+ });
4188
+ }
4189
+ };
4190
+ };
4191
+ };
4192
+
4193
+ var ToolbarBoldButton = /*#__PURE__*/createMarkToolbarButton({
4194
+ title: 'Bold',
4195
+ mark: Contentful.MARKS.BOLD,
4196
+ icon: /*#__PURE__*/React.createElement(f36Icons.FormatBoldIcon, null)
4197
+ });
4252
4198
  var styles$e = {
4253
4199
  bold: /*#__PURE__*/emotion.css({
4254
4200
  fontWeight: 600
@@ -4271,6 +4217,9 @@ var createBoldPlugin = function createBoldPlugin() {
4271
4217
  options: {
4272
4218
  hotkey: ['mod+b']
4273
4219
  },
4220
+ handlers: {
4221
+ onKeyDown: buildMarkEventHandler(Contentful.MARKS.BOLD)
4222
+ },
4274
4223
  deserializeHtml: {
4275
4224
  rules: [{
4276
4225
  validNodeName: ['STRONG', 'B']
@@ -4288,26 +4237,11 @@ var createBoldPlugin = function createBoldPlugin() {
4288
4237
  });
4289
4238
  };
4290
4239
 
4291
- function ToolbarCodeButton(props) {
4292
- var editor = useContentfulEditor();
4293
-
4294
- function handleClick() {
4295
- if (!(editor != null && editor.selection)) return;
4296
- plateCore.toggleMark(editor, {
4297
- key: Contentful.MARKS.CODE
4298
- });
4299
- focus(editor);
4300
- }
4301
-
4302
- if (!editor) return null;
4303
- return /*#__PURE__*/React.createElement(ToolbarButton, {
4304
- title: "Code",
4305
- testId: "code-toolbar-button",
4306
- onClick: handleClick,
4307
- isActive: plateCore.isMarkActive(editor, Contentful.MARKS.CODE),
4308
- isDisabled: props.isDisabled
4309
- }, /*#__PURE__*/React.createElement(f36Icons.CodeIcon, null));
4310
- }
4240
+ var ToolbarCodeButton = /*#__PURE__*/createMarkToolbarButton({
4241
+ title: 'Code',
4242
+ mark: Contentful.MARKS.CODE,
4243
+ icon: /*#__PURE__*/React.createElement(f36Icons.CodeIcon, null)
4244
+ });
4311
4245
  var styles$f = {
4312
4246
  code: /*#__PURE__*/emotion.css({
4313
4247
  fontFamily: 'monospace',
@@ -4326,6 +4260,9 @@ var createCodePlugin = function createCodePlugin() {
4326
4260
  options: {
4327
4261
  hotkey: ['mod+/']
4328
4262
  },
4263
+ handlers: {
4264
+ onKeyDown: buildMarkEventHandler(Contentful.MARKS.CODE)
4265
+ },
4329
4266
  deserializeHtml: {
4330
4267
  rules: [{
4331
4268
  validNodeName: ['CODE', 'PRE']
@@ -4338,26 +4275,11 @@ var createCodePlugin = function createCodePlugin() {
4338
4275
  });
4339
4276
  };
4340
4277
 
4341
- function ToolbarItalicButton(props) {
4342
- var editor = useContentfulEditor();
4343
-
4344
- function handleClick() {
4345
- if (!(editor != null && editor.selection)) return;
4346
- plateCore.toggleMark(editor, {
4347
- key: Contentful.MARKS.ITALIC
4348
- });
4349
- focus(editor);
4350
- }
4351
-
4352
- if (!editor) return null;
4353
- return /*#__PURE__*/React.createElement(ToolbarButton, {
4354
- title: "Italic",
4355
- testId: "italic-toolbar-button",
4356
- onClick: handleClick,
4357
- isActive: plateCore.isMarkActive(editor, Contentful.MARKS.ITALIC),
4358
- isDisabled: props.isDisabled
4359
- }, /*#__PURE__*/React.createElement(f36Icons.FormatItalicIcon, null));
4360
- }
4278
+ var ToolbarItalicButton = /*#__PURE__*/createMarkToolbarButton({
4279
+ title: 'Italic',
4280
+ mark: Contentful.MARKS.ITALIC,
4281
+ icon: /*#__PURE__*/React.createElement(f36Icons.FormatItalicIcon, null)
4282
+ });
4361
4283
  var styles$g = {
4362
4284
  italic: /*#__PURE__*/emotion.css({
4363
4285
  fontStyle: 'italic'
@@ -4375,6 +4297,9 @@ var createItalicPlugin = function createItalicPlugin() {
4375
4297
  options: {
4376
4298
  hotkey: ['mod+i']
4377
4299
  },
4300
+ handlers: {
4301
+ onKeyDown: buildMarkEventHandler(Contentful.MARKS.ITALIC)
4302
+ },
4378
4303
  deserializeHtml: {
4379
4304
  rules: [{
4380
4305
  validNodeName: ['I', 'EM']
@@ -4392,26 +4317,11 @@ var createItalicPlugin = function createItalicPlugin() {
4392
4317
  });
4393
4318
  };
4394
4319
 
4395
- function ToolbarUnderlineButton(props) {
4396
- var editor = useContentfulEditor();
4397
-
4398
- function handleClick() {
4399
- if (!(editor != null && editor.selection)) return;
4400
- plateCore.toggleMark(editor, {
4401
- key: Contentful.MARKS.UNDERLINE
4402
- });
4403
- focus(editor);
4404
- }
4405
-
4406
- if (!editor) return null;
4407
- return /*#__PURE__*/React.createElement(ToolbarButton, {
4408
- title: "Underline",
4409
- testId: "underline-toolbar-button",
4410
- onClick: handleClick,
4411
- isActive: plateCore.isMarkActive(editor, Contentful.MARKS.UNDERLINE),
4412
- isDisabled: props.isDisabled
4413
- }, /*#__PURE__*/React.createElement(f36Icons.FormatUnderlinedIcon, null));
4414
- }
4320
+ var ToolbarUnderlineButton = /*#__PURE__*/createMarkToolbarButton({
4321
+ title: 'Underline',
4322
+ mark: Contentful.MARKS.UNDERLINE,
4323
+ icon: /*#__PURE__*/React.createElement(f36Icons.FormatUnderlinedIcon, null)
4324
+ });
4415
4325
  function Underline(props) {
4416
4326
  return /*#__PURE__*/React.createElement("u", Object.assign({}, props.attributes), props.children);
4417
4327
  }
@@ -4422,6 +4332,9 @@ var createUnderlinePlugin = function createUnderlinePlugin() {
4422
4332
  options: {
4423
4333
  hotkey: ['mod+u']
4424
4334
  },
4335
+ handlers: {
4336
+ onKeyDown: buildMarkEventHandler(Contentful.MARKS.UNDERLINE)
4337
+ },
4425
4338
  deserializeHtml: {
4426
4339
  rules: [{
4427
4340
  validNodeName: ['U']
@@ -4644,6 +4557,7 @@ var withNormalizer = function withNormalizer(editor) {
4644
4557
  var createNormalizerPlugin = function createNormalizerPlugin() {
4645
4558
  return {
4646
4559
  key: 'NormalizerPlugin',
4560
+ // @ts-expect-error
4647
4561
  withOverrides: withNormalizer
4648
4562
  };
4649
4563
  };
@@ -4821,9 +4735,12 @@ function Quote(props) {
4821
4735
  }), props.children);
4822
4736
  }
4823
4737
 
4824
- function toggleQuote(editor) {
4738
+ function toggleQuote(editor, logAction) {
4825
4739
  if (!editor.selection) return;
4826
4740
  var isActive = isBlockSelected(editor, Contentful.BLOCKS.QUOTE);
4741
+ logAction(isActive ? 'remove' : 'insert', {
4742
+ nodeType: Contentful.BLOCKS.QUOTE
4743
+ });
4827
4744
  slate.Editor.withoutNormalizing(editor, function () {
4828
4745
  if (!editor.selection) return;
4829
4746
  slate.Transforms.unwrapNodes(editor, {
@@ -4855,7 +4772,7 @@ var onKeyDownToggleQuote = function onKeyDownToggleQuote(editor, plugin) {
4855
4772
 
4856
4773
  if (hotkey && isHotkey(hotkey, event)) {
4857
4774
  event.preventDefault();
4858
- toggleQuote(editor);
4775
+ toggleQuote(editor, editor.tracking.onShortcutAction);
4859
4776
  }
4860
4777
  };
4861
4778
  };
@@ -4882,7 +4799,54 @@ function createQuotePlugin() {
4882
4799
  normalizer: [{
4883
4800
  validChildren: Contentful.CONTAINERS[Contentful.BLOCKS.QUOTE],
4884
4801
  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)
4885
- }]
4802
+ }],
4803
+ withOverrides: function withOverrides(editor) {
4804
+ var insertFragment = editor.insertFragment;
4805
+
4806
+ editor.insertFragment = function (fragment) {
4807
+ var startingNode = fragment.length && fragment[0];
4808
+ var startsWithBlockquote = slate.Element.isElement(startingNode) && startingNode.type === Contentful.BLOCKS.QUOTE;
4809
+ var containerEntry = plateCore.getAbove(editor, {
4810
+ match: {
4811
+ type: Contentful.TEXT_CONTAINERS
4812
+ }
4813
+ });
4814
+ var containerIsNotEmpty = containerEntry && slate.Node.string(containerEntry[0]) !== '';
4815
+
4816
+ if (startsWithBlockquote && containerIsNotEmpty) {
4817
+ var selection = editor.selection;
4818
+
4819
+ var isContentSelected = function isContentSelected(selection) {
4820
+ return !!selection && slate.Point.compare(selection.anchor, selection.focus) !== 0;
4821
+ }; // if something is selected (highlighted) we replace the selection
4822
+
4823
+
4824
+ if (isContentSelected(selection)) {
4825
+ slate.Transforms["delete"](editor, {
4826
+ at: selection
4827
+ });
4828
+ } // get the cursor entry again, it may be different after deletion
4829
+
4830
+
4831
+ var _containerEntry = plateCore.getAbove(editor, {
4832
+ match: {
4833
+ type: Contentful.TEXT_CONTAINERS
4834
+ }
4835
+ });
4836
+
4837
+ var _containerIsNotEmpty = _containerEntry && slate.Node.string(_containerEntry[0]) !== '';
4838
+
4839
+ if (_containerIsNotEmpty) {
4840
+ slate.Transforms.insertNodes(editor, fragment);
4841
+ return;
4842
+ }
4843
+ }
4844
+
4845
+ insertFragment(fragment);
4846
+ };
4847
+
4848
+ return editor;
4849
+ }
4886
4850
  };
4887
4851
  }
4888
4852
 
@@ -4891,7 +4855,7 @@ function ToolbarQuoteButton(props) {
4891
4855
 
4892
4856
  function handleOnClick() {
4893
4857
  if (!editor) return;
4894
- toggleQuote(editor);
4858
+ toggleQuote(editor, editor.tracking.onToolbarAction);
4895
4859
  focus(editor);
4896
4860
  }
4897
4861
 
@@ -4940,8 +4904,7 @@ function hasHeadersOutsideFirstRow(nodes) {
4940
4904
  });
4941
4905
  }
4942
4906
 
4943
- function addTableTrackingEvents(editor, _ref6) {
4944
- var onViewportAction = _ref6.onViewportAction;
4907
+ function addTableTrackingEvents(editor) {
4945
4908
  var insertData = editor.insertData;
4946
4909
 
4947
4910
  editor.insertData = function (data) {
@@ -4955,7 +4918,7 @@ function addTableTrackingEvents(editor, _ref6) {
4955
4918
  if (hasTables(markupBefore)) return;
4956
4919
 
4957
4920
  if (hasTables(markupAfter)) {
4958
- onViewportAction('paste', {
4921
+ editor.tracking.onViewportAction('paste', {
4959
4922
  tablePasted: true,
4960
4923
  hasHeadersOutsideFirstRow: hasHeadersOutsideFirstRow(markupAfter)
4961
4924
  });
@@ -4967,29 +4930,6 @@ function addTableTrackingEvents(editor, _ref6) {
4967
4930
  };
4968
4931
  }
4969
4932
 
4970
- function useTracking(_ref) {
4971
- var onAction = _ref.onAction;
4972
- var trackingMemo = React.useMemo(function () {
4973
- return {
4974
- onViewportAction: function onViewportAction(actionName, data) {
4975
- if (data === void 0) {
4976
- data = {};
4977
- }
4978
-
4979
- return onAction(actionName, _extends({
4980
- origin: 'viewport-interaction'
4981
- }, data));
4982
- }
4983
- };
4984
- }, [] // eslint-disable-line
4985
- );
4986
- return trackingMemo;
4987
- }
4988
-
4989
- var _constate$2 = /*#__PURE__*/constate(useTracking),
4990
- TrackingProvider = _constate$2[0],
4991
- useTrackingContext = _constate$2[1];
4992
-
4993
4933
  var addRow = function addRow(editor, getNextRowPath) {
4994
4934
  if (plateCore.someNode(editor, {
4995
4935
  match: {
@@ -5235,9 +5175,6 @@ var TableActions = function TableActions() {
5235
5175
  var editor = useContentfulEditor();
5236
5176
  var isDisabled = Slate.useReadOnly();
5237
5177
 
5238
- var _useTrackingContext = useTrackingContext(),
5239
- onViewportAction = _useTrackingContext.onViewportAction;
5240
-
5241
5178
  var _React$useState = React__default.useState(false),
5242
5179
  isOpen = _React$useState[0],
5243
5180
  setOpen = _React$useState[1];
@@ -5287,11 +5224,11 @@ var TableActions = function TableActions() {
5287
5224
  }); // Tracking
5288
5225
 
5289
5226
  var actionName = type + "Table" + (element === 'Table' ? '' : element);
5290
- onViewportAction(actionName, {
5227
+ editor.tracking.onViewportAction(actionName, {
5291
5228
  tableSize: tableSize
5292
5229
  });
5293
5230
  };
5294
- }, [editor, isHeaderEnabled, close, onViewportAction]);
5231
+ }, [editor, isHeaderEnabled, close]);
5295
5232
 
5296
5233
  if (isDisabled) {
5297
5234
  return null;
@@ -5382,7 +5319,7 @@ var createTableOnKeyDown = function createTableOnKeyDown(editor, plugin) {
5382
5319
  };
5383
5320
  };
5384
5321
 
5385
- var createTablePlugin = function createTablePlugin(tracking) {
5322
+ var createTablePlugin = function createTablePlugin() {
5386
5323
  var _overrideByKey;
5387
5324
 
5388
5325
  return plateTable.createTablePlugin({
@@ -5391,7 +5328,7 @@ var createTablePlugin = function createTablePlugin(tracking) {
5391
5328
  onKeyDown: createTableOnKeyDown
5392
5329
  },
5393
5330
  withOverrides: function withOverrides(editor) {
5394
- addTableTrackingEvents(editor, tracking);
5331
+ addTableTrackingEvents(editor);
5395
5332
  var insertFragment = editor.insertFragment;
5396
5333
 
5397
5334
  editor.insertFragment = function (fragments) {
@@ -5491,10 +5428,6 @@ var createTablePlugin = function createTablePlugin(tracking) {
5491
5428
 
5492
5429
  function ToolbarTableButton(props) {
5493
5430
  var editor = useContentfulEditor();
5494
-
5495
- var _useTrackingContext = useTrackingContext(),
5496
- onViewportAction = _useTrackingContext.onViewportAction;
5497
-
5498
5431
  var isActive = editor && isTableActive(editor);
5499
5432
 
5500
5433
  function handleClick() {
@@ -5515,7 +5448,7 @@ function ToolbarTableButton(props) {
5515
5448
  return _context.abrupt("return");
5516
5449
 
5517
5450
  case 2:
5518
- onViewportAction('insertTable');
5451
+ editor.tracking.onToolbarAction('insertTable');
5519
5452
  insertTableAndFocusFirstCell(editor);
5520
5453
  focus(editor);
5521
5454
 
@@ -5620,35 +5553,199 @@ function deleteEmptyParagraph(unit, editor, deleteFunction) {
5620
5553
  }
5621
5554
  }
5622
5555
 
5623
- var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
5624
- return plateTrailingBlock.createTrailingBlockPlugin({
5625
- options: {
5626
- type: Contentful.BLOCKS.PARAGRAPH,
5627
- level: 0
5556
+ var _extends2, _extends4, _inlines;
5557
+ var inlines = /*#__PURE__*/Object.values(Contentful.INLINES).map(function (type) {
5558
+ return {
5559
+ type: type
5560
+ };
5561
+ });
5562
+ var schema = {
5563
+ document: {
5564
+ nodes: [{
5565
+ types: /*#__PURE__*/Contentful.TOP_LEVEL_BLOCKS.map(function (type) {
5566
+ return {
5567
+ type: type
5568
+ };
5569
+ })
5570
+ }]
5571
+ },
5572
+ blocks: /*#__PURE__*/_extends((_extends2 = {}, _extends2[Contentful.BLOCKS.PARAGRAPH] = {
5573
+ nodes: [{
5574
+ match: /*#__PURE__*/[].concat(inlines, [{
5575
+ object: 'text'
5576
+ }])
5577
+ }]
5578
+ }, _extends2[Contentful.BLOCKS.HEADING_1] = {
5579
+ nodes: [{
5580
+ match: /*#__PURE__*/[].concat(inlines, [{
5581
+ object: 'text'
5582
+ }])
5583
+ }]
5584
+ }, _extends2[Contentful.BLOCKS.HEADING_2] = {
5585
+ nodes: [{
5586
+ match: /*#__PURE__*/[].concat(inlines, [{
5587
+ object: 'text'
5588
+ }])
5589
+ }]
5590
+ }, _extends2[Contentful.BLOCKS.HEADING_3] = {
5591
+ nodes: [{
5592
+ match: /*#__PURE__*/[].concat(inlines, [{
5593
+ object: 'text'
5594
+ }])
5595
+ }]
5596
+ }, _extends2[Contentful.BLOCKS.HEADING_4] = {
5597
+ nodes: [{
5598
+ match: /*#__PURE__*/[].concat(inlines, [{
5599
+ object: 'text'
5600
+ }])
5601
+ }]
5602
+ }, _extends2[Contentful.BLOCKS.HEADING_5] = {
5603
+ nodes: [{
5604
+ match: /*#__PURE__*/[].concat(inlines, [{
5605
+ object: 'text'
5606
+ }])
5607
+ }]
5608
+ }, _extends2[Contentful.BLOCKS.HEADING_6] = {
5609
+ nodes: [{
5610
+ match: /*#__PURE__*/[].concat(inlines, [{
5611
+ object: 'text'
5612
+ }])
5613
+ }]
5614
+ }, _extends2), /*#__PURE__*/Contentful.VOID_BLOCKS.reduce(function (blocks, nodeType) {
5615
+ var _extends3;
5616
+
5617
+ return _extends({}, blocks, (_extends3 = {}, _extends3[nodeType] = {
5618
+ isVoid: true
5619
+ }, _extends3));
5620
+ }, {}), (_extends4 = {}, _extends4[Contentful.BLOCKS.QUOTE] = {
5621
+ nodes: [{
5622
+ match: [/*#__PURE__*/Contentful.CONTAINERS[Contentful.BLOCKS.QUOTE].map(function (type) {
5623
+ return {
5624
+ type: type
5625
+ };
5626
+ })],
5627
+ min: 1
5628
+ }],
5629
+ normalize: function normalize(editor, error) {
5630
+ if (error.code === 'child_type_invalid') {
5631
+ return editor.unwrapBlockByKey(error.node.key, Contentful.BLOCKS.QUOTE);
5632
+ }
5628
5633
  }
5634
+ }, _extends4)),
5635
+ inlines: (_inlines = {}, _inlines[Contentful.INLINES.HYPERLINK] = {
5636
+ nodes: [{
5637
+ match: [{
5638
+ object: 'text'
5639
+ }]
5640
+ }]
5641
+ }, _inlines[Contentful.INLINES.ENTRY_HYPERLINK] = {
5642
+ nodes: [{
5643
+ match: [{
5644
+ object: 'text'
5645
+ }]
5646
+ }]
5647
+ }, _inlines[Contentful.INLINES.ASSET_HYPERLINK] = {
5648
+ nodes: [{
5649
+ match: [{
5650
+ object: 'text'
5651
+ }]
5652
+ }]
5653
+ }, _inlines[Contentful.INLINES.EMBEDDED_ENTRY] = {
5654
+ isVoid: true
5655
+ }, _inlines)
5656
+ };
5657
+
5658
+ function getCharacterCount(editor) {
5659
+ var document = contentfulSlateJSAdapter.toContentfulDocument({
5660
+ document: editor.children,
5661
+ schema: schema
5629
5662
  });
5663
+ return richTextPlainTextRenderer.documentToPlainTextString(document).length;
5664
+ }
5665
+
5666
+ var actionOrigin = {
5667
+ TOOLBAR: 'toolbar-icon',
5668
+ SHORTCUT: 'shortcut',
5669
+ VIEWPORT: 'viewport-interaction',
5670
+ COMMAND_PALETTE: 'command-palette'
5630
5671
  };
5672
+ var createTrackingPlugin = function createTrackingPlugin(onAction) {
5673
+ var trackingActions = {
5674
+ onViewportAction: function onViewportAction(actionName, data) {
5675
+ if (data === void 0) {
5676
+ data = {};
5677
+ }
5631
5678
 
5632
- /**
5633
- * Re-creates a void node with valid children.
5634
- */
5679
+ return onAction(actionName, _extends({
5680
+ origin: actionOrigin.VIEWPORT
5681
+ }, data));
5682
+ },
5683
+ onShortcutAction: function onShortcutAction(actionName, data) {
5684
+ if (data === void 0) {
5685
+ data = {};
5686
+ }
5635
5687
 
5636
- var transformVoid = function transformVoid(editor, _ref) {
5637
- var node = _ref[0],
5638
- path = _ref[1];
5688
+ return onAction(actionName, _extends({
5689
+ origin: actionOrigin.SHORTCUT
5690
+ }, data));
5691
+ },
5692
+ onToolbarAction: function onToolbarAction(actionName, data) {
5693
+ if (data === void 0) {
5694
+ data = {};
5695
+ }
5639
5696
 
5640
- var validVoid = _extends({}, node, {
5641
- children: [{
5642
- text: ''
5643
- }]
5644
- }); // A workaround because Slate doesn't allow adjusting void nodes children
5697
+ return onAction(actionName, _extends({
5698
+ origin: actionOrigin.TOOLBAR
5699
+ }, data));
5700
+ },
5701
+ onCommandPaletteAction: function onCommandPaletteAction(actionName, data) {
5702
+ if (data === void 0) {
5703
+ data = {};
5704
+ }
5645
5705
 
5706
+ return onAction(actionName, _extends({
5707
+ origin: actionOrigin.COMMAND_PALETTE
5708
+ }, data));
5709
+ }
5710
+ };
5711
+ return {
5712
+ key: 'TrackingPlugin',
5713
+ withOverrides: function withOverrides(editor) {
5714
+ var insertData = editor.insertData;
5715
+ editor.tracking = trackingActions;
5716
+
5717
+ editor.insertData = function (data) {
5718
+ var isCopyAndPaste = data.types.length !== 0;
5719
+
5720
+ if (isCopyAndPaste) {
5721
+ var _window$getSelection;
5722
+
5723
+ var characterCountSelection = (_window$getSelection = window.getSelection()) == null ? void 0 : _window$getSelection.toString().length;
5724
+ var characterCountBefore = getCharacterCount(editor);
5725
+ setTimeout(function () {
5726
+ var characterCountAfter = getCharacterCount(editor);
5727
+ trackingActions.onShortcutAction('paste', {
5728
+ characterCountAfter: characterCountAfter,
5729
+ characterCountBefore: characterCountBefore,
5730
+ characterCountSelection: characterCountSelection
5731
+ });
5732
+ });
5733
+ }
5646
5734
 
5647
- slate.Transforms.removeNodes(editor, {
5648
- at: path
5649
- });
5650
- slate.Transforms.insertNodes(editor, [validVoid], {
5651
- at: path
5735
+ insertData(data);
5736
+ };
5737
+
5738
+ return editor;
5739
+ }
5740
+ };
5741
+ };
5742
+
5743
+ var createTrailingParagraphPlugin = function createTrailingParagraphPlugin() {
5744
+ return plateTrailingBlock.createTrailingBlockPlugin({
5745
+ options: {
5746
+ type: Contentful.BLOCKS.PARAGRAPH,
5747
+ level: 0
5748
+ }
5652
5749
  });
5653
5750
  };
5654
5751
 
@@ -5680,34 +5777,17 @@ var createVoidsPlugin = function createVoidsPlugin() {
5680
5777
  return !(isRootLevel(path) && plateCore.isFirstChild(path)) && !!node.isVoid;
5681
5778
  }
5682
5779
  }
5683
- }],
5684
- normalizer: [{
5685
- match: {
5686
- isVoid: true
5687
- },
5688
- validNode: function validNode(editor, _ref3) {
5689
- var path = _ref3[1];
5690
- var children = Array.from(slate.Node.children(editor, path));
5691
-
5692
- if (children.length !== 1) {
5693
- return false;
5694
- }
5695
-
5696
- var _children$ = children[0],
5697
- textNode = _children$[0];
5698
- return slate.Text.isText(textNode) && textNode.text === '';
5699
- },
5700
- transform: transformVoid
5701
5780
  }]
5702
5781
  };
5703
5782
  };
5704
5783
 
5705
- var getPlugins = function getPlugins(sdk, tracking) {
5784
+ var getPlugins = function getPlugins(sdk, onAction) {
5706
5785
  return [// AST must come after the HTML deserializer
5707
- plateCore.createDeserializeHtmlPlugin(), plateCore.createDeserializeAstPlugin(), plateSerializerDocx.createDeserializeDocxPlugin(), // Global shortcuts
5786
+ plateCore.createDeserializeHtmlPlugin(), plateCore.createDeserializeAstPlugin(), plateSerializerDocx.createDeserializeDocxPlugin(), // Tracking - This should come first so all plugins below will have access to `editor.tracking`
5787
+ createTrackingPlugin(onAction), // Global / Global shortcuts
5708
5788
  createDragAndDropPlugin(), // Block Elements
5709
- createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk, tracking), createEmbeddedAssetBlockPlugin(sdk, tracking), // Inline elements
5710
- createHyperlinkPlugin(sdk, tracking), createEmbeddedEntityInlinePlugin(sdk, tracking), // Marks
5789
+ createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
5790
+ createHyperlinkPlugin(sdk), createEmbeddedEntityInlinePlugin(sdk), // Marks
5711
5791
  createMarksPlugin(), // Other
5712
5792
  createTrailingParagraphPlugin(), createTextPlugin(), createVoidsPlugin(), createSelectOnBackspacePlugin(), // Pasting content from other sources
5713
5793
  createPasteHTMLPlugin(), // These plugins drive their configurations from the list of plugins
@@ -5929,10 +6009,10 @@ var Toolbar = function Toolbar(_ref) {
5929
6009
  isDisabled: isDisabled
5930
6010
  })), validationInfo.isAnyBlockFormattingEnabled && /*#__PURE__*/React__default.createElement("span", {
5931
6011
  className: styles$k.divider
5932
- }), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.QUOTE) && /*#__PURE__*/React__default.createElement(ToolbarQuoteButton, {
5933
- isDisabled: isDisabled || !canInsertBlocks
5934
6012
  }), /*#__PURE__*/React__default.createElement(ToolbarListButton, {
5935
6013
  isDisabled: isDisabled || !canInsertBlocks
6014
+ }), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.QUOTE) && /*#__PURE__*/React__default.createElement(ToolbarQuoteButton, {
6015
+ isDisabled: isDisabled || !canInsertBlocks
5936
6016
  }), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.HR) && /*#__PURE__*/React__default.createElement(ToolbarHrButton, {
5937
6017
  isDisabled: isDisabled || !canInsertBlocks
5938
6018
  }), isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.TABLE) && /*#__PURE__*/React__default.createElement(ToolbarTableButton, {
@@ -5975,62 +6055,113 @@ var StickyToolbarWrapper = function StickyToolbarWrapper(_ref) {
5975
6055
  }, children);
5976
6056
  };
5977
6057
 
6058
+ /**
6059
+ * For legacy reasons, a document may not have any content at all
6060
+ * e.g:
6061
+ *
6062
+ * {nodeType: document, data: {}, content: []}
6063
+ *
6064
+ * Rendering such document will break the Slate editor
6065
+ */
6066
+
6067
+ var hasContent = function hasContent(doc) {
6068
+ if (!doc) {
6069
+ return false;
6070
+ }
6071
+
6072
+ return doc.content.length > 0;
6073
+ };
6074
+
6075
+ var useNormalizedSlateValue = function useNormalizedSlateValue(_ref) {
6076
+ var id = _ref.id,
6077
+ incomingDoc = _ref.incomingDoc,
6078
+ plugins = _ref.plugins;
6079
+ return React.useMemo(function () {
6080
+ var editor = plateCore.createPlateEditor({
6081
+ id: id,
6082
+ plugins: plugins,
6083
+ disableCorePlugins: disableCorePlugins
6084
+ });
6085
+ var doc = contentfulSlateJSAdapter.toSlatejsDocument({
6086
+ document: hasContent(incomingDoc) ? incomingDoc : Contentful.EMPTY_DOCUMENT,
6087
+ schema: schema
6088
+ }); // Sets editor value & kicks normalization
6089
+
6090
+ slate.Transforms.insertNodes(editor, doc); // TODO: return the editor itself to avoid recompiling & initializing all
6091
+ // of the plugins again. It's currently not possible due to a bug in Plate
6092
+ // with initialValues
6093
+ // See: https://slate-js.slack.com/archives/C013QHXSCG1/p1645112799942819
6094
+
6095
+ return editor.children;
6096
+ }, [id, plugins, incomingDoc]);
6097
+ };
6098
+
6099
+ /**
6100
+ * Returns whether a given operation is relevant enough to trigger a save.
6101
+ */
6102
+
6103
+ var isRelevantOperation = function isRelevantOperation(op) {
6104
+ if (op.type === 'set_selection') {
6105
+ return false;
6106
+ }
6107
+
6108
+ return true;
6109
+ };
6110
+
6111
+ var useOnValueChanged = function useOnValueChanged(_ref) {
6112
+ var editor = _ref.editor,
6113
+ handler = _ref.handler;
6114
+ var onChange = React.useMemo(function () {
6115
+ return debounce(function (document) {
6116
+ handler == null ? void 0 : handler(contentfulSlateJSAdapter.toContentfulDocument({
6117
+ document: document,
6118
+ schema: schema
6119
+ }));
6120
+ }, 500);
6121
+ }, [handler]);
6122
+ return React.useCallback(function (value) {
6123
+ var operations = editor.operations.filter(isRelevantOperation);
6124
+
6125
+ if (operations.length > 0) {
6126
+ onChange(value);
6127
+ }
6128
+ }, [editor, onChange]);
6129
+ };
6130
+
5978
6131
  var _excluded = ["sdk", "isInitiallyDisabled", "onAction"];
5979
6132
  var ConnectedRichTextEditor = function ConnectedRichTextEditor(props) {
5980
- var tracking = useTrackingContext();
6133
+ var id = useContentfulEditorId();
5981
6134
  var editor = useContentfulEditor();
5982
-
5983
- var _useState = React.useState([]),
5984
- value = _useState[0],
5985
- setValue = _useState[1];
5986
-
6135
+ var plugins = React__default.useMemo(function () {
6136
+ var _props$onAction;
6137
+
6138
+ return getPlugins(props.sdk, (_props$onAction = props.onAction) != null ? _props$onAction : noop);
6139
+ }, [props.sdk, props.onAction]);
6140
+ var initialValue = useNormalizedSlateValue({
6141
+ id: id,
6142
+ incomingDoc: props.value,
6143
+ plugins: plugins
6144
+ });
6145
+ var onValueChanged = useOnValueChanged({
6146
+ editor: editor,
6147
+ handler: props.onChange
6148
+ });
5987
6149
  var classNames = emotion.cx(styles$j.editor, props.minHeight !== undefined ? emotion.css({
5988
6150
  minHeight: props.minHeight
5989
6151
  }) : undefined, props.isDisabled ? styles$j.disabled : styles$j.enabled, props.isToolbarHidden && styles$j.hiddenToolbar);
5990
- var plugins = React__default.useMemo(function () {
5991
- return getPlugins(props.sdk, tracking);
5992
- }, [props.sdk, tracking]);
5993
- React__default.useEffect(function () {
5994
- if (!editor) {
5995
- return;
5996
- }
5997
-
5998
- var docFromAdapter = contentfulSlatejsAdapter.toSlatejsDocument({
5999
- document: props.value || Contentful.EMPTY_DOCUMENT,
6000
- schema: schema
6001
- });
6002
- var doc = sanitizeIncomingSlateDoc(docFromAdapter); // Slate throws an error if the value on the initial render is invalid
6003
- // so we directly set the value on the editor in order
6004
- // to be able to trigger normalization on the initial value before rendering
6005
- // TODO: use https://plate.udecode.io/docs/Plate#normalizeinitialvalue when working
6006
-
6007
- editor.children = doc;
6008
- slate.Editor.normalize(editor, {
6009
- force: true
6010
- }); // We set the value so that the rendering can take over from here
6011
-
6012
- setValue(editor.children);
6013
- }, [props.value, editor]);
6014
6152
  return /*#__PURE__*/React__default.createElement("div", {
6015
6153
  className: styles$j.root,
6016
6154
  "data-test-id": "rich-text-editor"
6017
6155
  }, /*#__PURE__*/React__default.createElement(plateCore.Plate, {
6018
- id: getContentfulEditorId(props.sdk),
6019
- value: value,
6156
+ id: id,
6157
+ initialValue: initialValue,
6020
6158
  plugins: plugins,
6021
6159
  disableCorePlugins: disableCorePlugins,
6022
6160
  editableProps: {
6023
6161
  className: classNames,
6024
6162
  readOnly: props.isDisabled
6025
6163
  },
6026
- onChange: function onChange(slateDoc) {
6027
- setValue(slateDoc);
6028
- var contentfulDoc = contentfulSlatejsAdapter.toContentfulDocument({
6029
- document: slateDoc,
6030
- schema: schema
6031
- });
6032
- props.onChange == null ? void 0 : props.onChange(contentfulDoc);
6033
- }
6164
+ onChange: onValueChanged
6034
6165
  }, !props.isToolbarHidden && /*#__PURE__*/React__default.createElement(StickyToolbarWrapper, {
6035
6166
  isDisabled: props.isDisabled
6036
6167
  }, /*#__PURE__*/React__default.createElement(Toolbar, {
@@ -6047,12 +6178,11 @@ var RichTextEditor = function RichTextEditor(props) {
6047
6178
  var isEmptyValue = React.useCallback(function (value) {
6048
6179
  return !value || deepEquals(value, Contentful.EMPTY_DOCUMENT);
6049
6180
  }, []);
6181
+ var editorId = getContentfulEditorId(sdk);
6050
6182
  return /*#__PURE__*/React__default.createElement(fieldEditorReference.EntityProvider, {
6051
6183
  sdk: sdk
6052
6184
  }, /*#__PURE__*/React__default.createElement(SdkProvider, {
6053
6185
  sdk: sdk
6054
- }, /*#__PURE__*/React__default.createElement(TrackingProvider, {
6055
- onAction: onAction || noop
6056
6186
  }, /*#__PURE__*/React__default.createElement(fieldEditorShared.FieldConnector, {
6057
6187
  throttle: 0,
6058
6188
  field: sdk.field,
@@ -6064,17 +6194,17 @@ var RichTextEditor = function RichTextEditor(props) {
6064
6194
  disabled = _ref.disabled,
6065
6195
  setValue = _ref.setValue,
6066
6196
  externalReset = _ref.externalReset;
6067
- return /*#__PURE__*/React__default.createElement(ContentfulEditorProvider, {
6068
- sdk: sdk
6197
+ return /*#__PURE__*/React__default.createElement(ContentfulEditorIdProvider, {
6198
+ value: editorId
6069
6199
  }, /*#__PURE__*/React__default.createElement(ConnectedRichTextEditor, Object.assign({}, otherProps, {
6070
6200
  key: "rich-text-editor-" + externalReset,
6071
6201
  value: lastRemoteValue,
6072
6202
  sdk: sdk,
6073
- onAction: onAction || noop,
6203
+ onAction: onAction,
6074
6204
  isDisabled: disabled,
6075
6205
  onChange: setValue
6076
6206
  })));
6077
- }))));
6207
+ })));
6078
6208
  };
6079
6209
 
6080
6210
  var LINK_TYPES$1 = {