@contentful/field-editor-rich-text 2.0.0-next.14 → 2.0.0-next.17
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.
- package/dist/field-editor-rich-text.cjs.development.js +57 -37
- package/dist/field-editor-rich-text.cjs.development.js.map +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js +1 -1
- package/dist/field-editor-rich-text.cjs.production.min.js.map +1 -1
- package/dist/field-editor-rich-text.esm.js +60 -40
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/editor.d.ts +0 -2
- package/dist/plugins/List/utils.d.ts +2 -0
- package/dist/plugins/PasteHTML/createPasteHTMLPlugin.d.ts +6 -0
- package/dist/test-utils/jsx.d.ts +1 -1
- package/package.json +4 -4
|
@@ -1,15 +1,15 @@
|
|
|
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,
|
|
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,
|
|
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';
|
|
9
9
|
import { createDeserializeDocxPlugin } from '@udecode/plate-serializer-docx';
|
|
10
10
|
import { createSoftBreakPlugin as createSoftBreakPlugin$1, createExitBreakPlugin as createExitBreakPlugin$1 } from '@udecode/plate-break';
|
|
11
11
|
import isHotkey from 'is-hotkey';
|
|
12
|
-
import { Text, Element, Editor, Transforms, Range,
|
|
12
|
+
import { Text, Element, Editor, Transforms, Range, Node, Path, Point } from 'slate';
|
|
13
13
|
import { ReactEditor, useSelected, useReadOnly, useFocused } from 'slate-react';
|
|
14
14
|
import constate from 'constate';
|
|
15
15
|
import { AssetCard, Menu, Text as Text$1, Notification, EntryCard, MenuItem, Button, Flex, Icon, InlineEntryCard, Tooltip, ModalContent, Form, FormControl, TextInput, Select, FormLabel, TextLink, ModalControls, IconButton } from '@contentful/f36-components';
|
|
@@ -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
|
|
@@ -2793,10 +2777,6 @@ function withHrEvents(editor) {
|
|
|
2793
2777
|
pathToSelectedHr = _getNodeEntryFromSele[1];
|
|
2794
2778
|
|
|
2795
2779
|
if (pathToSelectedHr) {
|
|
2796
|
-
if (shouldUnwrapBlockquote(editor, BLOCKS.HR)) {
|
|
2797
|
-
unwrapFromRoot(editor);
|
|
2798
|
-
}
|
|
2799
|
-
|
|
2800
2780
|
var isBackspace = event.key === 'Backspace';
|
|
2801
2781
|
var isDelete = event.key === 'Delete';
|
|
2802
2782
|
|
|
@@ -2814,11 +2794,6 @@ function ToolbarHrButton(props) {
|
|
|
2814
2794
|
|
|
2815
2795
|
function handleOnClick() {
|
|
2816
2796
|
if (!(editor != null && editor.selection)) return;
|
|
2817
|
-
|
|
2818
|
-
if (shouldUnwrapBlockquote(editor, BLOCKS.HR)) {
|
|
2819
|
-
unwrapFromRoot(editor);
|
|
2820
|
-
}
|
|
2821
|
-
|
|
2822
2797
|
var hr = {
|
|
2823
2798
|
type: BLOCKS.HR,
|
|
2824
2799
|
data: {},
|
|
@@ -3728,6 +3703,16 @@ var replaceNodeWithListItems = function replaceNodeWithListItems(editor, entry)
|
|
|
3728
3703
|
at: path
|
|
3729
3704
|
});
|
|
3730
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
|
+
};
|
|
3731
3716
|
|
|
3732
3717
|
/**
|
|
3733
3718
|
* Build a new list item node while preserving marks
|
|
@@ -4104,11 +4089,6 @@ function ToolbarListButton(props) {
|
|
|
4104
4089
|
function handleClick(type) {
|
|
4105
4090
|
return function () {
|
|
4106
4091
|
if (!(editor != null && editor.selection)) return;
|
|
4107
|
-
|
|
4108
|
-
if (shouldUnwrapBlockquote(editor, type)) {
|
|
4109
|
-
unwrapFromRoot(editor);
|
|
4110
|
-
}
|
|
4111
|
-
|
|
4112
4092
|
toggleList(editor, {
|
|
4113
4093
|
type: type
|
|
4114
4094
|
});
|
|
@@ -4121,13 +4101,13 @@ function ToolbarListButton(props) {
|
|
|
4121
4101
|
title: "UL",
|
|
4122
4102
|
testId: "ul-toolbar-button",
|
|
4123
4103
|
onClick: handleClick(BLOCKS.UL_LIST),
|
|
4124
|
-
isActive:
|
|
4104
|
+
isActive: isListTypeActive(editor, BLOCKS.UL_LIST),
|
|
4125
4105
|
isDisabled: props.isDisabled
|
|
4126
4106
|
}, /*#__PURE__*/createElement(ListBulletedIcon, null)), isNodeTypeEnabled(sdk.field, BLOCKS.OL_LIST) && /*#__PURE__*/createElement(ToolbarButton, {
|
|
4127
4107
|
title: "OL",
|
|
4128
4108
|
testId: "ol-toolbar-button",
|
|
4129
4109
|
onClick: handleClick(BLOCKS.OL_LIST),
|
|
4130
|
-
isActive:
|
|
4110
|
+
isActive: isListTypeActive(editor, BLOCKS.OL_LIST),
|
|
4131
4111
|
isDisabled: props.isDisabled
|
|
4132
4112
|
}, /*#__PURE__*/createElement(ListNumberedIcon, null)));
|
|
4133
4113
|
}
|
|
@@ -4694,11 +4674,54 @@ var sanitizeHTML = function sanitizeHTML(html) {
|
|
|
4694
4674
|
return doc.body.innerHTML.replace(/>\s+</g, '><');
|
|
4695
4675
|
};
|
|
4696
4676
|
|
|
4677
|
+
/**
|
|
4678
|
+
* Get x-slate-fragment attribute from data-slate-fragment
|
|
4679
|
+
*/
|
|
4680
|
+
|
|
4681
|
+
var catchSlateFragment = /data-slate-fragment="(.+?)"/m;
|
|
4682
|
+
var getSlateFragmentAttribute = function getSlateFragmentAttribute(dataTransfer) {
|
|
4683
|
+
var htmlData = dataTransfer.getData('text/html');
|
|
4684
|
+
|
|
4685
|
+
var _ref = htmlData.match(catchSlateFragment) || [],
|
|
4686
|
+
fragment = _ref[1];
|
|
4687
|
+
|
|
4688
|
+
return fragment;
|
|
4689
|
+
};
|
|
4690
|
+
/**
|
|
4691
|
+
* Get the x-slate-fragment attribute that exist in text/html data
|
|
4692
|
+
* and append it to the DataTransfer object
|
|
4693
|
+
*/
|
|
4694
|
+
|
|
4695
|
+
var ensureXSlateFragment = function ensureXSlateFragment(dataTransfer) {
|
|
4696
|
+
if (!dataTransfer.getData('application/x-slate-fragment')) {
|
|
4697
|
+
var fragment = getSlateFragmentAttribute(dataTransfer);
|
|
4698
|
+
|
|
4699
|
+
if (fragment) {
|
|
4700
|
+
var clipboardData = new DataTransfer();
|
|
4701
|
+
dataTransfer.types.forEach(function (type) {
|
|
4702
|
+
clipboardData.setData(type, dataTransfer.getData(type));
|
|
4703
|
+
});
|
|
4704
|
+
clipboardData.setData('application/x-slate-fragment', fragment);
|
|
4705
|
+
return clipboardData;
|
|
4706
|
+
}
|
|
4707
|
+
}
|
|
4708
|
+
|
|
4709
|
+
return dataTransfer;
|
|
4710
|
+
};
|
|
4697
4711
|
var createPasteHTMLPlugin = function createPasteHTMLPlugin() {
|
|
4698
4712
|
var _pluginsByKey;
|
|
4699
4713
|
|
|
4700
4714
|
return {
|
|
4701
4715
|
key: 'PasteHTMLPlugin',
|
|
4716
|
+
withOverrides: function withOverrides(editor) {
|
|
4717
|
+
var insertData = editor.insertData;
|
|
4718
|
+
|
|
4719
|
+
editor.insertData = function (data) {
|
|
4720
|
+
return insertData(ensureXSlateFragment(data));
|
|
4721
|
+
};
|
|
4722
|
+
|
|
4723
|
+
return editor;
|
|
4724
|
+
},
|
|
4702
4725
|
inject: {
|
|
4703
4726
|
pluginsByKey: (_pluginsByKey = {}, _pluginsByKey[KEY_DESERIALIZE_HTML] = {
|
|
4704
4727
|
editor: {
|
|
@@ -4717,10 +4740,7 @@ var style$1 = /*#__PURE__*/css({
|
|
|
4717
4740
|
margin: '0 0 1.3125rem',
|
|
4718
4741
|
borderLeft: "6px solid " + tokens.gray200,
|
|
4719
4742
|
paddingLeft: '0.875rem',
|
|
4720
|
-
fontStyle: 'normal'
|
|
4721
|
-
'& a': {
|
|
4722
|
-
color: 'inherit'
|
|
4723
|
-
}
|
|
4743
|
+
fontStyle: 'normal'
|
|
4724
4744
|
});
|
|
4725
4745
|
function Quote(props) {
|
|
4726
4746
|
return /*#__PURE__*/createElement("blockquote", Object.assign({}, props.attributes, {
|
|
@@ -4791,7 +4811,7 @@ function createQuotePlugin() {
|
|
|
4791
4811
|
},
|
|
4792
4812
|
normalizer: [{
|
|
4793
4813
|
validChildren: CONTAINERS[BLOCKS.QUOTE],
|
|
4794
|
-
transform: (_transform = {}, _transform[BLOCKS.QUOTE] = transformUnwrap, _transform[
|
|
4814
|
+
transform: (_transform = {}, _transform[BLOCKS.QUOTE] = transformUnwrap, _transform["default"] = transformLift, _transform)
|
|
4795
4815
|
}],
|
|
4796
4816
|
withOverrides: function withOverrides(editor) {
|
|
4797
4817
|
var insertFragment = editor.insertFragment;
|