@contentful/field-editor-rich-text 2.1.3 → 2.3.0

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.
@@ -16,15 +16,17 @@ var noop = _interopDefault(require('lodash/noop'));
16
16
  var plateSerializerDocx = require('@udecode/plate-serializer-docx');
17
17
  var plateBreak = require('@udecode/plate-break');
18
18
  var plateResetNode = require('@udecode/plate-reset-node');
19
- var slate = require('slate');
20
- var Slate = require('slate-react');
19
+ var reactPopper = require('react-popper');
21
20
  var f36Components = require('@contentful/f36-components');
21
+ var f36Utils = require('@contentful/f36-utils');
22
22
  var constate = _interopDefault(require('constate'));
23
23
  var isHotkey = _interopDefault(require('is-hotkey'));
24
- var tokens = _interopDefault(require('@contentful/f36-tokens'));
24
+ var slate = require('slate');
25
+ var Slate = require('slate-react');
25
26
  var find = _interopDefault(require('lodash/find'));
26
27
  var flow = _interopDefault(require('lodash/flow'));
27
28
  var get = _interopDefault(require('lodash/get'));
29
+ var tokens = _interopDefault(require('@contentful/f36-tokens'));
28
30
  var f36Icons = require('@contentful/f36-icons');
29
31
  var plateList = require('@udecode/plate-list');
30
32
  var castArray = _interopDefault(require('lodash/castArray'));
@@ -341,6 +343,131 @@ var createResetNodePlugin = function createResetNodePlugin() {
341
343
  });
342
344
  };
343
345
 
346
+ /**
347
+ * Trim leading slash character if found. Bails otherwise.
348
+ *
349
+ * @example
350
+ * trimLeadingSlash("/my query") // --> "my query"
351
+ */
352
+ function trimLeadingSlash(text) {
353
+ if (!text.startsWith('/')) {
354
+ return text;
355
+ }
356
+
357
+ return text.slice(1);
358
+ }
359
+
360
+ function useSdk(_ref) {
361
+ var sdk = _ref.sdk;
362
+ var sdkMemo = React.useMemo(function () {
363
+ return sdk;
364
+ }, []); // eslint-disable-line -- TODO: explain this disable
365
+
366
+ return sdkMemo;
367
+ }
368
+
369
+ var _constate = /*#__PURE__*/constate(useSdk),
370
+ SdkProvider = _constate[0],
371
+ useSdkContext = _constate[1];
372
+
373
+ var useCommandList = function useCommandList(commandItems, container) {
374
+ var _React$useState = React.useState(function () {
375
+ // select the first item on initial render
376
+ if ('group' in commandItems[0]) {
377
+ return commandItems[0].commands[0].id;
378
+ }
379
+
380
+ return commandItems[0].id;
381
+ }),
382
+ selectedItem = _React$useState[0],
383
+ setSelectedItem = _React$useState[1];
384
+
385
+ var _React$useState2 = React.useState(commandItems.length > 0),
386
+ isOpen = _React$useState2[0],
387
+ setIsOpen = _React$useState2[1];
388
+
389
+ React.useEffect(function () {
390
+ if (!container.current) {
391
+ return;
392
+ }
393
+
394
+ var buttons = Array.from(container.current.querySelectorAll('button'));
395
+ var currBtn = buttons.find(function (btn) {
396
+ return btn.id === selectedItem;
397
+ });
398
+ var currIndex = currBtn ? buttons.indexOf(currBtn) : 0;
399
+ var shouldSelectFirstBtn = !currBtn && buttons.length;
400
+
401
+ if (shouldSelectFirstBtn) {
402
+ setSelectedItem(buttons[0].id);
403
+ buttons[0].scrollIntoView({
404
+ block: 'nearest',
405
+ inline: 'start'
406
+ });
407
+ }
408
+
409
+ function handleKeyDown(event) {
410
+ if (isHotkey('up', event)) {
411
+ event.preventDefault();
412
+
413
+ if (currIndex === 0) {
414
+ return;
415
+ }
416
+
417
+ setSelectedItem(buttons[currIndex - 1].id);
418
+ buttons[currIndex - 1].scrollIntoView({
419
+ block: 'nearest',
420
+ inline: 'start'
421
+ });
422
+ } else if (isHotkey('down', event)) {
423
+ event.preventDefault();
424
+
425
+ if (currIndex === buttons.length - 1) {
426
+ return;
427
+ }
428
+
429
+ setSelectedItem(buttons[currIndex + 1].id);
430
+ buttons[currIndex + 1].scrollIntoView({
431
+ block: 'nearest',
432
+ inline: 'start'
433
+ });
434
+ } else if (isHotkey('enter', event)) {
435
+ event.preventDefault();
436
+
437
+ if (currBtn) {
438
+ setSelectedItem('');
439
+ currBtn.click();
440
+ }
441
+ } //TODO: handle shift+enter, which must be detected using separate events
442
+
443
+ }
444
+
445
+ if (commandItems.length) {
446
+ window.addEventListener('keydown', handleKeyDown);
447
+ }
448
+
449
+ return function () {
450
+ return window.removeEventListener('keydown', handleKeyDown);
451
+ };
452
+ }, [commandItems, container, selectedItem]);
453
+ React.useEffect(function () {
454
+ var handleMousedown = function handleMousedown(event) {
455
+ if (container.current && !container.current.contains(event.target)) {
456
+ setIsOpen(false);
457
+ }
458
+ };
459
+
460
+ document.addEventListener('mousedown', handleMousedown);
461
+ return function () {
462
+ document.removeEventListener('mousedown', handleMousedown);
463
+ };
464
+ }, [container]);
465
+ return {
466
+ selectedItem: selectedItem,
467
+ isOpen: isOpen
468
+ };
469
+ };
470
+
344
471
  var IS_SAFARI = typeof navigator !== 'undefined' && /*#__PURE__*/ /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
