@contentful/field-editor-rich-text 0.23.0-next → 0.24.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/dist/ContentfulEditorProvider.d.ts +2 -2
- package/dist/field-editor-rich-text.cjs.development.js +637 -150
- 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 +644 -157
- package/dist/field-editor-rich-text.esm.js.map +1 -1
- package/dist/plugins/EmbeddedEntityBlock/LinkedEntityBlock.d.ts +0 -2
- package/dist/plugins/EmbeddedEntityBlock/index.d.ts +3 -2
- package/dist/plugins/Paste/index.d.ts +2 -0
- package/dist/plugins/Paste/sanitizers/helpers.d.ts +5 -0
- package/dist/plugins/Paste/sanitizers/index.d.ts +2 -0
- package/dist/plugins/Paste/sanitizers/removeComments.d.ts +2 -0
- package/dist/plugins/Paste/sanitizers/sanitizeTables.d.ts +2 -0
- package/dist/plugins/Table/index.d.ts +159 -159
- package/dist/plugins/shared/EntityStatusIcon.d.ts +8 -0
- package/dist/plugins/shared/FetchingWrappedAssetCard.d.ts +0 -2
- package/dist/plugins/shared/FetchingWrappedEntryCard.d.ts +2 -4
- package/package.json +17 -16
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import React__default, {
|
|
1
|
+
import React__default, { useState, useEffect, createElement, useMemo, Fragment, useCallback } from 'react';
|
|
2
2
|
import noop from 'lodash-es/noop';
|
|
3
3
|
import { toSlatejsDocument, toContentfulDocument } from '@contentful/contentful-slatejs-adapter';
|
|
4
4
|
import { TOP_LEVEL_BLOCKS, BLOCKS, CONTAINERS, VOID_BLOCKS, INLINES, MARKS, EMPTY_DOCUMENT } from '@contentful/rich-text-types';
|
|
5
|
-
import { useEntities,
|
|
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';
|
|
8
8
|
import deepEquals from 'fast-deep-equal';
|
|
9
|
-
import { EditorToolbarButton, Dropdown, Button, DropdownList, DropdownListItem, Tag, Paragraph as Paragraph$1, EntryCard, AssetCard, Modal, Form, TextField, SelectField, Option, FormLabel, TextLink, Tooltip, IconButton, Flex,
|
|
9
|
+
import { EditorToolbarButton, Dropdown, Button, DropdownList, DropdownListItem, Tag, Paragraph as Paragraph$1, Icon, EntryCard, AssetCard, Modal, Form, TextField, SelectField, Option, FormLabel, TextLink, Tooltip, IconButton, Flex, InlineEntryCard, EditorToolbar, EditorToolbarDivider } from '@contentful/forma-36-react-components';
|
|
10
10
|
import { useSelected, useFocused, ReactEditor, useReadOnly } from 'slate-react';
|
|
11
|
-
import { Editor, Transforms, Element, Text, Range, Path, Node } from 'slate';
|
|
11
|
+
import { Editor, Transforms, Element, Text, Range, Path, Node as Node$1 } from 'slate';
|
|
12
12
|
import { getPlatePluginOptions, useStoreEditorRef, getRenderElement, getPlatePluginTypes, getRenderLeaf, getPlatePluginType, Plate, createReactPlugin, createHistoryPlugin } from '@udecode/plate-core';
|
|
13
13
|
import { getElementDeserializer, getLeafDeserializer, getText, setNodes, insertNodes, toggleNodeType, getToggleMarkOnKeyDown, isMarkActive, toggleMark, getAbove, getChildren, someNode, getToggleElementOnKeyDown } from '@udecode/plate-common';
|
|
14
14
|
import constate from 'constate';
|
|
@@ -16,8 +16,9 @@ import find from 'lodash-es/find';
|
|
|
16
16
|
import flow from 'lodash-es/flow';
|
|
17
17
|
import get from 'lodash-es/get';
|
|
18
18
|
import { ELEMENT_LIC, ELEMENT_LI, ELEMENT_UL, ELEMENT_OL, toggleList, createListPlugin } from '@udecode/plate-list';
|
|
19
|
-
import { entityHelpers, ModalDialogLauncher, FieldConnector } from '@contentful/field-editor-shared';
|
|
19
|
+
import { entityHelpers, isValidImage, shortenStorageUnit, ModalDialogLauncher, FieldConnector } from '@contentful/field-editor-shared';
|
|
20
20
|
import moment from 'moment';
|
|
21
|
+
import mimetype from '@contentful/mimetype';
|
|
21
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';
|
|
22
23
|
import { createDeserializeHTMLPlugin } from '@udecode/plate-html-serializer';
|
|
23
24
|
import { ELEMENT_PARAGRAPH } from '@udecode/plate-paragraph';
|
|
@@ -120,6 +121,44 @@ function _taggedTemplateLiteralLoose(strings, raw) {
|
|
|
120
121
|
return strings;
|
|
121
122
|
}
|
|
122
123
|
|
|
124
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
125
|
+
if (!o) return;
|
|
126
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
127
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
128
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
129
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
130
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function _arrayLikeToArray(arr, len) {
|
|
134
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
135
|
+
|
|
136
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
137
|
+
|
|
138
|
+
return arr2;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
142
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
143
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
144
|
+
|
|
145
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
146
|
+
if (it) o = it;
|
|
147
|
+
var i = 0;
|
|
148
|
+
return function () {
|
|
149
|
+
if (i >= o.length) return {
|
|
150
|
+
done: true
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
done: false,
|
|
154
|
+
value: o[i++]
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
160
|
+
}
|
|
161
|
+
|
|
123
162
|
var STYLE_EDITOR_BORDER = "1px solid " + tokens.gray400;
|
|
124
163
|
var styles = {
|
|
125
164
|
root: /*#__PURE__*/css({
|
|
@@ -504,9 +543,25 @@ function getContentfulEditorId(sdk) {
|
|
|
504
543
|
}
|
|
505
544
|
|
|
506
545
|
function useContentfulEditorHook(_ref) {
|
|
546
|
+
var _editor$selection;
|
|
547
|
+
|
|
507
548
|
var sdk = _ref.sdk;
|
|
508
549
|
var editorId = getContentfulEditorId(sdk);
|
|
509
550
|
var editor = useStoreEditorRef(editorId);
|
|
551
|
+
|
|
552
|
+
var _React$useState = useState((_editor$selection = editor == null ? void 0 : editor.selection) != null ? _editor$selection : null),
|
|
553
|
+
selection = _React$useState[0],
|
|
554
|
+
setSelection = _React$useState[1];
|
|
555
|
+
|
|
556
|
+
useEffect(function () {
|
|
557
|
+
if (!(editor != null && editor.selection)) return;
|
|
558
|
+
setSelection(editor.selection);
|
|
559
|
+
}, [editor == null ? void 0 : editor.selection]);
|
|
560
|
+
|
|
561
|
+
if (editor && !(editor != null && editor.selection) && selection) {
|
|
562
|
+
editor.selection = selection;
|
|
563
|
+
}
|
|
564
|
+
|
|
510
565
|
return editor;
|
|
511
566
|
}
|
|
512
567
|
|
|
@@ -548,7 +603,8 @@ function withHrEvents(editor) {
|
|
|
548
603
|
function ToolbarHrButton(props) {
|
|
549
604
|
var editor = useContentfulEditor();
|
|
550
605
|
|
|
551
|
-
function handleOnClick() {
|
|
606
|
+
function handleOnClick(event) {
|
|
607
|
+
event.preventDefault();
|
|
552
608
|
if (!(editor != null && editor.selection)) return;
|
|
553
609
|
|
|
554
610
|
if (shouldUnwrapBlockquote(editor, BLOCKS.HR)) {
|
|
@@ -577,7 +633,8 @@ function ToolbarHrButton(props) {
|
|
|
577
633
|
tooltipPlace: "bottom",
|
|
578
634
|
label: "HR",
|
|
579
635
|
disabled: props.isDisabled,
|
|
580
|
-
|
|
636
|
+
// @ts-expect-error
|
|
637
|
+
onMouseDown: handleOnClick,
|
|
581
638
|
testId: "hr-toolbar-button",
|
|
582
639
|
isActive: isBlockSelected(editor, BLOCKS.HR)
|
|
583
640
|
});
|
|
@@ -693,7 +750,7 @@ function withHeadingEvents(editor) {
|
|
|
693
750
|
|
|
694
751
|
if (hasSelectionText(editor)) {
|
|
695
752
|
var currentOffset = editor.selection.focus.offset;
|
|
696
|
-
var currentTextLength = Node.string(currentFragment).length;
|
|
753
|
+
var currentTextLength = Node$1.string(currentFragment).length;
|
|
697
754
|
var cursorIsAtTheBeginning = currentOffset === 0;
|
|
698
755
|
var cursorIsAtTheEnd = currentTextLength === currentOffset;
|
|
699
756
|
|
|
@@ -775,19 +832,22 @@ function ToolbarHeadingButton(props) {
|
|
|
775
832
|
someHeadingsEnabled = _React$useMemo[1];
|
|
776
833
|
|
|
777
834
|
function handleOnSelectItem(type) {
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
835
|
+
return function (event) {
|
|
836
|
+
event.preventDefault();
|
|
837
|
+
if (!(editor != null && editor.selection)) return;
|
|
838
|
+
setSelected(type);
|
|
839
|
+
setOpen(false);
|
|
781
840
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
841
|
+
if (shouldUnwrapBlockquote(editor, type)) {
|
|
842
|
+
unwrapFromRoot(editor);
|
|
843
|
+
}
|
|
785
844
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
845
|
+
toggleNodeType(editor, {
|
|
846
|
+
activeType: type,
|
|
847
|
+
inactiveType: type
|
|
848
|
+
});
|
|
849
|
+
ReactEditor.focus(editor);
|
|
850
|
+
};
|
|
791
851
|
}
|
|
792
852
|
|
|
793
853
|
if (!editor) return null;
|
|
@@ -811,9 +871,7 @@ function ToolbarHeadingButton(props) {
|
|
|
811
871
|
return nodeTypesByEnablement[nodeType] && /*#__PURE__*/createElement(DropdownListItem, {
|
|
812
872
|
key: nodeType,
|
|
813
873
|
isActive: selected === nodeType,
|
|
814
|
-
|
|
815
|
-
return handleOnSelectItem(nodeType);
|
|
816
|
-
},
|
|
874
|
+
onMouseDown: handleOnSelectItem(nodeType),
|
|
817
875
|
testId: "dropdown-option-" + nodeType,
|
|
818
876
|
isDisabled: props.isDisabled
|
|
819
877
|
}, /*#__PURE__*/createElement("span", {
|
|
@@ -919,7 +977,7 @@ function withQuoteEvents(editor) {
|
|
|
919
977
|
|
|
920
978
|
if (hasSelectionText(editor)) {
|
|
921
979
|
var currentOffset = editor.selection.focus.offset;
|
|
922
|
-
var currentTextLength = Node.string(currentFragment).length;
|
|
980
|
+
var currentTextLength = Node$1.string(currentFragment).length;
|
|
923
981
|
var cursorIsAtTheBeginning = currentOffset === 0;
|
|
924
982
|
var cursorIsAtTheEnd = currentTextLength === currentOffset;
|
|
925
983
|
|
|
@@ -962,7 +1020,8 @@ function withQuoteEvents(editor) {
|
|
|
962
1020
|
function ToolbarQuoteButton(props) {
|
|
963
1021
|
var editor = useContentfulEditor();
|
|
964
1022
|
|
|
965
|
-
function handleOnClick() {
|
|
1023
|
+
function handleOnClick(event) {
|
|
1024
|
+
event.preventDefault();
|
|
966
1025
|
if (!editor) return;
|
|
967
1026
|
createBlockQuote(editor);
|
|
968
1027
|
ReactEditor.focus(editor);
|
|
@@ -974,7 +1033,8 @@ function ToolbarQuoteButton(props) {
|
|
|
974
1033
|
tooltip: "Blockquote",
|
|
975
1034
|
tooltipPlace: "bottom",
|
|
976
1035
|
label: "Blockquote",
|
|
977
|
-
|
|
1036
|
+
// @ts-expect-error
|
|
1037
|
+
onMouseDown: handleOnClick,
|
|
978
1038
|
testId: "quote-toolbar-button",
|
|
979
1039
|
disabled: props.isDisabled,
|
|
980
1040
|
isActive: isBlockSelected(editor, BLOCKS.QUOTE)
|
|
@@ -1006,16 +1066,19 @@ function ToolbarListButton(props) {
|
|
|
1006
1066
|
var editor = useContentfulEditor();
|
|
1007
1067
|
|
|
1008
1068
|
function handleClick(type) {
|
|
1009
|
-
|
|
1069
|
+
return function (event) {
|
|
1070
|
+
event.preventDefault();
|
|
1071
|
+
if (!(editor != null && editor.selection)) return;
|
|
1010
1072
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1073
|
+
if (shouldUnwrapBlockquote(editor, type)) {
|
|
1074
|
+
unwrapFromRoot(editor);
|
|
1075
|
+
}
|
|
1014
1076
|
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1077
|
+
toggleList(editor, {
|
|
1078
|
+
type: type
|
|
1079
|
+
});
|
|
1080
|
+
ReactEditor.focus(editor);
|
|
1081
|
+
};
|
|
1019
1082
|
}
|
|
1020
1083
|
|
|
1021
1084
|
if (!editor) return null;
|
|
@@ -1025,9 +1088,8 @@ function ToolbarListButton(props) {
|
|
|
1025
1088
|
tooltipPlace: "bottom",
|
|
1026
1089
|
label: "UL",
|
|
1027
1090
|
testId: "ul-toolbar-button",
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
},
|
|
1091
|
+
// @ts-expect-error
|
|
1092
|
+
onMouseDown: handleClick(BLOCKS.UL_LIST),
|
|
1031
1093
|
isActive: isBlockSelected(editor, BLOCKS.UL_LIST),
|
|
1032
1094
|
disabled: props.isDisabled
|
|
1033
1095
|
}), isNodeTypeEnabled(sdk.field, BLOCKS.OL_LIST) && /*#__PURE__*/createElement(EditorToolbarButton, {
|
|
@@ -1036,9 +1098,8 @@ function ToolbarListButton(props) {
|
|
|
1036
1098
|
tooltipPlace: "bottom",
|
|
1037
1099
|
label: "OL",
|
|
1038
1100
|
testId: "ol-toolbar-button",
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
},
|
|
1101
|
+
// @ts-expect-error
|
|
1102
|
+
onMouseDown: handleClick(BLOCKS.OL_LIST),
|
|
1042
1103
|
isActive: isBlockSelected(editor, BLOCKS.OL_LIST),
|
|
1043
1104
|
disabled: props.isDisabled
|
|
1044
1105
|
}));
|
|
@@ -1072,7 +1133,8 @@ var _withBoldOptions;
|
|
|
1072
1133
|
function ToolbarBoldButton(props) {
|
|
1073
1134
|
var editor = useContentfulEditor();
|
|
1074
1135
|
|
|
1075
|
-
function handleClick() {
|
|
1136
|
+
function handleClick(event) {
|
|
1137
|
+
event.preventDefault();
|
|
1076
1138
|
if (!(editor != null && editor.selection)) return;
|
|
1077
1139
|
toggleMark(editor, MARKS.BOLD);
|
|
1078
1140
|
ReactEditor.focus(editor);
|
|
@@ -1085,7 +1147,8 @@ function ToolbarBoldButton(props) {
|
|
|
1085
1147
|
tooltipPlace: "bottom",
|
|
1086
1148
|
label: "Bold",
|
|
1087
1149
|
testId: "bold-toolbar-button",
|
|
1088
|
-
|
|
1150
|
+
// @ts-expect-error
|
|
1151
|
+
onMouseDown: handleClick,
|
|
1089
1152
|
isActive: isMarkActive(editor, MARKS.BOLD),
|
|
1090
1153
|
disabled: props.isDisabled
|
|
1091
1154
|
});
|
|
@@ -1133,7 +1196,8 @@ var _withCodeOptions;
|
|
|
1133
1196
|
function ToolbarCodeButton(props) {
|
|
1134
1197
|
var editor = useContentfulEditor();
|
|
1135
1198
|
|
|
1136
|
-
function handleClick() {
|
|
1199
|
+
function handleClick(event) {
|
|
1200
|
+
event.preventDefault();
|
|
1137
1201
|
if (!(editor != null && editor.selection)) return;
|
|
1138
1202
|
toggleMark(editor, MARKS.CODE);
|
|
1139
1203
|
ReactEditor.focus(editor);
|
|
@@ -1146,7 +1210,8 @@ function ToolbarCodeButton(props) {
|
|
|
1146
1210
|
tooltipPlace: "bottom",
|
|
1147
1211
|
label: "Code",
|
|
1148
1212
|
testId: "code-toolbar-button",
|
|
1149
|
-
|
|
1213
|
+
// @ts-expect-error
|
|
1214
|
+
onMouseDown: handleClick,
|
|
1150
1215
|
isActive: isMarkActive(editor, MARKS.CODE),
|
|
1151
1216
|
disabled: props.isDisabled
|
|
1152
1217
|
});
|
|
@@ -1187,7 +1252,8 @@ var _withItalicOptions;
|
|
|
1187
1252
|
function ToolbarItalicButton(props) {
|
|
1188
1253
|
var editor = useContentfulEditor();
|
|
1189
1254
|
|
|
1190
|
-
function handleClick() {
|
|
1255
|
+
function handleClick(event) {
|
|
1256
|
+
event.preventDefault();
|
|
1191
1257
|
if (!(editor != null && editor.selection)) return;
|
|
1192
1258
|
toggleMark(editor, MARKS.ITALIC);
|
|
1193
1259
|
ReactEditor.focus(editor);
|
|
@@ -1200,7 +1266,8 @@ function ToolbarItalicButton(props) {
|
|
|
1200
1266
|
tooltipPlace: "bottom",
|
|
1201
1267
|
label: "Italic",
|
|
1202
1268
|
testId: "italic-toolbar-button",
|
|
1203
|
-
|
|
1269
|
+
// @ts-expect-error
|
|
1270
|
+
onMouseDown: handleClick,
|
|
1204
1271
|
isActive: isMarkActive(editor, MARKS.ITALIC),
|
|
1205
1272
|
disabled: props.isDisabled
|
|
1206
1273
|
});
|
|
@@ -1240,7 +1307,8 @@ var _withUnderlineOptions;
|
|
|
1240
1307
|
function ToolbarUnderlineButton(props) {
|
|
1241
1308
|
var editor = useContentfulEditor();
|
|
1242
1309
|
|
|
1243
|
-
function handleClick() {
|
|
1310
|
+
function handleClick(event) {
|
|
1311
|
+
event.preventDefault();
|
|
1244
1312
|
if (!(editor != null && editor.selection)) return;
|
|
1245
1313
|
toggleMark(editor, MARKS.UNDERLINE);
|
|
1246
1314
|
ReactEditor.focus(editor);
|
|
@@ -1253,7 +1321,8 @@ function ToolbarUnderlineButton(props) {
|
|
|
1253
1321
|
tooltipPlace: "bottom",
|
|
1254
1322
|
label: "Underline",
|
|
1255
1323
|
testId: "underline-toolbar-button",
|
|
1256
|
-
|
|
1324
|
+
// @ts-expect-error
|
|
1325
|
+
onMouseDown: handleClick,
|
|
1257
1326
|
isActive: isMarkActive(editor, MARKS.UNDERLINE),
|
|
1258
1327
|
disabled: props.isDisabled
|
|
1259
1328
|
});
|
|
@@ -2278,26 +2347,97 @@ function EntryAssetTooltip(_ref) {
|
|
|
2278
2347
|
})));
|
|
2279
2348
|
}
|
|
2280
2349
|
|
|
2350
|
+
var styles$a = {
|
|
2351
|
+
scheduleIcon: /*#__PURE__*/css({
|
|
2352
|
+
marginRight: tokens.spacing2Xs
|
|
2353
|
+
})
|
|
2354
|
+
};
|
|
2355
|
+
function EntityStatusIcon(_ref) {
|
|
2356
|
+
var entity = _ref.entity,
|
|
2357
|
+
entityType = _ref.entityType;
|
|
2358
|
+
|
|
2359
|
+
var _useEntities = useEntities(),
|
|
2360
|
+
loadEntityScheduledActions = _useEntities.loadEntityScheduledActions;
|
|
2361
|
+
|
|
2362
|
+
return /*#__PURE__*/createElement(ScheduledIconWithTooltip, {
|
|
2363
|
+
getEntityScheduledActions: loadEntityScheduledActions,
|
|
2364
|
+
entityType: entityType,
|
|
2365
|
+
entityId: entity.sys.id
|
|
2366
|
+
}, /*#__PURE__*/createElement(Icon, {
|
|
2367
|
+
className: styles$a.scheduleIcon,
|
|
2368
|
+
icon: "Clock",
|
|
2369
|
+
size: "small",
|
|
2370
|
+
color: "muted",
|
|
2371
|
+
testId: "schedule-icon"
|
|
2372
|
+
}));
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
var styles$b = {
|
|
2376
|
+
entryCard: /*#__PURE__*/css({
|
|
2377
|
+
cursor: 'pointer'
|
|
2378
|
+
})
|
|
2379
|
+
};
|
|
2380
|
+
|
|
2381
|
+
function EntryThumbnail(_ref) {
|
|
2382
|
+
var file = _ref.file;
|
|
2383
|
+
if (!isValidImage(file)) return null;
|
|
2384
|
+
return /*#__PURE__*/createElement(AssetThumbnail, {
|
|
2385
|
+
file: file
|
|
2386
|
+
});
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
function EntryDropdownMenu(_ref2) {
|
|
2390
|
+
var onEdit = _ref2.onEdit,
|
|
2391
|
+
onRemove = _ref2.onRemove,
|
|
2392
|
+
isDisabled = _ref2.isDisabled;
|
|
2393
|
+
return /*#__PURE__*/createElement(DropdownList, null, /*#__PURE__*/createElement(DropdownListItem, {
|
|
2394
|
+
isTitle: true
|
|
2395
|
+
}, "Actions"), /*#__PURE__*/createElement(DropdownListItem, {
|
|
2396
|
+
onClick: onEdit,
|
|
2397
|
+
testId: "card-action-edit"
|
|
2398
|
+
}, "Edit"), /*#__PURE__*/createElement(DropdownListItem, {
|
|
2399
|
+
onClick: onRemove,
|
|
2400
|
+
isDisabled: isDisabled,
|
|
2401
|
+
testId: "card-action-remove"
|
|
2402
|
+
}, "Remove"));
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2281
2405
|
function FetchingWrappedEntryCard(props) {
|
|
2282
2406
|
var _useEntities = useEntities(),
|
|
2283
2407
|
getOrLoadEntry = _useEntities.getOrLoadEntry,
|
|
2284
|
-
loadEntityScheduledActions = _useEntities.loadEntityScheduledActions,
|
|
2285
2408
|
entries = _useEntities.entries;
|
|
2286
2409
|
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2410
|
+
var _React$useState = useState(null),
|
|
2411
|
+
file = _React$useState[0],
|
|
2412
|
+
setFile = _React$useState[1];
|
|
2290
2413
|
|
|
2291
2414
|
var entry = entries[props.entryId];
|
|
2415
|
+
var contentType = useMemo(function () {
|
|
2416
|
+
return props.sdk.space.getCachedContentTypes().find(function (contentType) {
|
|
2417
|
+
return contentType.sys.id === (entry == null ? void 0 : entry.sys.contentType.sys.id);
|
|
2418
|
+
});
|
|
2419
|
+
}, [props.sdk, entry]);
|
|
2420
|
+
var defaultLocaleCode = props.sdk.locales["default"];
|
|
2292
2421
|
useEffect(function () {
|
|
2293
2422
|
if (!entry) return;
|
|
2294
|
-
|
|
2295
|
-
|
|
2423
|
+
entityHelpers.getEntryImage({
|
|
2424
|
+
entry: entry,
|
|
2425
|
+
contentType: contentType,
|
|
2426
|
+
localeCode: props.locale,
|
|
2427
|
+
defaultLocaleCode: defaultLocaleCode
|
|
2428
|
+
}, props.sdk.space.getAsset).then(setFile)["catch"](function () {
|
|
2429
|
+
return setFile(null);
|
|
2430
|
+
});
|
|
2431
|
+
}, [entry, contentType, props.locale, defaultLocaleCode, props.sdk, file]);
|
|
2432
|
+
useEffect(function () {
|
|
2433
|
+
getOrLoadEntry(props.entryId);
|
|
2434
|
+
}, [props.entryId]); // eslint-disable-line
|
|
2296
2435
|
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2436
|
+
function renderDropdown() {
|
|
2437
|
+
if (!props.onEdit || !props.onRemove) return undefined;
|
|
2438
|
+
return /*#__PURE__*/createElement(EntryDropdownMenu, {
|
|
2300
2439
|
isDisabled: props.isDisabled,
|
|
2440
|
+
onEdit: props.onEdit,
|
|
2301
2441
|
onRemove: props.onRemove
|
|
2302
2442
|
});
|
|
2303
2443
|
}
|
|
@@ -2309,49 +2449,149 @@ function FetchingWrappedEntryCard(props) {
|
|
|
2309
2449
|
});
|
|
2310
2450
|
}
|
|
2311
2451
|
|
|
2312
|
-
|
|
2313
|
-
return
|
|
2452
|
+
if (entry === 'failed') {
|
|
2453
|
+
return /*#__PURE__*/createElement(MissingEntityCard, {
|
|
2454
|
+
entityType: "Entry",
|
|
2455
|
+
isDisabled: props.isDisabled,
|
|
2456
|
+
onRemove: props.onRemove
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
var entryStatus = entry ? entityHelpers.getEntryStatus(entry.sys) : undefined;
|
|
2461
|
+
|
|
2462
|
+
if (entryStatus === 'deleted') {
|
|
2463
|
+
return /*#__PURE__*/createElement(MissingEntityCard, {
|
|
2464
|
+
entityType: "Entry",
|
|
2465
|
+
isDisabled: props.isDisabled,
|
|
2466
|
+
onRemove: props.onRemove
|
|
2467
|
+
});
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
var title = entityHelpers.getEntryTitle({
|
|
2471
|
+
entry: entry,
|
|
2472
|
+
contentType: contentType,
|
|
2473
|
+
localeCode: props.locale,
|
|
2474
|
+
defaultLocaleCode: defaultLocaleCode,
|
|
2475
|
+
defaultTitle: 'Untitled'
|
|
2314
2476
|
});
|
|
2315
|
-
|
|
2477
|
+
var description = entityHelpers.getEntityDescription({
|
|
2478
|
+
entity: entry,
|
|
2316
2479
|
contentType: contentType,
|
|
2317
|
-
defaultLocaleCode: props.sdk.locales["default"],
|
|
2318
|
-
entry: entry,
|
|
2319
|
-
entryUrl: props.getEntryUrl && props.getEntryUrl(entry.sys.id),
|
|
2320
|
-
getAsset: props.sdk.space.getAsset,
|
|
2321
|
-
getEntityScheduledActions: loadEntityScheduledActions,
|
|
2322
|
-
isClickable: false,
|
|
2323
|
-
isDisabled: props.isDisabled,
|
|
2324
|
-
isSelected: props.isSelected,
|
|
2325
2480
|
localeCode: props.locale,
|
|
2326
|
-
|
|
2327
|
-
|
|
2481
|
+
defaultLocaleCode: defaultLocaleCode
|
|
2482
|
+
});
|
|
2483
|
+
return /*#__PURE__*/createElement(EntryCard, {
|
|
2484
|
+
contentType: contentType == null ? void 0 : contentType.name,
|
|
2485
|
+
title: title,
|
|
2486
|
+
description: description,
|
|
2328
2487
|
size: "default",
|
|
2329
|
-
|
|
2488
|
+
selected: props.isSelected,
|
|
2489
|
+
status: entryStatus,
|
|
2490
|
+
className: styles$b.entryCard,
|
|
2491
|
+
thumbnailElement: file ? /*#__PURE__*/createElement(EntryThumbnail, {
|
|
2492
|
+
file: file
|
|
2493
|
+
}) : null,
|
|
2494
|
+
statusIcon: /*#__PURE__*/createElement(EntityStatusIcon, {
|
|
2495
|
+
entityType: "Entry",
|
|
2496
|
+
entity: entry
|
|
2497
|
+
}),
|
|
2498
|
+
dropdownListElements: renderDropdown()
|
|
2330
2499
|
});
|
|
2331
2500
|
}
|
|
2332
2501
|
|
|
2502
|
+
var styles$c = {
|
|
2503
|
+
assetCard: /*#__PURE__*/css({
|
|
2504
|
+
cursor: 'pointer'
|
|
2505
|
+
}),
|
|
2506
|
+
cardDropdown: /*#__PURE__*/css({
|
|
2507
|
+
width: '300px'
|
|
2508
|
+
}),
|
|
2509
|
+
truncated: /*#__PURE__*/css({
|
|
2510
|
+
overflow: 'hidden',
|
|
2511
|
+
whiteSpace: 'nowrap',
|
|
2512
|
+
textOverflow: 'ellipsis'
|
|
2513
|
+
})
|
|
2514
|
+
};
|
|
2515
|
+
|
|
2516
|
+
function AssetDropdownMenu(_ref) {
|
|
2517
|
+
var onEdit = _ref.onEdit,
|
|
2518
|
+
onRemove = _ref.onRemove,
|
|
2519
|
+
isDisabled = _ref.isDisabled,
|
|
2520
|
+
entityFile = _ref.entityFile;
|
|
2521
|
+
var fileName = entityFile.fileName,
|
|
2522
|
+
mimeType = entityFile.contentType,
|
|
2523
|
+
details = entityFile.details;
|
|
2524
|
+
var fileSize = details.size,
|
|
2525
|
+
image = details.image;
|
|
2526
|
+
|
|
2527
|
+
function downloadAsset() {
|
|
2528
|
+
if (!entityFile) return;
|
|
2529
|
+
window.open(entityFile.url, '_blank', 'noopener,noreferrer');
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
return /*#__PURE__*/createElement(Fragment, null, /*#__PURE__*/createElement(DropdownList, null, /*#__PURE__*/createElement(DropdownListItem, {
|
|
2533
|
+
isTitle: true
|
|
2534
|
+
}, "Actions"), onEdit && /*#__PURE__*/createElement(DropdownListItem, {
|
|
2535
|
+
onClick: onEdit,
|
|
2536
|
+
testId: "card-action-edit"
|
|
2537
|
+
}, "Edit"), entityFile && /*#__PURE__*/createElement(DropdownListItem, {
|
|
2538
|
+
onClick: downloadAsset,
|
|
2539
|
+
testId: "card-action-download"
|
|
2540
|
+
}, "Download"), onRemove && /*#__PURE__*/createElement(DropdownListItem, {
|
|
2541
|
+
onClick: onRemove,
|
|
2542
|
+
isDisabled: isDisabled,
|
|
2543
|
+
testId: "card-action-remove"
|
|
2544
|
+
}, "Remove")), /*#__PURE__*/createElement(DropdownList, {
|
|
2545
|
+
border: "top"
|
|
2546
|
+
}, /*#__PURE__*/createElement(DropdownListItem, {
|
|
2547
|
+
isTitle: true
|
|
2548
|
+
}, "File info"), fileName && /*#__PURE__*/createElement(DropdownListItem, null, /*#__PURE__*/createElement("div", {
|
|
2549
|
+
className: styles$c.truncated
|
|
2550
|
+
}, fileName)), mimeType && /*#__PURE__*/createElement(DropdownListItem, null, /*#__PURE__*/createElement("div", null, mimeType)), fileSize && /*#__PURE__*/createElement(DropdownListItem, null, shortenStorageUnit(fileSize, 'B')), image && /*#__PURE__*/createElement(DropdownListItem, null, image.width + " \xD7 " + image.height)));
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2333
2553
|
function FetchingWrappedAssetCard(props) {
|
|
2334
2554
|
var _useEntities = useEntities(),
|
|
2335
2555
|
getOrLoadAsset = _useEntities.getOrLoadAsset,
|
|
2336
|
-
loadEntityScheduledActions = _useEntities.loadEntityScheduledActions,
|
|
2337
2556
|
assets = _useEntities.assets;
|
|
2338
2557
|
|
|
2558
|
+
var asset = assets[props.assetId];
|
|
2559
|
+
var defaultLocaleCode = props.sdk.locales["default"];
|
|
2560
|
+
var entityFile = asset != null && asset.fields.file ? asset.fields.file[props.locale] || asset.fields.file[defaultLocaleCode] : undefined;
|
|
2339
2561
|
useEffect(function () {
|
|
2340
2562
|
getOrLoadAsset(props.assetId);
|
|
2341
2563
|
}, [props.assetId]); // eslint-disable-line
|
|
2342
2564
|
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
}, [asset]); // eslint-disable-line
|
|
2565
|
+
function getAssetSrc() {
|
|
2566
|
+
if (!(entityFile != null && entityFile.url)) return '';
|
|
2567
|
+
return entityFile.url + "?h=300";
|
|
2568
|
+
}
|
|
2348
2569
|
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2570
|
+
function getFileType() {
|
|
2571
|
+
var groupToIconMap = {
|
|
2572
|
+
image: 'image',
|
|
2573
|
+
video: 'video',
|
|
2574
|
+
audio: 'audio',
|
|
2575
|
+
richtext: 'richtext',
|
|
2576
|
+
presentation: 'presentation',
|
|
2577
|
+
spreadsheet: 'spreadsheet',
|
|
2578
|
+
pdfdocument: 'pdf',
|
|
2579
|
+
archive: 'archive',
|
|
2580
|
+
plaintext: 'plaintext',
|
|
2581
|
+
code: 'code',
|
|
2582
|
+
markup: 'markup'
|
|
2583
|
+
};
|
|
2584
|
+
var archive = groupToIconMap['archive'];
|
|
2585
|
+
|
|
2586
|
+
if (!entityFile) {
|
|
2587
|
+
return archive;
|
|
2588
|
+
}
|
|
2589
|
+
|
|
2590
|
+
var groupName = mimetype.getGroupLabel({
|
|
2591
|
+
type: entityFile.contentType,
|
|
2592
|
+
fallbackFileName: entityFile.fileName
|
|
2354
2593
|
});
|
|
2594
|
+
return groupToIconMap[groupName] || archive;
|
|
2355
2595
|
}
|
|
2356
2596
|
|
|
2357
2597
|
if (asset === undefined) {
|
|
@@ -2364,20 +2604,49 @@ function FetchingWrappedAssetCard(props) {
|
|
|
2364
2604
|
});
|
|
2365
2605
|
}
|
|
2366
2606
|
|
|
2367
|
-
|
|
2607
|
+
if (asset === 'failed') {
|
|
2608
|
+
return /*#__PURE__*/createElement(MissingEntityCard, {
|
|
2609
|
+
entityType: "Asset",
|
|
2610
|
+
isDisabled: props.isDisabled,
|
|
2611
|
+
onRemove: props.onRemove
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2615
|
+
var status = asset ? entityHelpers.getEntryStatus(asset.sys) : undefined;
|
|
2616
|
+
|
|
2617
|
+
if (status === 'deleted') {
|
|
2618
|
+
return /*#__PURE__*/createElement(MissingEntityCard, {
|
|
2619
|
+
entityType: "Asset",
|
|
2620
|
+
asSquare: true,
|
|
2621
|
+
isDisabled: props.isDisabled,
|
|
2622
|
+
onRemove: props.onRemove
|
|
2623
|
+
});
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
var entityTitle = entityHelpers.getAssetTitle({
|
|
2368
2627
|
asset: asset,
|
|
2369
|
-
defaultLocaleCode: props.sdk.locales["default"],
|
|
2370
|
-
// @ts-expect-error
|
|
2371
|
-
getAsset: props.sdk.space.getAsset,
|
|
2372
|
-
getAssetUrl: props.getAssetUrl,
|
|
2373
|
-
getEntityScheduledActions: loadEntityScheduledActions,
|
|
2374
|
-
isClickable: false,
|
|
2375
|
-
isDisabled: props.isDisabled,
|
|
2376
|
-
isSelected: props.isSelected,
|
|
2377
2628
|
localeCode: props.locale,
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2629
|
+
defaultLocaleCode: defaultLocaleCode,
|
|
2630
|
+
defaultTitle: 'Untitled'
|
|
2631
|
+
});
|
|
2632
|
+
return /*#__PURE__*/createElement(AssetCard, {
|
|
2633
|
+
title: entityTitle,
|
|
2634
|
+
selected: props.isSelected,
|
|
2635
|
+
size: "default",
|
|
2636
|
+
src: getAssetSrc(),
|
|
2637
|
+
type: getFileType(),
|
|
2638
|
+
status: status,
|
|
2639
|
+
statusIcon: /*#__PURE__*/createElement(EntityStatusIcon, {
|
|
2640
|
+
entityType: "Asset",
|
|
2641
|
+
entity: asset
|
|
2642
|
+
}),
|
|
2643
|
+
className: styles$c.assetCard,
|
|
2644
|
+
dropdownListElements: entityFile && /*#__PURE__*/createElement(AssetDropdownMenu, {
|
|
2645
|
+
onEdit: props.onEdit,
|
|
2646
|
+
onRemove: props.onRemove,
|
|
2647
|
+
isDisabled: props.isDisabled,
|
|
2648
|
+
entityFile: entityFile
|
|
2649
|
+
})
|
|
2381
2650
|
});
|
|
2382
2651
|
}
|
|
2383
2652
|
|
|
@@ -2421,7 +2690,7 @@ function getLinkedContentTypeIdsForNodeType(field, nodeType) {
|
|
|
2421
2690
|
}
|
|
2422
2691
|
|
|
2423
2692
|
var _templateObject$3, _SYS_LINK_TYPES, _LINK_TYPE_SELECTION_;
|
|
2424
|
-
var styles$
|
|
2693
|
+
var styles$d = {
|
|
2425
2694
|
removeSelectionLabel: /*#__PURE__*/css(_templateObject$3 || (_templateObject$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-left: ", ";\n "])), tokens.spacingS)
|
|
2426
2695
|
};
|
|
2427
2696
|
var SYS_LINK_TYPES = (_SYS_LINK_TYPES = {}, _SYS_LINK_TYPES[INLINES.ENTRY_HYPERLINK] = 'Entry', _SYS_LINK_TYPES[INLINES.ASSET_HYPERLINK] = 'Asset', _SYS_LINK_TYPES);
|
|
@@ -2609,7 +2878,7 @@ function HyperlinkModal(props) {
|
|
|
2609
2878
|
htmlFor: ""
|
|
2610
2879
|
}, "Link target", ' '), linkEntity && linkEntity.sys.linkType === SYS_LINK_TYPES[linkType] ? /*#__PURE__*/createElement(Fragment, null, /*#__PURE__*/createElement(TextLink, {
|
|
2611
2880
|
onClick: resetLinkEntity,
|
|
2612
|
-
className: styles$
|
|
2881
|
+
className: styles$d.removeSelectionLabel
|
|
2613
2882
|
}, "Remove selection"), /*#__PURE__*/createElement("div", null, linkType === INLINES.ENTRY_HYPERLINK && /*#__PURE__*/createElement(FetchingWrappedEntryCard, {
|
|
2614
2883
|
sdk: props.sdk,
|
|
2615
2884
|
locale: props.sdk.field.locale,
|
|
@@ -2724,7 +2993,7 @@ function _addOrEditLink() {
|
|
|
2724
2993
|
}
|
|
2725
2994
|
|
|
2726
2995
|
var _withHyperlinkOptions;
|
|
2727
|
-
var styles$
|
|
2996
|
+
var styles$e = {
|
|
2728
2997
|
hyperlinkWrapper: /*#__PURE__*/css({
|
|
2729
2998
|
display: 'inline',
|
|
2730
2999
|
position: 'static',
|
|
@@ -2808,7 +3077,7 @@ function createHyperlinkPlugin(sdk) {
|
|
|
2808
3077
|
sys: {
|
|
2809
3078
|
id: element.getAttribute('data-link-id'),
|
|
2810
3079
|
linkType: element.getAttribute('data-link-type'),
|
|
2811
|
-
|
|
3080
|
+
type: 'Link'
|
|
2812
3081
|
}
|
|
2813
3082
|
}
|
|
2814
3083
|
}
|
|
@@ -2825,7 +3094,7 @@ function createHyperlinkPlugin(sdk) {
|
|
|
2825
3094
|
sys: {
|
|
2826
3095
|
id: element.getAttribute('data-link-id'),
|
|
2827
3096
|
linkType: element.getAttribute('data-link-type'),
|
|
2828
|
-
|
|
3097
|
+
type: 'Link'
|
|
2829
3098
|
}
|
|
2830
3099
|
}
|
|
2831
3100
|
}
|
|
@@ -2903,14 +3172,14 @@ function UrlHyperlink(props) {
|
|
|
2903
3172
|
|
|
2904
3173
|
return /*#__PURE__*/createElement(Tooltip, {
|
|
2905
3174
|
content: uri,
|
|
2906
|
-
targetWrapperClassName: styles$
|
|
3175
|
+
targetWrapperClassName: styles$e.hyperlinkWrapper,
|
|
2907
3176
|
place: "bottom",
|
|
2908
3177
|
maxWidth: "auto"
|
|
2909
3178
|
}, /*#__PURE__*/createElement(TextLink, {
|
|
2910
3179
|
href: uri,
|
|
2911
3180
|
rel: "noopener noreferrer",
|
|
2912
3181
|
onClick: handleClick,
|
|
2913
|
-
className: styles$
|
|
3182
|
+
className: styles$e.hyperlink
|
|
2914
3183
|
}, props.children));
|
|
2915
3184
|
}
|
|
2916
3185
|
|
|
@@ -2959,14 +3228,14 @@ function EntityHyperlink(props) {
|
|
|
2959
3228
|
type: target.sys.linkType,
|
|
2960
3229
|
sdk: sdk
|
|
2961
3230
|
}),
|
|
2962
|
-
targetWrapperClassName: styles$
|
|
3231
|
+
targetWrapperClassName: styles$e.hyperlinkWrapper,
|
|
2963
3232
|
place: "bottom",
|
|
2964
3233
|
maxWidth: "auto"
|
|
2965
3234
|
}, /*#__PURE__*/createElement(TextLink, {
|
|
2966
3235
|
href: "javascript:void(0)",
|
|
2967
3236
|
rel: "noopener noreferrer",
|
|
2968
3237
|
onClick: handleClick,
|
|
2969
|
-
className: styles$
|
|
3238
|
+
className: styles$e.hyperlink,
|
|
2970
3239
|
"data-link-type": target.sys.linkType,
|
|
2971
3240
|
"data-link-id": target.sys.id
|
|
2972
3241
|
}, props.children));
|
|
@@ -3020,7 +3289,8 @@ function ToolbarHyperlinkButton(props) {
|
|
|
3020
3289
|
tooltipPlace: "bottom",
|
|
3021
3290
|
label: "Hyperlink",
|
|
3022
3291
|
testId: "hyperlink-toolbar-button",
|
|
3023
|
-
|
|
3292
|
+
// @ts-expect-error
|
|
3293
|
+
onMouseDown: handleClick,
|
|
3024
3294
|
isActive: isActive,
|
|
3025
3295
|
disabled: props.isDisabled
|
|
3026
3296
|
});
|
|
@@ -3238,7 +3508,7 @@ var setHeader = function setHeader(editor, enable) {
|
|
|
3238
3508
|
});
|
|
3239
3509
|
};
|
|
3240
3510
|
|
|
3241
|
-
var styles$
|
|
3511
|
+
var styles$f = {
|
|
3242
3512
|
topRight: /*#__PURE__*/css({
|
|
3243
3513
|
position: 'absolute',
|
|
3244
3514
|
top: tokens.spacingXs,
|
|
@@ -3316,7 +3586,7 @@ var TableActions = function TableActions() {
|
|
|
3316
3586
|
};
|
|
3317
3587
|
}, [editor, isHeaderEnabled, close, onViewportAction]);
|
|
3318
3588
|
return /*#__PURE__*/React__default.createElement(Dropdown, {
|
|
3319
|
-
className: styles$
|
|
3589
|
+
className: styles$f.topRight,
|
|
3320
3590
|
position: "left",
|
|
3321
3591
|
isOpen: isOpen,
|
|
3322
3592
|
onClose: close,
|
|
@@ -3356,27 +3626,27 @@ var TableActions = function TableActions() {
|
|
|
3356
3626
|
};
|
|
3357
3627
|
|
|
3358
3628
|
var _templateObject$4, _templateObject2$3, _templateObject3$3, _templateObject4$1, _styles$1, _withTableOptions;
|
|
3359
|
-
var styles$
|
|
3629
|
+
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);
|
|
3360
3630
|
var Table = function Table(props) {
|
|
3361
3631
|
return /*#__PURE__*/createElement("table", Object.assign({}, props.attributes, {
|
|
3362
|
-
className: styles$
|
|
3632
|
+
className: styles$g[BLOCKS.TABLE]
|
|
3363
3633
|
}), /*#__PURE__*/createElement("tbody", null, props.children));
|
|
3364
3634
|
};
|
|
3365
3635
|
var TR = function TR(props) {
|
|
3366
3636
|
return /*#__PURE__*/createElement("tr", Object.assign({}, props.attributes, {
|
|
3367
|
-
className: styles$
|
|
3637
|
+
className: styles$g[BLOCKS.TABLE_ROW]
|
|
3368
3638
|
}), props.children);
|
|
3369
3639
|
};
|
|
3370
3640
|
var TH = function TH(props) {
|
|
3371
3641
|
var isSelected = useSelected();
|
|
3372
3642
|
return /*#__PURE__*/createElement("th", Object.assign({}, props.attributes, props.element.data, {
|
|
3373
|
-
className: styles$
|
|
3643
|
+
className: styles$g[BLOCKS.TABLE_HEADER_CELL]
|
|
3374
3644
|
}), isSelected && /*#__PURE__*/createElement(TableActions, null), props.children);
|
|
3375
3645
|
};
|
|
3376
3646
|
var TD = function TD(props) {
|
|
3377
3647
|
var isSelected = useSelected();
|
|
3378
3648
|
return /*#__PURE__*/createElement("td", Object.assign({}, props.attributes, props.element.data, {
|
|
3379
|
-
className: styles$
|
|
3649
|
+
className: styles$g[BLOCKS.TABLE_CELL]
|
|
3380
3650
|
}), isSelected && /*#__PURE__*/createElement(TableActions, null), props.children);
|
|
3381
3651
|
};
|
|
3382
3652
|
var withTableOptions = (_withTableOptions = {}, _withTableOptions[ELEMENT_TABLE] = {
|
|
@@ -3409,7 +3679,8 @@ function addTableTrackingEvents(editor, _ref) {
|
|
|
3409
3679
|
|
|
3410
3680
|
if (hasTables(markupAfter)) {
|
|
3411
3681
|
onViewportAction('paste', {
|
|
3412
|
-
tablePasted: true
|
|
3682
|
+
tablePasted: true,
|
|
3683
|
+
hasHeadersOutsideFirstRow: hasHeadersOutsideFirstRow(markupAfter)
|
|
3413
3684
|
});
|
|
3414
3685
|
}
|
|
3415
3686
|
}, 1);
|
|
@@ -3417,6 +3688,40 @@ function addTableTrackingEvents(editor, _ref) {
|
|
|
3417
3688
|
};
|
|
3418
3689
|
}
|
|
3419
3690
|
|
|
3691
|
+
function addTableNormalization(editor) {
|
|
3692
|
+
var normalizeNode = editor.normalizeNode;
|
|
3693
|
+
|
|
3694
|
+
editor.normalizeNode = function (entry) {
|
|
3695
|
+
var node = entry[0],
|
|
3696
|
+
path = entry[1]; // TODO: This should be enforced by sanitizeSlateDoc() but the internal
|
|
3697
|
+
// editor value can be different.
|
|
3698
|
+
// cf. https://github.com/ianstormtaylor/slate/issues/2206
|
|
3699
|
+
|
|
3700
|
+
var cellTypes = [BLOCKS.TABLE_CELL, BLOCKS.TABLE_HEADER_CELL];
|
|
3701
|
+
|
|
3702
|
+
if (Element.isElement(node) && cellTypes.includes(node.type)) {
|
|
3703
|
+
for (var _iterator = _createForOfIteratorHelperLoose(Node$1.children(editor, path)), _step; !(_step = _iterator()).done;) {
|
|
3704
|
+
var _step$value = _step.value,
|
|
3705
|
+
child = _step$value[0],
|
|
3706
|
+
childPath = _step$value[1];
|
|
3707
|
+
|
|
3708
|
+
if (Text.isText(child)) {
|
|
3709
|
+
var paragraph = {
|
|
3710
|
+
type: BLOCKS.PARAGRAPH,
|
|
3711
|
+
data: {},
|
|
3712
|
+
children: []
|
|
3713
|
+
};
|
|
3714
|
+
Transforms.wrapNodes(editor, paragraph, {
|
|
3715
|
+
at: childPath
|
|
3716
|
+
});
|
|
3717
|
+
}
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3720
|
+
|
|
3721
|
+
normalizeNode(entry);
|
|
3722
|
+
};
|
|
3723
|
+
}
|
|
3724
|
+
|
|
3420
3725
|
function hasTables(nodes) {
|
|
3421
3726
|
return nodes.some(function (_ref2) {
|
|
3422
3727
|
var type = _ref2.type;
|
|
@@ -3424,16 +3729,62 @@ function hasTables(nodes) {
|
|
|
3424
3729
|
});
|
|
3425
3730
|
}
|
|
3426
3731
|
|
|
3732
|
+
var isTableHeaderCell = function isTableHeaderCell(_ref3) {
|
|
3733
|
+
var type = _ref3.type;
|
|
3734
|
+
return type === BLOCKS.TABLE_HEADER_CELL;
|
|
3735
|
+
};
|
|
3736
|
+
|
|
3737
|
+
function hasHeadersOutsideFirstRow(nodes) {
|
|
3738
|
+
return nodes.filter(function (_ref4) {
|
|
3739
|
+
var type = _ref4.type;
|
|
3740
|
+
return type === BLOCKS.TABLE;
|
|
3741
|
+
}).flatMap(function (_ref5) {
|
|
3742
|
+
var children = _ref5.children;
|
|
3743
|
+
return children.slice(1);
|
|
3744
|
+
}).some(function (_ref6) {
|
|
3745
|
+
var children = _ref6.children;
|
|
3746
|
+
return children.some(isTableHeaderCell);
|
|
3747
|
+
});
|
|
3748
|
+
}
|
|
3749
|
+
|
|
3427
3750
|
function createWithTableEvents(tracking) {
|
|
3428
3751
|
return function withTableEvents(editor) {
|
|
3429
3752
|
addTableTrackingEvents(editor, tracking);
|
|
3753
|
+
addTableNormalization(editor);
|
|
3430
3754
|
return getTableOnKeyDown()(editor);
|
|
3431
3755
|
};
|
|
3432
3756
|
}
|
|
3433
3757
|
|
|
3434
3758
|
var createTablePlugin = function createTablePlugin(tracking) {
|
|
3435
3759
|
return _extends({}, createTablePlugin$1(), {
|
|
3436
|
-
onKeyDown: createWithTableEvents(tracking)
|
|
3760
|
+
onKeyDown: createWithTableEvents(tracking),
|
|
3761
|
+
withOverrides: function withOverrides(editor) {
|
|
3762
|
+
var insertFragment = editor.insertFragment;
|
|
3763
|
+
|
|
3764
|
+
editor.insertFragment = function (fragments) {
|
|
3765
|
+
// 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
|
|
3766
|
+
// More info: https://github.com/ianstormtaylor/slate/pull/4489 and https://github.com/ianstormtaylor/slate/issues/4542
|
|
3767
|
+
var fragmentHasTable = fragments.some(function (fragment) {
|
|
3768
|
+
return fragment.type === BLOCKS.TABLE;
|
|
3769
|
+
});
|
|
3770
|
+
|
|
3771
|
+
if (fragmentHasTable) {
|
|
3772
|
+
var emptyParagraph = {
|
|
3773
|
+
type: BLOCKS.PARAGRAPH,
|
|
3774
|
+
children: [{
|
|
3775
|
+
text: ''
|
|
3776
|
+
}],
|
|
3777
|
+
data: {},
|
|
3778
|
+
isVoid: false
|
|
3779
|
+
};
|
|
3780
|
+
Transforms.insertNodes(editor, emptyParagraph);
|
|
3781
|
+
}
|
|
3782
|
+
|
|
3783
|
+
insertFragment(fragments);
|
|
3784
|
+
};
|
|
3785
|
+
|
|
3786
|
+
return editor;
|
|
3787
|
+
}
|
|
3437
3788
|
});
|
|
3438
3789
|
};
|
|
3439
3790
|
function ToolbarTableButton(props) {
|
|
@@ -3485,7 +3836,8 @@ function ToolbarTableButton(props) {
|
|
|
3485
3836
|
tooltipPlace: "bottom",
|
|
3486
3837
|
label: "Table",
|
|
3487
3838
|
testId: "table-toolbar-button",
|
|
3488
|
-
|
|
3839
|
+
// @ts-expect-error
|
|
3840
|
+
onMouseDown: handleClick,
|
|
3489
3841
|
// TODO: active state looks off since the button will be disabled. Do we still need it?
|
|
3490
3842
|
isActive: isActive,
|
|
3491
3843
|
disabled: props.isDisabled
|
|
@@ -3515,7 +3867,7 @@ function EmbeddedEntityDropdownButton(_ref) {
|
|
|
3515
3867
|
}, /*#__PURE__*/createElement(DropdownList, null, children));
|
|
3516
3868
|
}
|
|
3517
3869
|
|
|
3518
|
-
var styles$
|
|
3870
|
+
var styles$h = {
|
|
3519
3871
|
root: /*#__PURE__*/css({
|
|
3520
3872
|
marginBottom: '1.25rem'
|
|
3521
3873
|
})
|
|
@@ -3523,8 +3875,7 @@ var styles$e = {
|
|
|
3523
3875
|
function LinkedEntityBlock(props) {
|
|
3524
3876
|
var attributes = props.attributes,
|
|
3525
3877
|
children = props.children,
|
|
3526
|
-
element = props.element
|
|
3527
|
-
onEntityFetchComplete = props.onEntityFetchComplete;
|
|
3878
|
+
element = props.element;
|
|
3528
3879
|
var isSelected = useSelected();
|
|
3529
3880
|
var editor = useContentfulEditor();
|
|
3530
3881
|
var sdk = useSdkContext();
|
|
@@ -3549,7 +3900,7 @@ function LinkedEntityBlock(props) {
|
|
|
3549
3900
|
};
|
|
3550
3901
|
|
|
3551
3902
|
return /*#__PURE__*/React__default.createElement("div", Object.assign({}, attributes, {
|
|
3552
|
-
className: styles$
|
|
3903
|
+
className: styles$h.root,
|
|
3553
3904
|
"data-entity-type": entityType,
|
|
3554
3905
|
"data-entity-id": entityId
|
|
3555
3906
|
}), /*#__PURE__*/React__default.createElement("div", {
|
|
@@ -3561,12 +3912,7 @@ function LinkedEntityBlock(props) {
|
|
|
3561
3912
|
isDisabled: isDisabled,
|
|
3562
3913
|
isSelected: isSelected,
|
|
3563
3914
|
onRemove: handleRemoveClick,
|
|
3564
|
-
onEdit: handleEditClick
|
|
3565
|
-
getEntryUrl: function getEntryUrl() {
|
|
3566
|
-
var getEntryUrl = sdk.parameters.instance.getEntryUrl;
|
|
3567
|
-
return typeof getEntryUrl === 'function' ? getEntryUrl(entityId) : '';
|
|
3568
|
-
},
|
|
3569
|
-
onEntityFetchComplete: onEntityFetchComplete
|
|
3915
|
+
onEdit: handleEditClick
|
|
3570
3916
|
}), entityType === 'Asset' && /*#__PURE__*/React__default.createElement(FetchingWrappedAssetCard, {
|
|
3571
3917
|
sdk: sdk,
|
|
3572
3918
|
assetId: entityId,
|
|
@@ -3574,12 +3920,7 @@ function LinkedEntityBlock(props) {
|
|
|
3574
3920
|
isDisabled: isDisabled,
|
|
3575
3921
|
isSelected: isSelected,
|
|
3576
3922
|
onRemove: handleRemoveClick,
|
|
3577
|
-
onEdit: handleEditClick
|
|
3578
|
-
getAssetUrl: function getAssetUrl() {
|
|
3579
|
-
var getAssetUrl = sdk.parameters.instance.getAssetUrl;
|
|
3580
|
-
return typeof getAssetUrl === 'function' ? getAssetUrl(entityId) : '';
|
|
3581
|
-
},
|
|
3582
|
-
onEntityFetchComplete: onEntityFetchComplete
|
|
3923
|
+
onEdit: handleEditClick
|
|
3583
3924
|
})), children);
|
|
3584
3925
|
}
|
|
3585
3926
|
|
|
@@ -3719,7 +4060,7 @@ function insertBlock(editor, nodeType, entity) {
|
|
|
3719
4060
|
ReactEditor.focus(editor);
|
|
3720
4061
|
}
|
|
3721
4062
|
|
|
3722
|
-
var styles$
|
|
4063
|
+
var styles$i = {
|
|
3723
4064
|
icon: /*#__PURE__*/css({
|
|
3724
4065
|
marginRight: '10px'
|
|
3725
4066
|
})
|
|
@@ -3734,16 +4075,17 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
|
|
|
3734
4075
|
var sdk = useSdkContext();
|
|
3735
4076
|
|
|
3736
4077
|
var handleClick = /*#__PURE__*/function () {
|
|
3737
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
4078
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(event) {
|
|
3738
4079
|
return runtime_1.wrap(function _callee$(_context) {
|
|
3739
4080
|
while (1) {
|
|
3740
4081
|
switch (_context.prev = _context.next) {
|
|
3741
4082
|
case 0:
|
|
4083
|
+
event.preventDefault();
|
|
3742
4084
|
onClose();
|
|
3743
|
-
_context.next =
|
|
4085
|
+
_context.next = 4;
|
|
3744
4086
|
return selectEntityAndInsert(nodeType, sdk, editor, logAction || noop);
|
|
3745
4087
|
|
|
3746
|
-
case
|
|
4088
|
+
case 4:
|
|
3747
4089
|
case "end":
|
|
3748
4090
|
return _context.stop();
|
|
3749
4091
|
}
|
|
@@ -3751,7 +4093,7 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
|
|
|
3751
4093
|
}, _callee);
|
|
3752
4094
|
}));
|
|
3753
4095
|
|
|
3754
|
-
return function handleClick() {
|
|
4096
|
+
return function handleClick(_x) {
|
|
3755
4097
|
return _ref2.apply(this, arguments);
|
|
3756
4098
|
};
|
|
3757
4099
|
}();
|
|
@@ -3762,21 +4104,22 @@ function EmbeddedEntityBlockToolbarIcon(_ref) {
|
|
|
3762
4104
|
disabled: isDisabled,
|
|
3763
4105
|
className: baseClass + "-button",
|
|
3764
4106
|
size: "small",
|
|
3765
|
-
|
|
4107
|
+
// @ts-expect-error
|
|
4108
|
+
onMouseDown: handleClick,
|
|
3766
4109
|
icon: type === 'Asset' ? 'Asset' : 'EmbeddedEntryBlock',
|
|
3767
4110
|
buttonType: "muted",
|
|
3768
4111
|
testId: "toolbar-toggle-" + nodeType
|
|
3769
4112
|
}, "Embed " + type.toLowerCase()) : /*#__PURE__*/React__default.createElement(DropdownListItem, {
|
|
3770
4113
|
isDisabled: isDisabled,
|
|
3771
4114
|
className: baseClass + "-list-item",
|
|
3772
|
-
|
|
4115
|
+
onMouseDown: handleClick,
|
|
3773
4116
|
testId: "toolbar-toggle-" + nodeType
|
|
3774
4117
|
}, /*#__PURE__*/React__default.createElement(Flex, {
|
|
3775
4118
|
alignItems: "center",
|
|
3776
4119
|
flexDirection: "row"
|
|
3777
4120
|
}, /*#__PURE__*/React__default.createElement(Icon, {
|
|
3778
4121
|
icon: type === 'Asset' ? 'Asset' : 'EmbeddedEntryBlock',
|
|
3779
|
-
className: "rich-text__embedded-entry-list-icon " + styles$
|
|
4122
|
+
className: "rich-text__embedded-entry-list-icon " + styles$i.icon,
|
|
3780
4123
|
color: "secondary"
|
|
3781
4124
|
}), /*#__PURE__*/React__default.createElement("span", null, type)));
|
|
3782
4125
|
}
|
|
@@ -3819,6 +4162,7 @@ var createEmbeddedEntityPlugin = function createEmbeddedEntityPlugin(nodeType) {
|
|
|
3819
4162
|
if (!isBlock) return;
|
|
3820
4163
|
return {
|
|
3821
4164
|
type: nodeType,
|
|
4165
|
+
isVoid: true,
|
|
3822
4166
|
data: {
|
|
3823
4167
|
target: {
|
|
3824
4168
|
sys: {
|
|
@@ -3901,7 +4245,7 @@ function getWithEmbeddedEntityEvents(nodeType, sdk) {
|
|
|
3901
4245
|
|
|
3902
4246
|
var getEntryTitle = entityHelpers.getEntryTitle,
|
|
3903
4247
|
getEntryStatus = entityHelpers.getEntryStatus;
|
|
3904
|
-
var styles$
|
|
4248
|
+
var styles$j = {
|
|
3905
4249
|
scheduledIcon: /*#__PURE__*/css({
|
|
3906
4250
|
verticalAlign: 'text-bottom',
|
|
3907
4251
|
marginRight: tokens.spacing2Xs
|
|
@@ -3979,7 +4323,7 @@ function FetchingWrappedInlineEntryCard(props) {
|
|
|
3979
4323
|
entityType: "Entry",
|
|
3980
4324
|
entityId: entry.sys.id
|
|
3981
4325
|
}, /*#__PURE__*/React__default.createElement(Icon, {
|
|
3982
|
-
className: styles$
|
|
4326
|
+
className: styles$j.scheduledIcon,
|
|
3983
4327
|
icon: "Clock",
|
|
3984
4328
|
color: "muted",
|
|
3985
4329
|
testId: "scheduled-icon"
|
|
@@ -4005,7 +4349,7 @@ function createInlineEntryNode(id) {
|
|
|
4005
4349
|
}
|
|
4006
4350
|
|
|
4007
4351
|
var _withEmbeddedEntityIn;
|
|
4008
|
-
var styles$
|
|
4352
|
+
var styles$k = {
|
|
4009
4353
|
icon: /*#__PURE__*/css({
|
|
4010
4354
|
marginRight: '10px'
|
|
4011
4355
|
}),
|
|
@@ -4043,7 +4387,7 @@ function EmbeddedEntityInline(props) {
|
|
|
4043
4387
|
}
|
|
4044
4388
|
|
|
4045
4389
|
return /*#__PURE__*/createElement("span", Object.assign({}, props.attributes, {
|
|
4046
|
-
className: styles$
|
|
4390
|
+
className: styles$k.root,
|
|
4047
4391
|
"data-embedded-entity-inline-id": entryId
|
|
4048
4392
|
}), /*#__PURE__*/createElement("span", {
|
|
4049
4393
|
contentEditable: false
|
|
@@ -4161,7 +4505,7 @@ function ToolbarEmbeddedEntityInlineButton(props) {
|
|
|
4161
4505
|
}, /*#__PURE__*/createElement(Icon, {
|
|
4162
4506
|
icon: "EmbeddedEntryInline",
|
|
4163
4507
|
color: "secondary",
|
|
4164
|
-
className: "rich-text__embedded-entry-list-icon " + styles$
|
|
4508
|
+
className: "rich-text__embedded-entry-list-icon " + styles$k.icon
|
|
4165
4509
|
}), /*#__PURE__*/createElement("span", null, "Inline entry")));
|
|
4166
4510
|
}
|
|
4167
4511
|
function createEmbeddedEntityInlinePlugin(sdk) {
|
|
@@ -4281,7 +4625,7 @@ var EmbedEntityWidget = function EmbedEntityWidget(_ref) {
|
|
|
4281
4625
|
}, actions);
|
|
4282
4626
|
};
|
|
4283
4627
|
|
|
4284
|
-
var styles$
|
|
4628
|
+
var styles$l = {
|
|
4285
4629
|
embedActionsWrapper: /*#__PURE__*/css({
|
|
4286
4630
|
display: ['-webkit-box', '-ms-flexbox', 'flex'],
|
|
4287
4631
|
webkitAlignSelf: 'flex-start',
|
|
@@ -4311,7 +4655,7 @@ var Toolbar = function Toolbar(_ref) {
|
|
|
4311
4655
|
return /*#__PURE__*/React__default.createElement(EditorToolbar, {
|
|
4312
4656
|
testId: "toolbar"
|
|
4313
4657
|
}, /*#__PURE__*/React__default.createElement("div", {
|
|
4314
|
-
className: styles$
|
|
4658
|
+
className: styles$l.formattingOptionsWrapper
|
|
4315
4659
|
}, /*#__PURE__*/React__default.createElement(ToolbarHeadingButton, {
|
|
4316
4660
|
isDisabled: isDisabled || !canInsertBlocks
|
|
4317
4661
|
}), validationInfo.isAnyMarkEnabled && /*#__PURE__*/React__default.createElement(EditorToolbarDivider, null), isMarkEnabled(sdk.field, MARKS.BOLD) && /*#__PURE__*/React__default.createElement(ToolbarBoldButton, {
|
|
@@ -4333,7 +4677,7 @@ var Toolbar = function Toolbar(_ref) {
|
|
|
4333
4677
|
}), isNodeTypeEnabled(sdk.field, BLOCKS.TABLE) && /*#__PURE__*/React__default.createElement(ToolbarTableButton, {
|
|
4334
4678
|
isDisabled: isDisabled || !canInsertBlocks
|
|
4335
4679
|
})), /*#__PURE__*/React__default.createElement("div", {
|
|
4336
|
-
className: styles$
|
|
4680
|
+
className: styles$l.embedActionsWrapper
|
|
4337
4681
|
}, /*#__PURE__*/React__default.createElement(EmbedEntityWidget, {
|
|
4338
4682
|
isDisabled: isDisabled,
|
|
4339
4683
|
canInsertBlocks: canInsertBlocks
|
|
@@ -4358,7 +4702,7 @@ function getValidationInfo(field) {
|
|
|
4358
4702
|
}
|
|
4359
4703
|
|
|
4360
4704
|
var _templateObject$5;
|
|
4361
|
-
var styles$
|
|
4705
|
+
var styles$m = {
|
|
4362
4706
|
nativeSticky: /*#__PURE__*/css(_templateObject$5 || (_templateObject$5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n position: -webkit-sticky;\n position: sticky;\n top: -1px;\n z-index: 2;\n "])))
|
|
4363
4707
|
};
|
|
4364
4708
|
|
|
@@ -4366,15 +4710,158 @@ var StickyToolbarWrapper = function StickyToolbarWrapper(_ref) {
|
|
|
4366
4710
|
var isDisabled = _ref.isDisabled,
|
|
4367
4711
|
children = _ref.children;
|
|
4368
4712
|
return /*#__PURE__*/React__default.createElement("div", {
|
|
4369
|
-
className: isDisabled ? '' : styles$
|
|
4713
|
+
className: isDisabled ? '' : styles$m.nativeSticky
|
|
4370
4714
|
}, children);
|
|
4371
4715
|
};
|
|
4372
4716
|
|
|
4717
|
+
var removeChildNodes = function removeChildNodes(node, predicate) {
|
|
4718
|
+
return Array.from(node.childNodes).filter(predicate).forEach(function (table) {
|
|
4719
|
+
return node.removeChild(table);
|
|
4720
|
+
});
|
|
4721
|
+
};
|
|
4722
|
+
|
|
4723
|
+
var removeChildNodesUsingPredicate = function removeChildNodesUsingPredicate(predicate) {
|
|
4724
|
+
return function (nodeList) {
|
|
4725
|
+
var nodes = Array.from(nodeList);
|
|
4726
|
+
|
|
4727
|
+
while (nodes.length > 0) {
|
|
4728
|
+
var node = nodes.pop();
|
|
4729
|
+
removeChildNodes(node, predicate);
|
|
4730
|
+
|
|
4731
|
+
for (var _i = 0, _Array$from = Array.from(node.childNodes); _i < _Array$from.length; _i++) {
|
|
4732
|
+
var childNode = _Array$from[_i];
|
|
4733
|
+
nodes.push(childNode);
|
|
4734
|
+
}
|
|
4735
|
+
}
|
|
4736
|
+
|
|
4737
|
+
return nodes;
|
|
4738
|
+
};
|
|
4739
|
+
};
|
|
4740
|
+
|
|
4741
|
+
var isComment = function isComment(node) {
|
|
4742
|
+
return node.nodeType === Node.COMMENT_NODE;
|
|
4743
|
+
};
|
|
4744
|
+
|
|
4745
|
+
var removeCommentChildren = /*#__PURE__*/removeChildNodesUsingPredicate(isComment);
|
|
4746
|
+
var removeComments = function removeComments(_ref) {
|
|
4747
|
+
var doc = _ref[0],
|
|
4748
|
+
editor = _ref[1];
|
|
4749
|
+
removeCommentChildren(doc.childNodes);
|
|
4750
|
+
return [doc, editor];
|
|
4751
|
+
};
|
|
4752
|
+
|
|
4753
|
+
var TAG_NAME_TABLE = 'TABLE';
|
|
4754
|
+
var TAG_NAME_TABLE_CAPTION = 'CAPTION';
|
|
4755
|
+
var DISALLOWED_TABLE_CHILD_ELEMENTS = [TAG_NAME_TABLE, TAG_NAME_TABLE_CAPTION];
|
|
4756
|
+
|
|
4757
|
+
var isHTMLElement = function isHTMLElement(node) {
|
|
4758
|
+
return node.nodeType === Node.ELEMENT_NODE;
|
|
4759
|
+
};
|
|
4760
|
+
|
|
4761
|
+
var isTableElement = function isTableElement(node) {
|
|
4762
|
+
return isHTMLElement(node) && node.tagName === TAG_NAME_TABLE;
|
|
4763
|
+
};
|
|
4764
|
+
|
|
4765
|
+
var isDisallowedTableChildElement = function isDisallowedTableChildElement(node) {
|
|
4766
|
+
return isHTMLElement(node) && DISALLOWED_TABLE_CHILD_ELEMENTS.includes(node.tagName);
|
|
4767
|
+
};
|
|
4768
|
+
|
|
4769
|
+
var removeDisallowedTableChildElements = /*#__PURE__*/removeChildNodesUsingPredicate(isDisallowedTableChildElement);
|
|
4770
|
+
|
|
4771
|
+
var removeTableGrandchildren = function removeTableGrandchildren(nodeList) {
|
|
4772
|
+
var nodes = Array.from(nodeList);
|
|
4773
|
+
|
|
4774
|
+
while (nodes.length > 0) {
|
|
4775
|
+
var node = nodes.pop();
|
|
4776
|
+
|
|
4777
|
+
if (isTableElement(node)) {
|
|
4778
|
+
removeDisallowedTableChildElements(node.childNodes);
|
|
4779
|
+
continue;
|
|
4780
|
+
}
|
|
4781
|
+
|
|
4782
|
+
for (var _i = 0, _Array$from = Array.from(node.childNodes); _i < _Array$from.length; _i++) {
|
|
4783
|
+
var childNode = _Array$from[_i];
|
|
4784
|
+
nodes.push(childNode);
|
|
4785
|
+
}
|
|
4786
|
+
}
|
|
4787
|
+
|
|
4788
|
+
return nodes;
|
|
4789
|
+
};
|
|
4790
|
+
|
|
4791
|
+
var sanitizeTables = function sanitizeTables(_ref) {
|
|
4792
|
+
var doc = _ref[0],
|
|
4793
|
+
editor = _ref[1];
|
|
4794
|
+
|
|
4795
|
+
var _getNodeEntryFromSele = getNodeEntryFromSelection(editor, BLOCKS.TABLE),
|
|
4796
|
+
node = _getNodeEntryFromSele[0];
|
|
4797
|
+
|
|
4798
|
+
var isTableInCurrentSelection = !!node;
|
|
4799
|
+
|
|
4800
|
+
if (isTableInCurrentSelection) {
|
|
4801
|
+
removeDisallowedTableChildElements(doc.childNodes);
|
|
4802
|
+
} else {
|
|
4803
|
+
removeTableGrandchildren(doc.childNodes);
|
|
4804
|
+
}
|
|
4805
|
+
|
|
4806
|
+
return [doc, editor];
|
|
4807
|
+
};
|
|
4808
|
+
|
|
4809
|
+
|
|
4810
|
+
|
|
4811
|
+
var sanitizers = {
|
|
4812
|
+
__proto__: null,
|
|
4813
|
+
removeComments: removeComments,
|
|
4814
|
+
sanitizeTables: sanitizeTables
|
|
4815
|
+
};
|
|
4816
|
+
|
|
4817
|
+
var MIME_TYPE_HTML = 'text/html'; // TODO: Upgrade tslib so we can just flow(...sanitizers);
|
|
4818
|
+
|
|
4819
|
+
var sanitizeDocument = /*#__PURE__*/flow.apply(undefined, /*#__PURE__*/Object.values(sanitizers));
|
|
4820
|
+
|
|
4821
|
+
var sanitizeHtml = function sanitizeHtml(html, editor) {
|
|
4822
|
+
var doc = new DOMParser().parseFromString(html, MIME_TYPE_HTML);
|
|
4823
|
+
|
|
4824
|
+
var _sanitizeDocument = sanitizeDocument([doc, editor]),
|
|
4825
|
+
sanitizedDoc = _sanitizeDocument[0];
|
|
4826
|
+
|
|
4827
|
+
var sanitizedData = new XMLSerializer().serializeToString(sanitizedDoc);
|
|
4828
|
+
return sanitizedData;
|
|
4829
|
+
};
|
|
4830
|
+
|
|
4831
|
+
var htmlToDataTransfer = function htmlToDataTransfer(html) {
|
|
4832
|
+
var data = new DataTransfer();
|
|
4833
|
+
data.setData(MIME_TYPE_HTML, html);
|
|
4834
|
+
return data;
|
|
4835
|
+
};
|
|
4836
|
+
|
|
4837
|
+
function withPasteHandling(editor) {
|
|
4838
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
4839
|
+
return function (_event) {
|
|
4840
|
+
var insertData = editor.insertData;
|
|
4841
|
+
|
|
4842
|
+
editor.insertData = function (data) {
|
|
4843
|
+
var html = data.getData(MIME_TYPE_HTML);
|
|
4844
|
+
|
|
4845
|
+
if (html) {
|
|
4846
|
+
var sanitized = sanitizeHtml(html, editor);
|
|
4847
|
+
var newData = htmlToDataTransfer(sanitized);
|
|
4848
|
+
insertData(newData);
|
|
4849
|
+
}
|
|
4850
|
+
};
|
|
4851
|
+
};
|
|
4852
|
+
}
|
|
4853
|
+
|
|
4854
|
+
var createPastePlugin = function createPastePlugin() {
|
|
4855
|
+
return {
|
|
4856
|
+
onKeyDown: withPasteHandling
|
|
4857
|
+
};
|
|
4858
|
+
};
|
|
4859
|
+
|
|
4373
4860
|
var _templateObject$6, _styles$2, _withParagraphOptions;
|
|
4374
|
-
var styles$
|
|
4861
|
+
var styles$n = (_styles$2 = {}, _styles$2[BLOCKS.PARAGRAPH] = /*#__PURE__*/css(_templateObject$6 || (_templateObject$6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n line-height: ", ";\n margin-bottom: 1.5em;\n "])), tokens.lineHeightDefault), _styles$2);
|
|
4375
4862
|
function Paragraph(props) {
|
|
4376
4863
|
return /*#__PURE__*/createElement("div", Object.assign({}, props.attributes, {
|
|
4377
|
-
className: styles$
|
|
4864
|
+
className: styles$n[BLOCKS.PARAGRAPH]
|
|
4378
4865
|
}), props.children);
|
|
4379
4866
|
}
|
|
4380
4867
|
function createParagraphPlugin() {
|
|
@@ -4390,9 +4877,8 @@ function createParagraphPlugin() {
|
|
|
4390
4877
|
type: BLOCKS.PARAGRAPH,
|
|
4391
4878
|
deserialize: function deserialize(element) {
|
|
4392
4879
|
var isParagraphText = element.nodeName === 'P';
|
|
4393
|
-
var isDivText = element.nodeName === 'DIV' && !element.getAttribute('data-entity-type');
|
|
4394
4880
|
var isNotEmpty = element.textContent !== '';
|
|
4395
|
-
var isText =
|
|
4881
|
+
var isText = isParagraphText && isNotEmpty;
|
|
4396
4882
|
if (!isText) return;
|
|
4397
4883
|
return {
|
|
4398
4884
|
type: BLOCKS.PARAGRAPH
|
|
@@ -4553,7 +5039,8 @@ var _excluded = ["sdk", "isInitiallyDisabled", "onAction"];
|
|
|
4553
5039
|
|
|
4554
5040
|
var getPlugins = function getPlugins(sdk, tracking) {
|
|
4555
5041
|
var plugins = [// Core
|
|
4556
|
-
createReactPlugin(), createHistoryPlugin(), //
|
|
5042
|
+
createReactPlugin(), createHistoryPlugin(), // Behavior
|
|
5043
|
+
createPastePlugin(), // Global shortcuts
|
|
4557
5044
|
createNewLinePlugin(), createInsertBeforeFirstVoidBlockPlugin(), // Block Elements
|
|
4558
5045
|
createParagraphPlugin(), createListPlugin(), createHrPlugin(), createHeadingPlugin(), createQuotePlugin(), createTablePlugin(tracking), createEmbeddedEntryBlockPlugin(sdk), createEmbeddedAssetBlockPlugin(sdk), // Inline elements
|
|
4559
5046
|
createHyperlinkPlugin(sdk), createEmbeddedEntityInlinePlugin(sdk), // Marks
|
|
@@ -4626,8 +5113,6 @@ var RichTextEditor = function RichTextEditor(props) {
|
|
|
4626
5113
|
sdk: sdk
|
|
4627
5114
|
}, /*#__PURE__*/React__default.createElement(SdkProvider, {
|
|
4628
5115
|
sdk: sdk
|
|
4629
|
-
}, /*#__PURE__*/React__default.createElement(ContentfulEditorProvider, {
|
|
4630
|
-
sdk: sdk
|
|
4631
5116
|
}, /*#__PURE__*/React__default.createElement(TrackingProvider, {
|
|
4632
5117
|
onAction: onAction || noop
|
|
4633
5118
|
}, /*#__PURE__*/React__default.createElement(FieldConnector, {
|
|
@@ -4641,15 +5126,17 @@ var RichTextEditor = function RichTextEditor(props) {
|
|
|
4641
5126
|
disabled = _ref.disabled,
|
|
4642
5127
|
setValue = _ref.setValue,
|
|
4643
5128
|
externalReset = _ref.externalReset;
|
|
4644
|
-
return /*#__PURE__*/React__default.createElement(
|
|
5129
|
+
return /*#__PURE__*/React__default.createElement(ContentfulEditorProvider, {
|
|
5130
|
+
sdk: sdk
|
|
5131
|
+
}, /*#__PURE__*/React__default.createElement(ConnectedRichTextEditor, Object.assign({}, otherProps, {
|
|
4645
5132
|
key: "rich-text-editor-" + externalReset,
|
|
4646
5133
|
value: lastRemoteValue,
|
|
4647
5134
|
sdk: sdk,
|
|
4648
5135
|
onAction: onAction || noop,
|
|
4649
5136
|
isDisabled: disabled,
|
|
4650
5137
|
onChange: setValue
|
|
4651
|
-
}));
|
|
4652
|
-
}))))
|
|
5138
|
+
})));
|
|
5139
|
+
}))));
|
|
4653
5140
|
};
|
|
4654
5141
|
|
|
4655
5142
|
var LINK_TYPES$1 = {
|