@contentful/field-editor-rich-text 0.24.1-next → 0.26.2-next
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 -14
- 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 +59 -16
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/helpers/validations.d.ts +2 -1
- package/dist/plugins/List/index.d.ts +1 -0
- package/package.json +9 -9
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React__default, { useState, useEffect, createElement, useMemo, Fragment, useCallback } from 'react';
|
|
2
2
|
import noop from 'lodash-es/noop';
|
|
3
|
-
import {
|
|
4
|
-
import { TOP_LEVEL_BLOCKS, BLOCKS, CONTAINERS, VOID_BLOCKS, INLINES, MARKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
|
|
3
|
+
import { toContentfulDocument, toSlatejsDocument } from '@contentful/contentful-slatejs-adapter';
|
|
4
|
+
import { TOP_LEVEL_BLOCKS, BLOCKS, CONTAINERS, VOID_BLOCKS, INLINES, LIST_ITEM_BLOCKS, MARKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
|
|
5
5
|
import { useEntities, ScheduledIconWithTooltip, MissingEntityCard, AssetThumbnail, EntityProvider } from '@contentful/field-editor-reference';
|
|
6
6
|
import { css, cx } from 'emotion';
|
|
7
7
|
import tokens from '@contentful/forma-36-tokens';
|
|
@@ -15,11 +15,12 @@ import constate from 'constate';
|
|
|
15
15
|
import find from 'lodash-es/find';
|
|
16
16
|
import flow from 'lodash-es/flow';
|
|
17
17
|
import get from 'lodash-es/get';
|
|
18
|
-
import { ELEMENT_LIC, ELEMENT_LI, ELEMENT_UL, ELEMENT_OL,
|
|
18
|
+
import { ELEMENT_LIC, ELEMENT_LI, ELEMENT_UL, ELEMENT_OL, createListPlugin as createListPlugin$1, toggleList } from '@udecode/plate-list';
|
|
19
19
|
import { entityHelpers, isValidImage, shortenStorageUnit, ModalDialogLauncher, FieldConnector } from '@contentful/field-editor-shared';
|
|
20
20
|
import moment from 'moment';
|
|
21
21
|
import mimetype from '@contentful/mimetype';
|
|
22
22
|
import { ELEMENT_TABLE, ELEMENT_TH, ELEMENT_TR, ELEMENT_TD, insertTable, getEmptyRowNode, getEmptyCellNode, deleteRow, deleteColumn, deleteTable, createTablePlugin as createTablePlugin$1, getTableOnKeyDown } from '@udecode/plate-table';
|
|
23
|
+
import { documentToPlainTextString } from '@contentful/rich-text-plain-text-renderer';
|
|
23
24
|
import { createDeserializeHTMLPlugin } from '@udecode/plate-html-serializer';
|
|
24
25
|
import { ELEMENT_PARAGRAPH } from '@udecode/plate-paragraph';
|
|
25
26
|
import { createExitBreakPlugin } from '@udecode/plate-break';
|
|
@@ -672,6 +673,7 @@ var VALIDATIONS = {
|
|
|
672
673
|
ENABLED_MARKS: 'enabledMarks',
|
|
673
674
|
ENABLED_NODE_TYPES: 'enabledNodeTypes'
|
|
674
675
|
};
|
|
676
|
+
var DEFAULT_ENABLED_NODE_TYPES = [BLOCKS.DOCUMENT, BLOCKS.PARAGRAPH, 'text'];
|
|
675
677
|
|
|
676
678
|
var getRichTextValidation = function getRichTextValidation(field, validationType) {
|
|
677
679
|
return flow(function (v) {
|
|
@@ -682,13 +684,14 @@ var getRichTextValidation = function getRichTextValidation(field, validationType
|
|
|
682
684
|
};
|
|
683
685
|
|
|
684
686
|
var isFormattingOptionEnabled = function isFormattingOptionEnabled(field, validationType, nodeTypeOrMark) {
|
|
685
|
-
var enabledFormattings = getRichTextValidation(field, validationType);
|
|
687
|
+
var enabledFormattings = getRichTextValidation(field, validationType); // TODO: In the future, validations will always be opt-in. In that case
|
|
688
|
+
// we don't need this step.
|
|
686
689
|
|
|
687
690
|
if (enabledFormattings === undefined) {
|
|
688
691
|
return true;
|
|
689
692
|
}
|
|
690
693
|
|
|
691
|
-
return enabledFormattings.includes(nodeTypeOrMark);
|
|
694
|
+
return DEFAULT_ENABLED_NODE_TYPES.concat(enabledFormattings).includes(nodeTypeOrMark);
|
|
692
695
|
};
|
|
693
696
|
|
|
694
697
|
var isNodeTypeEnabled = function isNodeTypeEnabled(field, nodeType) {
|
|
@@ -1128,6 +1131,11 @@ var withListOptions = (_withListOptions = {}, _withListOptions[ELEMENT_LIC] = {
|
|
|
1128
1131
|
type: BLOCKS.OL_LIST,
|
|
1129
1132
|
component: OL
|
|
1130
1133
|
}, _withListOptions);
|
|
1134
|
+
var createListPlugin = function createListPlugin() {
|
|
1135
|
+
return createListPlugin$1({
|
|
1136
|
+
validLiChildrenTypes: LIST_ITEM_BLOCKS
|
|
1137
|
+
});
|
|
1138
|
+
};
|
|
1131
1139
|
|
|
1132
1140
|
var _withBoldOptions;
|
|
1133
1141
|
function ToolbarBoldButton(props) {
|
|
@@ -2413,13 +2421,17 @@ function FetchingWrappedEntryCard(props) {
|
|
|
2413
2421
|
|
|
2414
2422
|
var entry = entries[props.entryId];
|
|
2415
2423
|
var contentType = useMemo(function () {
|
|
2424
|
+
if (!entry || entry === 'failed') {
|
|
2425
|
+
return undefined;
|
|
2426
|
+
}
|
|
2427
|
+
|
|
2416
2428
|
return props.sdk.space.getCachedContentTypes().find(function (contentType) {
|
|
2417
|
-
return contentType.sys.id ===
|
|
2429
|
+
return contentType.sys.id === entry.sys.contentType.sys.id;
|
|
2418
2430
|
});
|
|
2419
2431
|
}, [props.sdk, entry]);
|
|
2420
2432
|
var defaultLocaleCode = props.sdk.locales["default"];
|
|
2421
2433
|
useEffect(function () {
|
|
2422
|
-
if (!entry) return;
|
|
2434
|
+
if (!entry || entry === 'failed') return;
|
|
2423
2435
|
entityHelpers.getEntryImage({
|
|
2424
2436
|
entry: entry,
|
|
2425
2437
|
contentType: contentType,
|
|
@@ -2551,13 +2563,15 @@ function AssetDropdownMenu(_ref) {
|
|
|
2551
2563
|
}
|
|
2552
2564
|
|
|
2553
2565
|
function FetchingWrappedAssetCard(props) {
|
|
2566
|
+
var _asset$fields;
|
|
2567
|
+
|
|
2554
2568
|
var _useEntities = useEntities(),
|
|
2555
2569
|
getOrLoadAsset = _useEntities.getOrLoadAsset,
|
|
2556
2570
|
assets = _useEntities.assets;
|
|
2557
2571
|
|
|
2558
2572
|
var asset = assets[props.assetId];
|
|
2559
2573
|
var defaultLocaleCode = props.sdk.locales["default"];
|
|
2560
|
-
var entityFile = asset != null && asset.fields.file ? asset.fields.file[props.locale] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
2574
|
+
var entityFile = asset != null && (_asset$fields = asset.fields) != null && _asset$fields.file ? asset.fields.file[props.locale] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
2561
2575
|
useEffect(function () {
|
|
2562
2576
|
getOrLoadAsset(props.assetId);
|
|
2563
2577
|
}, [props.assetId]); // eslint-disable-line
|
|
@@ -3627,6 +3641,15 @@ var TableActions = function TableActions() {
|
|
|
3627
3641
|
|
|
3628
3642
|
var _templateObject$4, _templateObject2$3, _templateObject3$3, _templateObject4$1, _styles$1, _withTableOptions;
|
|
3629
3643
|
var styles$g = (_styles$1 = {}, _styles$1[BLOCKS.TABLE] = /*#__PURE__*/css(_templateObject$4 || (_templateObject$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-bottom: 1.5em;\n border-collapse: collapse;\n border-radius: 5px;\n border-style: hidden;\n box-shadow: 0 0 0 1px ", ";\n width: 100%;\n table-layout: fixed;\n overflow: hidden;\n "])), tokens.gray400), _styles$1[BLOCKS.TABLE_ROW] = /*#__PURE__*/css(_templateObject2$3 || (_templateObject2$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n &:hover td {\n background-color: transparent !important;\n }\n "])), tokens.gray400), _styles$1[BLOCKS.TABLE_HEADER_CELL] = /*#__PURE__*/css(_templateObject3$3 || (_templateObject3$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n background-color: ", ";\n border: 1px solid ", ";\n padding: 10px 12px;\n font-weight: ", ";\n text-align: left;\n min-width: 48px;\n position: relative;\n div:last-child {\n margin-bottom: 0;\n }\n "])), tokens.gray200, tokens.gray400, tokens.fontWeightMedium), _styles$1[BLOCKS.TABLE_CELL] = /*#__PURE__*/css(_templateObject4$1 || (_templateObject4$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n border: 1px solid ", ";\n padding: 10px 12px;\n min-width: 48px;\n position: relative;\n div:last-child {\n margin-bottom: 0;\n }\n "])), tokens.gray400), _styles$1);
|
|
3644
|
+
|
|
3645
|
+
var slateNodeToText = function slateNodeToText(node) {
|
|
3646
|
+
var contentfulNode = toContentfulDocument({
|
|
3647
|
+
document: [node],
|
|
3648
|
+
schema: schema
|
|
3649
|
+
});
|
|
3650
|
+
return documentToPlainTextString(contentfulNode);
|
|
3651
|
+
};
|
|
3652
|
+
|
|
3630
3653
|
var Table = function Table(props) {
|
|
3631
3654
|
return /*#__PURE__*/createElement("table", Object.assign({}, props.attributes, {
|
|
3632
3655
|
className: styles$g[BLOCKS.TABLE]
|
|
@@ -3684,10 +3707,20 @@ function addTableTrackingEvents(editor, _ref) {
|
|
|
3684
3707
|
});
|
|
3685
3708
|
}
|
|
3686
3709
|
}, 1);
|
|
3710
|
+
} else {
|
|
3711
|
+
insertData(data);
|
|
3687
3712
|
}
|
|
3688
3713
|
};
|
|
3689
3714
|
}
|
|
3690
3715
|
|
|
3716
|
+
var paragraph = function paragraph() {
|
|
3717
|
+
return {
|
|
3718
|
+
type: BLOCKS.PARAGRAPH,
|
|
3719
|
+
data: {},
|
|
3720
|
+
children: []
|
|
3721
|
+
};
|
|
3722
|
+
};
|
|
3723
|
+
|
|
3691
3724
|
function addTableNormalization(editor) {
|
|
3692
3725
|
var normalizeNode = editor.normalizeNode;
|
|
3693
3726
|
|
|
@@ -3706,12 +3739,20 @@ function addTableNormalization(editor) {
|
|
|
3706
3739
|
childPath = _step$value[1];
|
|
3707
3740
|
|
|
3708
3741
|
if (Text.isText(child)) {
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
}
|
|
3714
|
-
|
|
3742
|
+
Transforms.wrapNodes(editor, paragraph(), {
|
|
3743
|
+
at: childPath
|
|
3744
|
+
});
|
|
3745
|
+
} else if (!CONTAINERS[node.type].includes(child.type)) {
|
|
3746
|
+
var paragraphWithTextFromNode = _extends({}, paragraph(), {
|
|
3747
|
+
children: [{
|
|
3748
|
+
text: slateNodeToText(child)
|
|
3749
|
+
}]
|
|
3750
|
+
});
|
|
3751
|
+
|
|
3752
|
+
Transforms.removeNodes(editor, {
|
|
3753
|
+
at: childPath
|
|
3754
|
+
});
|
|
3755
|
+
Transforms.insertNodes(editor, paragraphWithTextFromNode, {
|
|
3715
3756
|
at: childPath
|
|
3716
3757
|
});
|
|
3717
3758
|
}
|
|
@@ -4262,7 +4303,7 @@ function FetchingWrappedInlineEntryCard(props) {
|
|
|
4262
4303
|
}, [entries, props.entryId]);
|
|
4263
4304
|
var allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
4264
4305
|
var contentType = React__default.useMemo(function () {
|
|
4265
|
-
if (!entry || !allContentTypes) return undefined;
|
|
4306
|
+
if (!entry || entry === 'failed' || !allContentTypes) return undefined;
|
|
4266
4307
|
return allContentTypes.find(function (contentType) {
|
|
4267
4308
|
return contentType.sys.id === entry.sys.contentType.sys.id;
|
|
4268
4309
|
});
|
|
@@ -4752,7 +4793,7 @@ var removeComments = function removeComments(_ref) {
|
|
|
4752
4793
|
|
|
4753
4794
|
var TAG_NAME_TABLE = 'TABLE';
|
|
4754
4795
|
var TAG_NAME_TABLE_CAPTION = 'CAPTION';
|
|
4755
|
-
var DISALLOWED_TABLE_CHILD_ELEMENTS = [
|
|
4796
|
+
var DISALLOWED_TABLE_CHILD_ELEMENTS = [TAG_NAME_TABLE_CAPTION];
|
|
4756
4797
|
|
|
4757
4798
|
var isHTMLElement = function isHTMLElement(node) {
|
|
4758
4799
|
return node.nodeType === Node.ELEMENT_NODE;
|
|
@@ -4846,6 +4887,8 @@ function withPasteHandling(editor) {
|
|
|
4846
4887
|
var sanitized = sanitizeHtml(html, editor);
|
|
4847
4888
|
var newData = htmlToDataTransfer(sanitized);
|
|
4848
4889
|
insertData(newData);
|
|
4890
|
+
} else {
|
|
4891
|
+
insertData(data);
|
|
4849
4892
|
}
|
|
4850
4893
|
};
|
|
4851
4894
|
};
|