345
472
  var IS_CHROME = /*#__PURE__*/ /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9.]+)(:?\s|$)/.test(navigator.userAgent);
346
473
 
@@ -545,129 +672,36 @@ function toggleElement(editor, options, editorOptions) {
545
672
  });
546
673
  }
547
674
 
548
- /**
549
- * Trim leading slash character if found. Bails otherwise.
550
- *
551
- * @example
552
- * trimLeadingSlash("/my query") // --> "my query"
553
- */
554
- function trimLeadingSlash(text) {
555
- if (!text.startsWith('/')) {
556
- return text;
557
- }
558
-
559
- return text.slice(1);
560
- }
561
-
562
- function useSdk(_ref) {
563
- var sdk = _ref.sdk;
564
- var sdkMemo = React.useMemo(function () {
565
- return sdk;
566
- }, []); // eslint-disable-line -- TODO: explain this disable
567
-
568
- return sdkMemo;
569
- }
570
-
571
- var _constate = /*#__PURE__*/constate(useSdk),
572
- SdkProvider = _constate[0],
573
- useSdkContext = _constate[1];
574
-
575
- var useCommandList = function useCommandList(commandItems, container) {
576
- var _React$useState = React.useState(function () {
577
- // select the first item on initial render
578
- if ('group' in commandItems[0]) {
579
- return commandItems[0].commands[0].id;
580
- }
581
-
582
- return commandItems[0].id;
583
- }),
584
- selectedItem = _React$useState[0],
585
- setSelectedItem = _React$useState[1];
586
-
587
- var _React$useState2 = React.useState(commandItems.length > 0),
588
- isOpen = _React$useState2[0],
589
- setIsOpen = _React$useState2[1];
590
-
591
- React.useEffect(function () {
592
- if (!(container != null && container.current)) {
593
- return;
594
- }
595
-
596
- var buttons = Array.from(container.current.querySelectorAll('button'));
597
- var currBtn = buttons.find(function (btn) {
598
- return btn.id === selectedItem;
599
- });
600
- var currIndex = currBtn ? buttons.indexOf(currBtn) : 0;
601
- var shouldSelectFirstBtn = !currBtn && buttons.length;
602
-
603
- if (shouldSelectFirstBtn) {
604
- setSelectedItem(buttons[0].id);
605
- buttons[0].scrollIntoView({
606
- block: 'nearest',
607
- inline: 'start'
608
- });
609
- }
610
-
611
- function handleKeyDown(event) {
612
- if (isHotkey('up', event)) {
613
- event.preventDefault();
614
-
615
- if (currIndex === 0) {
616
- return;
617
- }
618
-
619
- setSelectedItem(buttons[currIndex - 1].id);
620
- buttons[currIndex - 1].scrollIntoView({
621
- block: 'nearest',
622
- inline: 'start'
623
- });
624
- } else if (isHotkey('down', event)) {
625
- event.preventDefault();
626
-
627
- if (currIndex === buttons.length - 1) {
628
- return;
629
- }
630
-
631
- setSelectedItem(buttons[currIndex + 1].id);
632
- buttons[currIndex + 1].scrollIntoView({
633
- block: 'nearest',
634
- inline: 'start'
635
- });
636
- } else if (isHotkey('enter', event)) {
637
- event.preventDefault();
675
+ var VALIDATIONS = {
676
+ ENABLED_MARKS: 'enabledMarks',
677
+ ENABLED_NODE_TYPES: 'enabledNodeTypes'
678
+ };
679
+ var DEFAULT_ENABLED_NODE_TYPES = [Contentful.BLOCKS.DOCUMENT, Contentful.BLOCKS.PARAGRAPH, 'text'];
638
680
 
639
- if (currBtn) {
640
- setSelectedItem('');
641
- currBtn.click();
642
- }
643
- } //TODO: handle shift+enter, which must be detected using separate events
681
+ var getRichTextValidation = function getRichTextValidation(field, validationType) {
682
+ return flow(function (v) {
683
+ return find(v, validationType);
684
+ }, function (v) {
685
+ return get(v, validationType);
686
+ })(field.validations);
687
+ };
644
688
 
645
- }
689
+ var isFormattingOptionEnabled = function isFormattingOptionEnabled(field, validationType, nodeTypeOrMark) {
690
+ var enabledFormattings = getRichTextValidation(field, validationType); // TODO: In the future, validations will always be opt-in. In that case
691
+ // we don't need this step.
646
692
 
647
- if (commandItems.length) {
648
- window.addEventListener('keydown', handleKeyDown);
649
- }
693
+ if (enabledFormattings === undefined) {
694
+ return true;
695
+ }
650
696
 
651
- return function () {
652
- return window.removeEventListener('keydown', handleKeyDown);
653
- };
654
- }, [commandItems, container, selectedItem]);
655
- React.useEffect(function () {
656
- var handleClick = function handleClick(event) {
657
- if (container.current && !container.current.contains(event.target)) {
658
- setIsOpen(false);
659
- }
660
- };
697
+ return DEFAULT_ENABLED_NODE_TYPES.concat(enabledFormattings).includes(nodeTypeOrMark);
698
+ };
661
699
 
662
- document.addEventListener('click', handleClick);
663
- return function () {
664
- document.removeEventListener('click', handleClick);
665
- };
666
- }, [container]);
667
- return {
668
- selectedItem: selectedItem,
669
- isOpen: isOpen
670
- };
700
+ var isNodeTypeEnabled = function isNodeTypeEnabled(field, nodeType) {
701
+ return isFormattingOptionEnabled(field, VALIDATIONS.ENABLED_NODE_TYPES, nodeType);
702
+ };
703
+ var isMarkEnabled = function isMarkEnabled(field, mark) {
704
+ return isFormattingOptionEnabled(field, VALIDATIONS.ENABLED_MARKS, mark);
671
705
  };
672
706
 
673
707
  var COMMAND_PROMPT = 'command-prompt';
@@ -1579,36 +1613,125 @@ var removeQuery = function removeQuery(editor) {
1579
1613
 
1580
1614
  var useCommands = function useCommands(sdk, query, editor) {
1581
1615
  var contentTypes = sdk.space.getCachedContentTypes();
1616
+ var canInsertBlocks = !isNodeTypeSelected(editor, Contentful.BLOCKS.TABLE);
1617
+ var inlineAllowed = isNodeTypeEnabled(sdk.field, Contentful.INLINES.EMBEDDED_ENTRY);
1618
+ var entriesAllowed = isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.EMBEDDED_ENTRY) && canInsertBlocks;
1619
+ var assetsAllowed = isNodeTypeEnabled(sdk.field, Contentful.BLOCKS.EMBEDDED_ASSET) && canInsertBlocks;
1582
1620
 
1583
1621
  var _useState = React.useState(function () {
1584
- var contentTypeCommands = contentTypes.map(function (contentType) {
1622
+ var getEmbedEntry = function getEmbedEntry(contentType) {
1623
+ return {
1624
+ id: contentType.sys.id,
1625
+ label: "Embed " + contentType.name,
1626
+ callback: function callback() {
1627
+ fetchEntries(sdk, contentType, query).then(function (entries) {
1628
+ removeQuery(editor);
1629
+
1630
+ if (!entries.length) {
1631
+ setCommands([{
1632
+ id: 'no-results',
1633
+ label: 'No results'
1634
+ }]);
1635
+ } else {
1636
+ setCommands(entries.map(function (entry) {
1637
+ return {
1638
+ id: entry.id + "-" + entry.displayTitle.replace(/\W+/g, '-').toLowerCase(),
1639
+ label: entry.displayTitle,
1640
+ callback: function callback() {
1641
+ removeCommand(editor);
1642
+
1643
+ if (editor.selection) {
1644
+ var selection = editor.selection;
1645
+ editor.insertSoftBreak();
1646
+ insertBlock(editor, Contentful.BLOCKS.EMBEDDED_ENTRY, entry.entry);
1647
+ slate.Transforms.select(editor, selection);
1648
+ editor.tracking.onCommandPaletteAction('insert', {
1649
+ nodeType: Contentful.BLOCKS.EMBEDDED_ENTRY
1650
+ });
1651
+ }
1652
+ }
1653
+ };
1654
+ }));
1655
+ }
1656
+ });
1657
+ }
1658
+ };
1659
+ };
1660
+
1661
+ var getEmbedInline = function getEmbedInline(contentType) {
1662
+ return {
1663
+ id: contentType.sys.id + "-inline",
1664
+ label: "Embed " + contentType.name + " - Inline",
1665
+ callback: function callback() {
1666
+ fetchEntries(sdk, contentType, query).then(function (entries) {
1667
+ removeQuery(editor);
1668
+
1669
+ if (!entries.length) {
1670
+ setCommands([{
1671
+ id: 'no-results',
1672
+ label: 'No results'
1673
+ }]);
1674
+ } else {
1675
+ setCommands(entries.map(function (entry) {
1676
+ return {
1677
+ id: entry.id + "-" + entry.displayTitle.replace(/\W+/g, '-').toLowerCase(),
1678
+ label: entry.displayTitle,
1679
+ callback: function callback() {
1680
+ var inlineNode = createInlineEntryNode(entry.id);
1681
+ removeCommand(editor);
1682
+ slate.Transforms.insertNodes(editor, inlineNode);
1683
+ editor.insertText('');
1684
+ editor.tracking.onCommandPaletteAction('insert', {
1685
+ nodeType: Contentful.INLINES.EMBEDDED_ENTRY
1686
+ });
1687
+ }
1688
+ };
1689
+ }));
1690
+ }
1691
+ });
1692
+ }
1693
+ };
1694
+ };
1695
+
1696
+ var contentTypeCommands = entriesAllowed || inlineAllowed ? contentTypes.map(function (contentType) {
1585
1697
  return {
1586
1698
  group: contentType.name,
1699
+ commands: entriesAllowed && inlineAllowed ? [getEmbedEntry(contentType), getEmbedInline(contentType)] : entriesAllowed ? [getEmbedEntry(contentType)] : [getEmbedInline(contentType)]
1700
+ };
1701
+ }) : [];
1702
+
1703
+ if (assetsAllowed) {
1704
+ var assetCommand = {
1705
+ group: 'Assets',
1587
1706
  commands: [{
1588
- id: contentType.sys.id,
1589
- label: "Embed " + contentType.name,
1707
+ id: 'embed-asset',
1708
+ label: 'Embed Asset',
1590
1709
  callback: function callback() {
1591
- fetchEntries(sdk, contentType, query).then(function (entries) {
1710
+ fetchAssets(sdk, query).then(function (assets) {
1592
1711
  removeQuery(editor);
1593
1712
 
1594
- if (!entries.length) {
1713
+ if (!assets.length) {
1595
1714
  setCommands([{
1596
1715
  id: 'no-results',
1597
1716
  label: 'No results'
1598
1717
  }]);
1599
1718
  } else {
1600
- setCommands(entries.map(function (entry) {
1719
+ setCommands(assets.map(function (asset) {
1601
1720
  return {
1602
- id: entry.id + "-" + entry.displayTitle.replace(/\W+/g, '-').toLowerCase(),
1603
- label: entry.displayTitle,
1721
+ id: asset.id + "-" + asset.displayTitle.replace(/\W+/g, '-').toLowerCase(),
1722
+ label: asset.displayTitle,
1723
+ thumbnail: asset.thumbnail,
1604
1724
  callback: function callback() {
1605
1725
  removeCommand(editor);
1606
1726
 
1607
1727
  if (editor.selection) {
1608
1728
  var selection = editor.selection;
1609
1729
  editor.insertSoftBreak();
1610
- insertBlock(editor, Contentful.BLOCKS.EMBEDDED_ENTRY, entry.entry);
1730
+ insertBlock(editor, Contentful.BLOCKS.EMBEDDED_ASSET, asset.entity);
1611
1731
  slate.Transforms.select(editor, selection);
1732
+ editor.tracking.onCommandPaletteAction('insert', {
1733
+ nodeType: Contentful.BLOCKS.EMBEDDED_ASSET
1734
+ });
1612
1735
  }
1613
1736
  }
1614
1737
  };
@@ -1616,75 +1739,12 @@ var useCommands = function useCommands(sdk, query, editor) {
1616
1739
  }
1617
1740
  });
1618
1741
  }
1619
- }, {
1620
- id: contentType.sys.id + "-inline",
1621
- label: "Embed " + contentType.name + " - Inline",
1622
- callback: function callback() {
1623
- fetchEntries(sdk, contentType, query).then(function (entries) {
1624
- removeQuery(editor);
1625
-
1626
- if (!entries.length) {
1627
- setCommands([{
1628
- id: 'no-results',
1629
- label: 'No results'
1630
- }]);
1631
- } else {
1632
- setCommands(entries.map(function (entry) {
1633
- return {
1634
- id: entry.id + "-" + entry.displayTitle.replace(/\W+/g, '-').toLowerCase(),
1635
- label: entry.displayTitle,
1636
- callback: function callback() {
1637
- var inlineNode = createInlineEntryNode(entry.id);
1638
- removeCommand(editor);
1639
- slate.Transforms.insertNodes(editor, inlineNode);
1640
- editor.insertText('');
1641
- }
1642
- };
1643
- }));
1644
- }
1645
- });
1646
- }
1647
1742
  }]
1648
1743
  };
1649
- });
1650
- var assetCommand = {
1651
- group: 'Assets',
1652
- commands: [{
1653
- id: 'embed-asset',
1654
- label: 'Embed Asset',
1655
- callback: function callback() {
1656
- fetchAssets(sdk, query).then(function (assets) {
1657
- removeQuery(editor);
1658
-
1659
- if (!assets.length) {
1660
- setCommands([{
1661
- id: 'no-results',
1662
- label: 'No results'
1663
- }]);
1664
- } else {
1665
- setCommands(assets.map(function (asset) {
1666
- return {
1667
- id: asset.id + "-" + asset.displayTitle.replace(/\W+/g, '-').toLowerCase(),
1668
- label: asset.displayTitle,
1669
- thumbnail: asset.thumbnail,
1670
- callback: function callback() {
1671
- removeCommand(editor);
1744
+ return [].concat(contentTypeCommands, [assetCommand]);
1745
+ }
1672
1746
 
1673
- if (editor.selection) {
1674
- var selection = editor.selection;
1675
- editor.insertSoftBreak();
1676
- insertBlock(editor, Contentful.BLOCKS.EMBEDDED_ASSET, asset.entity);
1677
- slate.Transforms.select(editor, selection);
1678
- }
1679
- }
1680
- };
1681
- }));
1682
- }
1683
- });
1684
- }
1685
- }]
1686
- };
1687
- return [].concat(contentTypeCommands, [assetCommand]);
1747
+ return contentTypeCommands;
1688
1748
  }),
1689
1749
  commands = _useState[0],
1690
1750
  setCommands = _useState[1];
@@ -1770,7 +1830,6 @@ var styles = {
1770
1830
  margin: tokens.spacingXs + " 0"
1771
1831
  }),
1772
1832
  menuHeader: /*#__PURE__*/emotion.css({
1773
- position: 'sticky',
1774
1833
  zIndex: tokens.zIndexDefault,
1775
1834
  top: 0,
1776
1835
  backgroundColor: tokens.gray100,
@@ -1869,25 +1928,34 @@ var CommandListItems = function CommandListItems(_ref4) {
1869
1928
 
1870
1929
  var CommandList = function CommandList(_ref5) {
1871
1930
  var query = _ref5.query,
1872
- editor = _ref5.editor;
1931
+ editor = _ref5.editor,
1932
+ textContainer = _ref5.textContainer;
1873
1933
  var sdk = useSdkContext();
1874
- var container = React.useRef(null);
1934
+ var popoverContainer = React.useRef(null);
1935
+ var popper = reactPopper.usePopper(textContainer, popoverContainer == null ? void 0 : popoverContainer.current, {
1936
+ placement: 'bottom-start'
1937
+ });
1875
1938
  var commandItems = useCommands(sdk, query, editor);
1876
1939
 
1877
- var _useCommandList = useCommandList(commandItems, container),
1940
+ var _useCommandList = useCommandList(commandItems, popoverContainer),
1878
1941
  selectedItem = _useCommandList.selectedItem,
1879
1942
  isOpen = _useCommandList.isOpen;
1880
1943
 
1944
+ if (!commandItems.length) {
1945
+ return null;
1946
+ }
1947
+
1881
1948
  return /*#__PURE__*/React.createElement("div", {
1882
1949
  className: styles.container,
1883
1950
  tabIndex: -1,
1884
- ref: container,
1885
1951
  contentEditable: false
1886
1952
  }, /*#__PURE__*/React.createElement("div", {
1887
1953
  role: "alert"
1888
- }, /*#__PURE__*/React.createElement(f36Components.ScreenReaderOnly, null, "Richtext commands. Currently focused item: ", selectedItem, ". Press ", /*#__PURE__*/React.createElement("kbd", null, "enter"), " to select, ", /*#__PURE__*/React.createElement("kbd", null, "arrows"), " to navigate, ", /*#__PURE__*/React.createElement("kbd", null, "escape"), " to close.")), /*#__PURE__*/React.createElement("div", {
1889
- "aria-hidden": true
1890
- }, /*#__PURE__*/React.createElement(f36Components.Popover, {
1954
+ }, /*#__PURE__*/React.createElement(f36Components.ScreenReaderOnly, null, "Richtext commands. Currently focused item: ", selectedItem, ". Press ", /*#__PURE__*/React.createElement("kbd", null, "enter"), " to select, ", /*#__PURE__*/React.createElement("kbd", null, "arrows"), " to navigate, ", /*#__PURE__*/React.createElement("kbd", null, "escape"), " to close.")), /*#__PURE__*/React.createElement(f36Utils.Portal, null, /*#__PURE__*/React.createElement("div", Object.assign({
1955
+ "aria-hidden": true,
1956
+ ref: popoverContainer,
1957
+ style: popper.styles.popper
1958
+ }, popper.attributes.popper), /*#__PURE__*/React.createElement(f36Components.Popover, {
1891
1959
  isOpen: isOpen,
1892
1960
  usePortal: false,
1893
1961
 
@@ -1914,7 +1982,7 @@ var CommandList = function CommandList(_ref5) {
1914
1982
  padding: "none",
1915
1983
  spacing: "spacingS",
1916
1984
  className: styles.footerList
1917
- }, /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("kbd", null, "\u2191"), /*#__PURE__*/React.createElement("kbd", null, "\u2193"), " to navigate"), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("kbd", null, "\u21B5"), " to confirm"), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("kbd", null, "esc"), " to close")))))));
1985
+ }, /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("kbd", null, "\u2191"), /*#__PURE__*/React.createElement("kbd", null, "\u2193"), " to navigate"), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("kbd", null, "\u21B5"), " to confirm"), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("kbd", null, "esc"), " to close"))))))));
1918
1986
  };
