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

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.
@@ -577,6 +577,10 @@ var useCommandList = function useCommandList(commandItems, container) {
577
577
  selectedItem = _React$useState[0],
578
578
  setSelectedItem = _React$useState[1];
579
579
 
580
+ var _React$useState2 = useState(commandItems.length > 0),
581
+ isOpen = _React$useState2[0],
582
+ setIsOpen = _React$useState2[1];
583
+
580
584
  useEffect(function () {
581
585
  if (!(container != null && container.current)) {
582
586
  return;
@@ -641,8 +645,21 @@ var useCommandList = function useCommandList(commandItems, container) {
641
645
  return window.removeEventListener('keydown', handleKeyDown);
642
646
  };
643
647
  }, [commandItems, container, selectedItem]);
648
+ useEffect(function () {
649
+ var handleClick = function handleClick(event) {
650
+ if (container.current && !container.current.contains(event.target)) {
651
+ setIsOpen(false);
652
+ }
653
+ };
654
+
655
+ document.addEventListener('click', handleClick);
656
+ return function () {
657
+ document.removeEventListener('click', handleClick);
658
+ };
659
+ }, [container]);
644
660
  return {
645
- selectedItem: selectedItem
661
+ selectedItem: selectedItem,
662
+ isOpen: isOpen
646
663
  };
647
664
  };
648
665
 
@@ -1851,11 +1868,8 @@ var CommandList = function CommandList(_ref5) {
1851
1868
  var commandItems = useCommands(sdk, query, editor);
1852
1869
 
1853
1870
  var _useCommandList = useCommandList(commandItems, container),
1854
- selectedItem = _useCommandList.selectedItem;
1855
-
1856
- if (commandItems.length === 0) {
1857
- return null;
1858
- }
1871
+ selectedItem = _useCommandList.selectedItem,
1872
+ isOpen = _useCommandList.isOpen;
1859
1873
 
1860
1874
  return /*#__PURE__*/createElement("div", {
1861
1875
  className: styles.container,
@@ -1867,17 +1881,21 @@ var CommandList = function CommandList(_ref5) {
1867
1881
  }, /*#__PURE__*/createElement(ScreenReaderOnly, null, "Richtext commands. Currently focused item: ", selectedItem, ". Press ", /*#__PURE__*/createElement("kbd", null, "enter"), " to select, ", /*#__PURE__*/createElement("kbd", null, "arrows"), " to navigate, ", /*#__PURE__*/createElement("kbd", null, "escape"), " to close.")), /*#__PURE__*/createElement("div", {
1868
1882
  "aria-hidden": true
1869
1883
  }, /*#__PURE__*/createElement(Popover, {
1870
- isOpen: true,
1884
+ isOpen: isOpen,
1871
1885
  usePortal: false,
1886
+
1887
+ /* eslint-disable-next-line jsx-a11y/no-autofocus -- we want to keep focus on text input*/
1872
1888
  autoFocus: false
1873
1889
  }, /*#__PURE__*/createElement(Popover.Trigger, null, /*#__PURE__*/createElement("span", null)), /*#__PURE__*/createElement(Popover.Content, {
1874
- className: styles.menuContent
1890
+ className: styles.menuContent,
1891
+ testId: "rich-text-commands"
1875
1892
  }, /*#__PURE__*/createElement("header", {
1876
1893
  className: styles.menuHeader
1877
1894
  }, /*#__PURE__*/createElement(SectionHeading, {
1878
1895
  marginBottom: "none"
1879
1896
  }, "Richtext commands")), /*#__PURE__*/createElement("div", {
1880
- className: styles.menuList
1897
+ className: styles.menuList,
1898
+ "data-test-id": "rich-text-commands-list"
1881
1899
  }, /*#__PURE__*/createElement(CommandListItems, {
1882
1900
  commandItems: commandItems,
1883
1901
  selectedItem: selectedItem
@@ -7371,24 +7389,13 @@ var StickyToolbarWrapper = function StickyToolbarWrapper(_ref) {
7371
7389
  }, children);
7372
7390
  };
7373
7391
 
7374
- /**
7375
- * Returns whether a given operation is relevant enough to trigger a save.
7376
- */
7377
-
7378
- var isRelevantOperation = function isRelevantOperation(op) {
7379
- if (op.type === 'set_selection') {
7380
- return false;
7381
- }
7382
-
7383
- return true;
7384
- };
7385
-
7392
+ var internalMarks = [COMMAND_PROMPT];
7386
7393
  var removeInternalMarks = function removeInternalMarks(document) {
7387
7394
  return _extends({}, document, {
7388
7395
  content: document.content.map(function (node) {
7389
7396
  if (node.nodeType === 'text') {
7390
7397
  node.marks = node.marks.filter(function (mark) {
7391
- return mark.type !== COMMAND_PROMPT;
7398
+ return !internalMarks.includes(mark.type);
7392
7399
  });
7393
7400
  return node;
7394
7401
  }
@@ -7398,6 +7405,18 @@ var removeInternalMarks = function removeInternalMarks(document) {
7398
7405
  });
7399
7406
  };
7400
7407
 
7408
+ /**
7409
+ * Returns whether a given operation is relevant enough to trigger a save.
7410
+ */
7411
+
7412
+ var isRelevantOperation = function isRelevantOperation(op) {
7413
+ if (op.type === 'set_selection') {
7414
+ return false;
7415
+ }
7416
+
7417
+ return true;
7418
+ };
7419
+
7401
7420
  var useOnValueChanged = function useOnValueChanged(_ref) {
7402
7421
  var editorId = _ref.editorId,
7403
7422
  handler = _ref.handler,