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

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.
@@ -1,8 +1,8 @@
1
1
  import React__default, { useContext, createContext, useMemo, createElement, useEffect, useState, memo, Fragment, useCallback } from 'react';
2
2
  import { useEntities, ScheduledIconWithTooltip, MissingEntityCard, AssetThumbnail, getScheduleTooltipContent, EntityProvider } from '@contentful/field-editor-reference';
3
3
  import { entityHelpers, shortenStorageUnit, isValidImage, ModalDialogLauncher, FieldConnector } from '@contentful/field-editor-shared';
4
- import { BLOCKS, INLINES, TABLE_BLOCKS, HEADINGS, TEXT_CONTAINERS, LIST_ITEM_BLOCKS, MARKS, CONTAINERS, TOP_LEVEL_BLOCKS, VOID_BLOCKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
5
- import { usePlateEditorState, usePlateEditorRef, getNodes, getText, toggleNodeType, getAbove, setNodes, isAncestorEmpty, getParent, isSelectionAtBlockStart, isSelectionAtBlockEnd, isFirstChild, insertNodes, moveChildren, isBlockAboveEmpty, mockPlugin, getPluginType, ELEMENT_DEFAULT, findNode, isMarkActive, toggleMark, someHtmlElement, match, KEY_DESERIALIZE_HTML, someNode, getChildren as getChildren$1, getBlockAbove, getLastChildPath, createDeserializeHtmlPlugin, createDeserializeAstPlugin, createPlateEditor, Plate } from '@udecode/plate-core';
4
+ import { BLOCKS, INLINES, TABLE_BLOCKS, TEXT_CONTAINERS, HEADINGS, LIST_ITEM_BLOCKS, MARKS, CONTAINERS, TOP_LEVEL_BLOCKS, VOID_BLOCKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
5
+ import { usePlateEditorState, usePlateEditorRef, getNodes, getText, toggleNodeType, getAbove, setNodes, isAncestorEmpty, getParent, getBlockAbove, isSelectionAtBlockStart, isSelectionAtBlockEnd, isFirstChild, insertNodes, moveChildren, isBlockAboveEmpty, mockPlugin, getPluginType, ELEMENT_DEFAULT, findNode, isMarkActive, toggleMark, someHtmlElement, match, KEY_DESERIALIZE_HTML, someNode, getChildren as getChildren$1, getLastChildPath, createDeserializeHtmlPlugin, createDeserializeAstPlugin, createPlateEditor, Plate } from '@udecode/plate-core';
6
6
  import { css, cx } from 'emotion';
7
7
  import deepEquals from 'fast-deep-equal';
8
8
  import noop from 'lodash-es/noop';
@@ -532,17 +532,6 @@ function getAncestorPathFromSelection(editor) {
532
532
  return level.length === 1;
533
533
  });
534
534
  }