1919
1987
 
1920
1988
  var CommandPrompt = function CommandPrompt(props) {
@@ -1922,10 +1990,19 @@ var CommandPrompt = function CommandPrompt(props) {
1922
1990
  return trimLeadingSlash(props.text.text);
1923
1991
  }, [props.text.text]);
1924
1992
  var editor = props.editor;
1925
- var canInsertBlocks = !isNodeTypeSelected(editor, Contentful.BLOCKS.TABLE);
1926
- return /*#__PURE__*/React.createElement("span", Object.assign({}, props.attributes), props.children, canInsertBlocks && /*#__PURE__*/React.createElement(CommandList, {
1993
+
1994
+ var _React$useState = React.useState(),
1995
+ textElement = _React$useState[0],
1996
+ setTextElement = _React$useState[1];
1997
+
1998
+ return /*#__PURE__*/React.createElement("span", Object.assign({
1999
+ ref: function ref(e) {
2000
+ setTextElement(e);
2001
+ }
2002
+ }, props.attributes), props.children, /*#__PURE__*/React.createElement(CommandList, {
1927
2003
  query: query,
1928
- editor: editor
2004
+ editor: editor,
2005
+ textContainer: textElement
1929
2006
  }));
1930
2007
  };
1931
2008
 
@@ -1936,6 +2013,7 @@ var createOnKeyDown = function createOnKeyDown() {
1936
2013
  var _setMarks;
1937
2014
 
1938
2015
  plateCore.setMarks(editor, (_setMarks = {}, _setMarks[COMMAND_PROMPT] = true, _setMarks));
2016
+ editor.tracking.onCommandPaletteAction('openRichTextCommandPalette');
1939
2017
  }
1940
2018
 
1941
2019
  var isActive = plateCore.isMarkActive(editor, COMMAND_PROMPT);
@@ -1965,6 +2043,7 @@ var createOnKeyDown = function createOnKeyDown() {
1965
2043
  key: COMMAND_PROMPT,
1966
2044
  at: _range
1967
2045
  });
2046
+ editor.tracking.onCommandPaletteAction('cancelRichTextCommandPalette');
1968
2047
  }
