@contentful/field-editor-rich-text 0.24.0-next → 0.26.1-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/CHANGELOG.md +684 -0
- package/dist/field-editor-rich-text.cjs.development.js +78 -15
- 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 +80 -17
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/plugins/List/index.d.ts +1 -0
- package/dist/plugins/Table/index.d.ts +1 -1
- package/package.json +9 -9
|
@@ -27,6 +27,7 @@ var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
|
27
27
|
var moment = _interopDefault(require('moment'));
|
|
28
28
|
var mimetype = _interopDefault(require('@contentful/mimetype'));
|
|
29
29
|
var plateTable = require('@udecode/plate-table');
|
|
30
|
+
var richTextPlainTextRenderer = require('@contentful/rich-text-plain-text-renderer');
|
|
30
31
|
var plateHtmlSerializer = require('@udecode/plate-html-serializer');
|
|
31
32
|
var plateParagraph = require('@udecode/plate-paragraph');
|
|
32
33
|
var plateBreak = require('@udecode/plate-break');
|
|
@@ -1135,6 +1136,11 @@ var withListOptions = (_withListOptions = {}, _withListOptions[plateList.ELEMENT
|
|
|
1135
1136
|
type: Contentful.BLOCKS.OL_LIST,
|
|
1136
1137
|
component: OL
|
|
1137
1138
|
}, _withListOptions);
|
|
1139
|
+
var createListPlugin = function createListPlugin() {
|
|
1140
|
+
return plateList.createListPlugin({
|
|
1141
|
+
validLiChildrenTypes: Contentful.LIST_ITEM_BLOCKS
|
|
1142
|
+
});
|
|
1143
|
+
};
|
|
1138
1144
|
|
|
1139
1145
|
var _withBoldOptions;
|
|
1140
1146
|
function ToolbarBoldButton(props) {
|
|
@@ -2420,13 +2426,17 @@ function FetchingWrappedEntryCard(props) {
|
|
|
2420
2426
|
|
|
2421
2427
|
var entry = entries[props.entryId];
|
|
2422
2428
|
var contentType = React.useMemo(function () {
|
|
2429
|
+
if (!entry || entry === 'failed') {
|
|
2430
|
+
return undefined;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2423
2433
|
return props.sdk.space.getCachedContentTypes().find(function (contentType) {
|
|
2424
|
-
return contentType.sys.id ===
|
|
2434
|
+
return contentType.sys.id === entry.sys.contentType.sys.id;
|
|
2425
2435
|
});
|
|
2426
2436
|
}, [props.sdk, entry]);
|
|
2427
2437
|
var defaultLocaleCode = props.sdk.locales["default"];
|
|
2428
2438
|
React.useEffect(function () {
|
|
2429
|
-
if (!entry) return;
|
|
2439
|
+
if (!entry || entry === 'failed') return;
|
|
2430
2440
|
fieldEditorShared.entityHelpers.getEntryImage({
|
|
2431
2441
|
entry: entry,
|
|
2432
2442
|
contentType: contentType,
|
|
@@ -2558,13 +2568,15 @@ function AssetDropdownMenu(_ref) {
|
|
|
2558
2568
|
}
|
|
2559
2569
|
|
|
2560
2570
|
function FetchingWrappedAssetCard(props) {
|
|
2571
|
+
var _asset$fields;
|
|
2572
|
+
|
|
2561
2573
|
var _useEntities = fieldEditorReference.useEntities(),
|
|
2562
2574
|
getOrLoadAsset = _useEntities.getOrLoadAsset,
|
|
2563
2575
|
assets = _useEntities.assets;
|
|
2564
2576
|
|
|
2565
2577
|
var asset = assets[props.assetId];
|
|
2566
2578
|
var defaultLocaleCode = props.sdk.locales["default"];
|
|
2567
|
-
var entityFile = asset != null && asset.fields.file ? asset.fields.file[props.locale] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
2579
|
+
var entityFile = asset != null && (_asset$fields = asset.fields) != null && _asset$fields.file ? asset.fields.file[props.locale] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
2568
2580
|
React.useEffect(function () {
|
|
2569
2581
|
getOrLoadAsset(props.assetId);
|
|
2570
2582
|
}, [props.assetId]); // eslint-disable-line
|
|
@@ -3634,6 +3646,15 @@ var TableActions = function TableActions() {
|
|
|
3634
3646
|
|
|
3635
3647
|
var _templateObject$4, _templateObject2$3, _templateObject3$3, _templateObject4$1, _styles$1, _withTableOptions;
|
|
3636
3648
|
var styles$g = (_styles$1 = {}, _styles$1[Contentful.BLOCKS.TABLE] = /*#__PURE__*/emotion.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[Contentful.BLOCKS.TABLE_ROW] = /*#__PURE__*/emotion.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[Contentful.BLOCKS.TABLE_HEADER_CELL] = /*#__PURE__*/emotion.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[Contentful.BLOCKS.TABLE_CELL] = /*#__PURE__*/emotion.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);
|
|
3649
|
+
|
|
3650
|
+
var slateNodeToText = function slateNodeToText(node) {
|
|
3651
|
+
var contentfulNode = contentfulSlatejsAdapter.toContentfulDocument({
|
|
3652
|
+
document: [node],
|
|
3653
|
+
schema: schema
|
|
3654
|
+
});
|
|
3655
|
+
return richTextPlainTextRenderer.documentToPlainTextString(contentfulNode);
|
|
3656
|
+
};
|
|
3657
|
+
|
|
3637
3658
|
var Table = function Table(props) {
|
|
3638
3659
|
return /*#__PURE__*/React.createElement("table", Object.assign({}, props.attributes, {
|
|
3639
3660
|
className: styles$g[Contentful.BLOCKS.TABLE]
|
|
@@ -3695,6 +3716,14 @@ function addTableTrackingEvents(editor, _ref) {
|
|
|
3695
3716
|
};
|
|
3696
3717
|
}
|
|
3697
3718
|
|
|
3719
|
+
var paragraph = function paragraph() {
|
|
3720
|
+
return {
|
|
3721
|
+
type: Contentful.BLOCKS.PARAGRAPH,
|
|
3722
|
+
data: {},
|
|
3723
|
+
children: []
|
|
3724
|
+
};
|
|
3725
|
+
};
|
|
3726
|
+
|
|
3698
3727
|
function addTableNormalization(editor) {
|
|
3699
3728
|
var normalizeNode = editor.normalizeNode;
|
|
3700
3729
|
|
|
@@ -3713,12 +3742,20 @@ function addTableNormalization(editor) {
|
|
|
3713
3742
|
childPath = _step$value[1];
|
|
3714
3743
|
|
|
3715
3744
|
if (slate.Text.isText(child)) {
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
}
|
|
3721
|
-
|
|
3745
|
+
slate.Transforms.wrapNodes(editor, paragraph(), {
|
|
3746
|
+
at: childPath
|
|
3747
|
+
});
|
|
3748
|
+
} else if (!Contentful.CONTAINERS[node.type].includes(child.type)) {
|
|
3749
|
+
var paragraphWithTextFromNode = _extends({}, paragraph(), {
|
|
3750
|
+
children: [{
|
|
3751
|
+
text: slateNodeToText(child)
|
|
3752
|
+
}]
|
|
3753
|
+
});
|
|
3754
|
+
|
|
3755
|
+
slate.Transforms.removeNodes(editor, {
|
|
3756
|
+
at: childPath
|
|
3757
|
+
});
|
|
3758
|
+
slate.Transforms.insertNodes(editor, paragraphWithTextFromNode, {
|
|
3722
3759
|
at: childPath
|
|
3723
3760
|
});
|
|
3724
3761
|
}
|
|
@@ -3764,7 +3801,34 @@ function createWithTableEvents(tracking) {
|
|
|
3764
3801
|
|
|
3765
3802
|
var createTablePlugin = function createTablePlugin(tracking) {
|
|
3766
3803
|
return _extends({}, plateTable.createTablePlugin(), {
|
|
3767
|
-
onKeyDown: createWithTableEvents(tracking)
|
|
3804
|
+
onKeyDown: createWithTableEvents(tracking),
|
|
3805
|
+
withOverrides: function withOverrides(editor) {
|
|
3806
|
+
var insertFragment = editor.insertFragment;
|
|
3807
|
+
|
|
3808
|
+
editor.insertFragment = function (fragments) {
|
|
3809
|
+
// We need to make sure we have a new, empty and clean paragraph in order to paste tables as-is due to how Slate behaves
|
|
3810
|
+
// More info: https://github.com/ianstormtaylor/slate/pull/4489 and https://github.com/ianstormtaylor/slate/issues/4542
|
|
3811
|
+
var fragmentHasTable = fragments.some(function (fragment) {
|
|
3812
|
+
return fragment.type === Contentful.BLOCKS.TABLE;
|
|
3813
|
+
});
|
|
3814
|
+
|
|
3815
|
+
if (fragmentHasTable) {
|
|
3816
|
+
var emptyParagraph = {
|
|
3817
|
+
type: Contentful.BLOCKS.PARAGRAPH,
|
|
3818
|
+
children: [{
|
|
3819
|
+
text: ''
|
|
3820
|
+
}],
|
|
3821
|
+
data: {},
|
|
3822
|
+
isVoid: false
|
|
3823
|
+
};
|
|
3824
|
+
slate.Transforms.insertNodes(editor, emptyParagraph);
|
|
3825
|
+
}
|
|
3826
|
+
|
|
3827
|
+
insertFragment(fragments);
|
|
3828
|
+
};
|
|
3829
|
+
|
|
3830
|
+
return editor;
|
|
3831
|
+
}
|
|
3768
3832
|
});
|
|
3769
3833
|
};
|
|
3770
3834
|
function ToolbarTableButton(props) {
|
|
@@ -4242,7 +4306,7 @@ function FetchingWrappedInlineEntryCard(props) {
|
|
|
4242
4306
|
}, [entries, props.entryId]);
|
|
4243
4307
|
var allContentTypes = props.sdk.space.getCachedContentTypes();
|
|
4244
4308
|
var contentType = React__default.useMemo(function () {
|
|
4245
|
-
if (!entry || !allContentTypes) return undefined;
|
|
4309
|
+
if (!entry || entry === 'failed' || !allContentTypes) return undefined;
|
|
4246
4310
|
return allContentTypes.find(function (contentType) {
|
|
4247
4311
|
return contentType.sys.id === entry.sys.contentType.sys.id;
|
|
4248
4312
|
});
|
|
@@ -4732,7 +4796,7 @@ var removeComments = function removeComments(_ref) {
|
|
|
4732
4796
|
|
|
4733
4797
|
var TAG_NAME_TABLE = 'TABLE';
|
|
4734
4798
|
var TAG_NAME_TABLE_CAPTION = 'CAPTION';
|
|
4735
|
-
var DISALLOWED_TABLE_CHILD_ELEMENTS = [
|
|
4799
|
+
var DISALLOWED_TABLE_CHILD_ELEMENTS = [TAG_NAME_TABLE_CAPTION];
|
|
4736
4800
|
|
|
4737
4801
|
var isHTMLElement = function isHTMLElement(node) {
|
|
4738
4802
|
return node.nodeType === Node.ELEMENT_NODE;
|
|
@@ -4857,9 +4921,8 @@ function createParagraphPlugin() {
|
|
|
4857
4921
|
type: Contentful.BLOCKS.PARAGRAPH,
|
|
4858
4922
|
deserialize: function deserialize(element) {
|
|
4859
4923
|
var isParagraphText = element.nodeName === 'P';
|
|
4860
|
-
var isDivText = element.nodeName === 'DIV' && !element.getAttribute('data-entity-type');
|
|
4861
4924
|
var isNotEmpty = element.textContent !== '';
|
|
4862
|
-
var isText =
|
|
4925
|
+
var isText = isParagraphText && isNotEmpty;
|
|
4863
4926
|
if (!isText) return;
|
|
4864
4927
|
return {
|
|
4865
4928
|
type: Contentful.BLOCKS.PARAGRAPH
|
|
@@ -5023,7 +5086,7 @@ var getPlugins = function getPlugins(sdk, tracking) {
|
|
|
5023
5086
|
plateCore.createReactPlugin(), plateCore.createHistoryPlugin(), // Behavior
|
|
5024
5087
|
createPastePlugin(), // Global shortcuts
|
|
5025
5088
|
createNewLinePlugin(), createInsertBeforeFirstVoidBlockPlugin(), // Block Elements
|
|
5026
|
-
createParagraphPlugin(),
|
|
5089
|
+
createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
|
|
5027
5090
|
createHyperlinkPlugin(sdk), createEmbeddedEntityInlinePlugin(sdk), // Marks
|
|
5028
5091
|
createBoldPlugin(), createCodePlugin(), createItalicPlugin(), createUnderlinePlugin(), // Other
|
|
5029
5092
|
createTrailingParagraphPlugin()];
|