535
- function shouldUnwrapBlockquote(editor, type) {
536
- var isQuoteSelected = isBlockSelected(editor, BLOCKS.QUOTE);
537
- var isValidType = [].concat(HEADINGS, [BLOCKS.OL_LIST, BLOCKS.UL_LIST, BLOCKS.HR]).includes(type);
538
- return isQuoteSelected && isValidType;
539
- }
540
- function unwrapFromRoot(editor) {
541
- var ancestorPath = getAncestorPathFromSelection(editor);
542
- Transforms.unwrapNodes(editor, {
543
- at: ancestorPath
544
- });
545
- }
546
535
  var isAtEndOfTextSelection = function isAtEndOfTextSelection(editor) {
547
536
  var _editor$selection, _editor$selection2;
548
537
 
@@ -2499,11 +2488,6 @@ function ToolbarHeadingButton(props) {
2499
2488
  if (!(editor != null && editor.selection)) return;
2500
2489
  setSelected(type);
2501
2490
  setOpen(false);
2502
-
2503
- if (shouldUnwrapBlockquote(editor, type)) {
2504
- unwrapFromRoot(editor);
2505
- }
2506
-
2507
2491
  var prevOnChange = editor.onChange;
2508
2492
  /*
2509
2493
  The focus might happen at point in time when
@@ -3719,6 +3703,16 @@ var replaceNodeWithListItems = function replaceNodeWithListItems(editor, entry)
3719
3703
  at: path
3720
3704
  });
3721
3705
  };
3706
+ var isListTypeActive = function isListTypeActive(editor, type) {
3707
+ // Lists can be nested. Here, we take the list type at the lowest level
3708
+ var listNode = getBlockAbove(editor, {
3709
+ match: {
3710
+ type: [BLOCKS.OL_LIST, BLOCKS.UL_LIST]
3711
+ },
3712
+ mode: 'lowest'
3713
+ });
3714
+ return (listNode == null ? void 0 : listNode[0].type) === type;
3715
+ };
3722
3716
 
3723
3717
  /**
3724
3718
  * Build a new list item node while preserving marks
@@ -4095,11 +4089,6 @@ function ToolbarListButton(props) {
4095
4089
  function handleClick(type) {
4096
4090
  return function () {
4097
4091
  if (!(editor != null && editor.selection)) return;
4098
-
4099
- if (shouldUnwrapBlockquote(editor, type)) {
4100
- unwrapFromRoot(editor);
4101
- }
4102
-
4103
4092
  toggleList(editor, {
4104
4093
  type: type
4105
4094
  });
@@ -4112,13 +4101,13 @@ function ToolbarListButton(props) {
4112
4101
  title: "UL",
4113
4102
  testId: "ul-toolbar-button",
4114
4103
  onClick: handleClick(BLOCKS.UL_LIST),
4115
- isActive: isBlockSelected(editor, BLOCKS.UL_LIST),
4104
+ isActive: isListTypeActive(editor, BLOCKS.UL_LIST),
4116
4105
  isDisabled: props.isDisabled
4117
4106
  }, /*#__PURE__*/createElement(ListBulletedIcon, null)), isNodeTypeEnabled(sdk.field, BLOCKS.OL_LIST) && /*#__PURE__*/createElement(ToolbarButton, {
4118
4107
  title: "OL",
4119
4108
  testId: "ol-toolbar-button",
4120
4109
  onClick: handleClick(BLOCKS.OL_LIST),
4121
- isActive: isBlockSelected(editor, BLOCKS.OL_LIST),
4110
+ isActive: isListTypeActive(editor, BLOCKS.OL_LIST),
4122
4111
  isDisabled: props.isDisabled
4123
4112
  }, /*#__PURE__*/createElement(ListNumberedIcon, null)));
4124
4113
  }
@@ -4751,10 +4740,7 @@ var style$1 = /*#__PURE__*/css({
4751
4740
  margin: '0 0 1.3125rem',
4752
4741
  borderLeft: "6px solid " + tokens.gray200,
4753
4742
  paddingLeft: '0.875rem',
4754
- fontStyle: 'normal',
4755
- '& a': {
4756
- color: 'inherit'
4757
- }
4743
+ fontStyle: 'normal'
4758
4744
  });
4759
4745
  function Quote(props) {
4760
4746
  return /*#__PURE__*/createElement("blockquote", Object.assign({}, props.attributes, {
@@ -4825,7 +4811,7 @@ function createQuotePlugin() {
4825
4811
  },
4826
4812
  normalizer: [{
4827
4813
  validChildren: CONTAINERS[BLOCKS.QUOTE],
4828
- transform: (_transform = {}, _transform[BLOCKS.QUOTE] = transformUnwrap, _transform[BLOCKS.HEADING_1] = transformUnwrap, _transform[BLOCKS.HEADING_2] = transformUnwrap, _transform[BLOCKS.HEADING_3] = transformUnwrap, _transform[BLOCKS.HEADING_4] = transformUnwrap, _transform[BLOCKS.HEADING_5] = transformUnwrap, _transform[BLOCKS.HEADING_6] = transformUnwrap, _transform["default"] = transformLift, _transform)
4814
+ transform: (_transform = {}, _transform[BLOCKS.QUOTE] = transformUnwrap, _transform["default"] = transformLift, _transform)
4829
4815
  }],
4830
4816
  withOverrides: function withOverrides(editor) {
4831
4817
  var insertFragment = editor.insertFragment;