1969
2048
  }
1970
2049
  };
@@ -2074,8 +2153,8 @@ function useFetchedEntity(_ref) {
2074
2153
  var _useEntities = fieldEditorReference.useEntities(),
2075
2154
  entries = _useEntities.entries,
2076
2155
  assets = _useEntities.assets,
2077
- getOrLoadEntry = _useEntities.getOrLoadEntry,
2078
- getOrLoadAsset = _useEntities.getOrLoadAsset;
2156
+ getEntry = _useEntities.getEntry,
2157
+ getAsset = _useEntities.getAsset;
2079
2158
 
2080
2159
  var store = type === 'Entry' ? entries : assets;
2081
2160
 
@@ -2093,7 +2172,7 @@ function useFetchedEntity(_ref) {
2093
2172
  }, [store, entity, id]); // Fetch the entity if needed
2094
2173
 
2095
2174
  React.useEffect(function () {
2096
- (type === 'Entry' ? getOrLoadEntry : getOrLoadAsset)(id); // "getOrLoadEntry" and "getOrLoadAsset" instances change with every
2175
+ (type === 'Entry' ? getEntry : getAsset)(id); // "getEntry" and "getAsset" instances change with every
2097
2176
  // entity store update causing page lag on initial load
2098
2177
  // TODO: consider rewriting useEntities() hook to avoid that happening in
2099
2178
  // first place.
@@ -2646,7 +2725,7 @@ var styles$3 = {
2646
2725
  };
2647
2726
  function FetchingWrappedInlineEntryCard(props) {
2648
2727
  var _useEntities = fieldEditorReference.useEntities(),
2649
- getOrLoadEntry = _useEntities.getOrLoadEntry,
2728
+ getEntry = _useEntities.getEntry,
2650
2729
  loadEntityScheduledActions = _useEntities.loadEntityScheduledActions,
2651
2730
  entries = _useEntities.entries;
2652
2731
 
@@ -2680,7 +2759,7 @@ function FetchingWrappedInlineEntryCard(props) {
2680
2759
  }, [entry, contentType, props.sdk.field.locale, props.sdk.locales["default"]]);
2681
2760
  React__default.useEffect(function () {
2682
2761
  if (!props.entryId) return;
2683
- getOrLoadEntry(props.entryId); // We don't include getOrLoadEntry below because it's part of the constate-derived
2762
+ getEntry(props.entryId); // We don't include getEntry below because it's part of the constate-derived
2684
2763
  // useEntities(), not props.
2685
2764
  // eslint-disable-next-line -- TODO: explain this disable
2686
2765
  }, [props.entryId]);
@@ -2966,38 +3045,6 @@ function getWithEmbeddedEntryInlineEvents(sdk) {
2966
3045
  };
2967
3046
  }
2968
3047
 
2969
- var VALIDATIONS = {
2970
- ENABLED_MARKS: 'enabledMarks',
2971
- ENABLED_NODE_TYPES: 'enabledNodeTypes'
2972
- };
2973
- var DEFAULT_ENABLED_NODE_TYPES = [Contentful.BLOCKS.DOCUMENT, Contentful.BLOCKS.PARAGRAPH, 'text'];
2974
-
2975
- var getRichTextValidation = function getRichTextValidation(field, validationType) {
2976
- return flow(function (v) {
2977
- return find(v, validationType);
2978
- }, function (v) {
2979
- return get(v, validationType);
2980
- })(field.validations);
2981
- };
2982
-
2983
- var isFormattingOptionEnabled = function isFormattingOptionEnabled(field, validationType, nodeTypeOrMark) {
2984
- var enabledFormattings = getRichTextValidation(field, validationType); // TODO: In the future, validations will always be opt-in. In that case
2985
- // we don't need this step.
2986
-
2987
- if (enabledFormattings === undefined) {
2988
- return true;
2989
- }
2990
-
2991
- return DEFAULT_ENABLED_NODE_TYPES.concat(enabledFormattings).includes(nodeTypeOrMark);
2992
- };
2993
-
2994
- var isNodeTypeEnabled = function isNodeTypeEnabled(field, nodeType) {
2995
- return isFormattingOptionEnabled(field, VALIDATIONS.ENABLED_NODE_TYPES, nodeType);
2996
- };
2997
- var isMarkEnabled = function isMarkEnabled(field, mark) {
2998
- return isFormattingOptionEnabled(field, VALIDATIONS.ENABLED_MARKS, mark);
2999
- };
3000
-
3001
3048
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _dropdown, _LABELS;
3002
3049
  var styles$5 = {
3003
3050
  dropdown: (_dropdown = {