@comet/admin-rte 8.20.2 → 9.0.0-beta.1
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/lib/core/BlockElement.js +11 -15
- package/lib/core/Controls/BlockTypesControls.js +17 -24
- package/lib/core/Controls/ControlButton.js +11 -18
- package/lib/core/Controls/Controls.js +14 -21
- package/lib/core/Controls/CustomControls.js +5 -12
- package/lib/core/Controls/FeaturesButtonGroup.d.ts +1 -1
- package/lib/core/Controls/FeaturesButtonGroup.d.ts.map +1 -1
- package/lib/core/Controls/FeaturesButtonGroup.js +35 -41
- package/lib/core/Controls/HistoryContols.js +6 -13
- package/lib/core/Controls/InlineStyleTypeControls.js +6 -13
- package/lib/core/Controls/LinkControls.js +19 -26
- package/lib/core/Controls/ListsControls.js +6 -13
- package/lib/core/Controls/ListsIndentControls.js +6 -13
- package/lib/core/Controls/SpecialCharactersControls.js +7 -14
- package/lib/core/Controls/Toolbar/Toolbar.d.ts +1 -0
- package/lib/core/Controls/Toolbar/Toolbar.d.ts.map +1 -1
- package/lib/core/Controls/Toolbar/Toolbar.js +9 -15
- package/lib/core/Controls/Toolbar/Toolbar.styles.d.ts +2 -2
- package/lib/core/Controls/Toolbar/Toolbar.styles.js +7 -14
- package/lib/core/Controls/TranslationControls.js +8 -15
- package/lib/core/Controls/useBlockTypes.d.ts +1 -1
- package/lib/core/Controls/useBlockTypes.d.ts.map +1 -1
- package/lib/core/Controls/useBlockTypes.js +16 -23
- package/lib/core/Controls/useHistory.js +16 -22
- package/lib/core/Controls/useInlineStyleType.d.ts +1 -1
- package/lib/core/Controls/useInlineStyleType.d.ts.map +1 -1
- package/lib/core/Controls/useInlineStyleType.js +30 -37
- package/lib/core/Controls/useListIndent.js +23 -29
- package/lib/core/Rte.js +47 -54
- package/lib/core/RteReadOnly.js +18 -25
- package/lib/core/defaultBlocktypeMap.js +30 -38
- package/lib/core/extension/Link/Decorator.js +4 -11
- package/lib/core/extension/Link/EditorComponent.js +3 -9
- package/lib/core/extension/Link/ToolbarButton.js +50 -55
- package/lib/core/extension/LinksRemove/ToolbarButton.js +8 -14
- package/lib/core/extension/NonBreakingSpace/Decorator.js +3 -10
- package/lib/core/extension/NonBreakingSpace/EditorComponent.js +8 -14
- package/lib/core/extension/NonBreakingSpace/ToolbarButton.js +15 -23
- package/lib/core/extension/SoftHyphen/Decorator.js +3 -9
- package/lib/core/extension/SoftHyphen/EditorComponent.js +7 -13
- package/lib/core/extension/SoftHyphen/ToolbarButton.js +14 -22
- package/lib/core/filterEditor/composeFilterEditorFns.js +1 -7
- package/lib/core/filterEditor/default.js +9 -16
- package/lib/core/filterEditor/manageStandardBlockType.js +3 -9
- package/lib/core/filterEditor/removeBlocksExceedingBlockLimit.js +4 -10
- package/lib/core/filterEditor/removeUnsupportedBlockTypes.js +3 -10
- package/lib/core/filterEditor/removeUnsupportedEntities.js +3 -10
- package/lib/core/filterEditor/removeUnsupportedInlineStyles.js +3 -10
- package/lib/core/filterEditor/removeUnsupportedListLevels.js +3 -9
- package/lib/core/filterEditor/utils/changeBlockType.js +3 -9
- package/lib/core/filterEditor/utils/manipulateEntityData.js +3 -9
- package/lib/core/filterEditor/utils/removeEntities.js +4 -10
- package/lib/core/filterEditor/utils/removeInlineStyles.js +4 -10
- package/lib/core/makeRteApi.js +19 -26
- package/lib/core/translation/EditorStateTranslationDialog.js +8 -15
- package/lib/core/translation/ToolbarButton.js +22 -28
- package/lib/core/translation/htmlToState.js +7 -13
- package/lib/core/translation/stateToHtml.js +5 -12
- package/lib/core/types.d.ts +2 -2
- package/lib/core/types.d.ts.map +1 -1
- package/lib/core/types.js +1 -5
- package/lib/core/utils/createBlockRenderMap.js +4 -12
- package/lib/core/utils/findEntityDataInCurrentSelection.js +3 -9
- package/lib/core/utils/findEntityInCurrentSelection.js +7 -13
- package/lib/core/utils/findTextInCurrentSelection.js +3 -9
- package/lib/core/utils/getCurrentBlock.js +1 -7
- package/lib/core/utils/getRteTheme.js +13 -19
- package/lib/core/utils/pasteAndFilterText.js +7 -13
- package/lib/core/utils/rangesIntersect.js +1 -7
- package/lib/core/utils/selectionIsInOneBlock.js +1 -7
- package/lib/field/createFinalFormRte.js +10 -17
- package/lib/field/createRteField.js +8 -15
- package/lib/index.js +28 -202
- package/lib/useDebounce.js +5 -10
- package/lib/usePrevious.js +4 -9
- package/lib/utils/requiredValidator.js +6 -12
- package/package.json +18 -14
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.EditorComponent = void 0;
|
|
7
|
-
var _adminIcons = require("@comet/admin-icons");
|
|
8
|
-
var _styles = require("@mui/material/styles");
|
|
9
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
1
|
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
|
|
2
|
+
import { RteSoftHyphen } from "@comet/admin-icons";
|
|
3
|
+
import { styled } from "@mui/material/styles";
|
|
4
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
5
|
//TODO: Allow text selection for SoftHyphen
|
|
12
|
-
var EditorComponent =
|
|
6
|
+
export var EditorComponent = function EditorComponent(_ref) {
|
|
13
7
|
var children = _ref.children;
|
|
14
|
-
return /*#__PURE__*/(
|
|
15
|
-
children: [/*#__PURE__*/(
|
|
8
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
9
|
+
children: [/*#__PURE__*/_jsx(VisibleHyphen, {}), children]
|
|
16
10
|
});
|
|
17
11
|
};
|
|
18
|
-
var VisibleHyphen = /*#__PURE__*/
|
|
12
|
+
var VisibleHyphen = /*#__PURE__*/styled(RteSoftHyphen, process.env.NODE_ENV === "production" ? {
|
|
19
13
|
target: "e1vvt4290"
|
|
20
14
|
} : {
|
|
21
15
|
target: "e1vvt4290",
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ToolbarButton = ToolbarButton;
|
|
7
|
-
var _adminIcons = require("@comet/admin-icons");
|
|
8
|
-
var _Tooltip = _interopRequireDefault(require("@mui/material/Tooltip"));
|
|
9
|
-
var _draftJs = require("draft-js");
|
|
10
|
-
var _reactIntl = require("react-intl");
|
|
11
|
-
var _ControlButton = require("../../Controls/ControlButton");
|
|
12
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
1
|
+
import { RteSoftHyphen } from "@comet/admin-icons";
|
|
14
2
|
// eslint-disable-next-line no-restricted-imports
|
|
15
|
-
|
|
3
|
+
import Tooltip from "@mui/material/Tooltip";
|
|
4
|
+
import { EditorState, Modifier } from "draft-js";
|
|
5
|
+
import { FormattedMessage } from "react-intl";
|
|
6
|
+
import { ControlButton } from "../../Controls/ControlButton";
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
8
|
var SHY_UNICODE_CHAR = 0x00ad;
|
|
17
|
-
function ToolbarButton(_ref) {
|
|
9
|
+
export function ToolbarButton(_ref) {
|
|
18
10
|
var editorState = _ref.editorState,
|
|
19
11
|
setEditorState = _ref.setEditorState;
|
|
20
12
|
function handleClick(e) {
|
|
@@ -24,18 +16,18 @@ function ToolbarButton(_ref) {
|
|
|
24
16
|
//@TODO: insert \u00ad in a way that link-entities don’t break when inserted in the middle of a link text
|
|
25
17
|
// right now the link is split into 2 link-entities
|
|
26
18
|
// works as expected when \u00ad is copied and pasted: https://unicode.flopp.net/c/00AD
|
|
27
|
-
var textWithEntity =
|
|
28
|
-
setEditorState(
|
|
19
|
+
var textWithEntity = Modifier.insertText(currentContent, selection, String.fromCharCode(SHY_UNICODE_CHAR));
|
|
20
|
+
setEditorState(EditorState.push(editorState, textWithEntity, "insert-characters"));
|
|
29
21
|
}
|
|
30
|
-
return /*#__PURE__*/(
|
|
31
|
-
title: /*#__PURE__*/(
|
|
22
|
+
return /*#__PURE__*/_jsx(Tooltip, {
|
|
23
|
+
title: /*#__PURE__*/_jsx(FormattedMessage, {
|
|
32
24
|
id: "comet.rte.extensions.softHyphen.buttonTooltip",
|
|
33
25
|
defaultMessage: "Insert a soft hyphen"
|
|
34
26
|
}),
|
|
35
27
|
placement: "top",
|
|
36
|
-
children: /*#__PURE__*/(
|
|
37
|
-
children: [/*#__PURE__*/(
|
|
38
|
-
icon:
|
|
28
|
+
children: /*#__PURE__*/_jsxs("span", {
|
|
29
|
+
children: [/*#__PURE__*/_jsx(ControlButton, {
|
|
30
|
+
icon: RteSoftHyphen,
|
|
39
31
|
onButtonClick: handleClick
|
|
40
32
|
}), " "]
|
|
41
33
|
})
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
1
|
var composeFilterEditorFns = function composeFilterEditorFns(fns) {
|
|
8
2
|
return function (newState, ctx) {
|
|
9
3
|
return fns.reduce(function (nextState, filterFn) {
|
|
@@ -11,4 +5,4 @@ var composeFilterEditorFns = function composeFilterEditorFns(fns) {
|
|
|
11
5
|
}, newState);
|
|
12
6
|
};
|
|
13
7
|
};
|
|
14
|
-
|
|
8
|
+
export default composeFilterEditorFns;
|
|
@@ -1,23 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _composeFilterEditorFns = _interopRequireDefault(require("./composeFilterEditorFns"));
|
|
8
|
-
var _removeBlocksExceedingBlockLimit = _interopRequireDefault(require("./removeBlocksExceedingBlockLimit"));
|
|
9
|
-
var _removeUnsupportedBlockTypes = _interopRequireDefault(require("./removeUnsupportedBlockTypes"));
|
|
10
|
-
var _removeUnsupportedEntities = _interopRequireDefault(require("./removeUnsupportedEntities"));
|
|
11
|
-
var _removeUnsupportedInlineStyles = _interopRequireDefault(require("./removeUnsupportedInlineStyles"));
|
|
12
|
-
var _removeUnsupportedListLevels = _interopRequireDefault(require("./removeUnsupportedListLevels"));
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
1
|
+
import composeFilterEditorFns from "./composeFilterEditorFns";
|
|
2
|
+
import removeBlocksExceedingBlockLimit from "./removeBlocksExceedingBlockLimit";
|
|
3
|
+
import removeUnsupportedBlockTypes from "./removeUnsupportedBlockTypes";
|
|
4
|
+
import removeUnsupportedEntities from "./removeUnsupportedEntities";
|
|
5
|
+
import removeUnsupportedInlineStyles from "./removeUnsupportedInlineStyles";
|
|
6
|
+
import removeUnsupportedListLevels from "./removeUnsupportedListLevels";
|
|
14
7
|
var defaultFilterEditorStateBeforeUpdate = function defaultFilterEditorStateBeforeUpdate(newState, ctx) {
|
|
15
|
-
var fns = [
|
|
8
|
+
var fns = [removeUnsupportedEntities, removeUnsupportedBlockTypes, removeUnsupportedInlineStyles, removeBlocksExceedingBlockLimit, removeUnsupportedListLevels];
|
|
16
9
|
var shouldFilter = newState.getLastChangeType() === "insert-fragment";
|
|
17
10
|
if (shouldFilter) {
|
|
18
11
|
// apply all filters from left to right
|
|
19
|
-
return (
|
|
12
|
+
return composeFilterEditorFns(fns)(newState, ctx);
|
|
20
13
|
}
|
|
21
14
|
return newState;
|
|
22
15
|
};
|
|
23
|
-
|
|
16
|
+
export default defaultFilterEditorStateBeforeUpdate;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import changeBlockType from "./utils/changeBlockType";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _changeBlockType = _interopRequireDefault(require("./utils/changeBlockType"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
3
|
// when standard-block-type is not "unstyled", all non-empty blocks with block-type of "unstyled" are changed to the standard-block-type
|
|
10
4
|
//
|
|
11
5
|
var manageStandardBlockType = function manageStandardBlockType(newState, _ref) {
|
|
@@ -13,10 +7,10 @@ var manageStandardBlockType = function manageStandardBlockType(newState, _ref) {
|
|
|
13
7
|
if (standardBlockType !== "unstyled") {
|
|
14
8
|
// only replace empty blocks
|
|
15
9
|
// unstyled blocks with content are preserved
|
|
16
|
-
return (
|
|
10
|
+
return changeBlockType(["unstyled"], standardBlockType, {
|
|
17
11
|
skipNonEmptyBlocks: true
|
|
18
12
|
})(newState);
|
|
19
13
|
}
|
|
20
14
|
return newState;
|
|
21
15
|
};
|
|
22
|
-
|
|
16
|
+
export default manageStandardBlockType;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _draftJs = require("draft-js");
|
|
1
|
+
import { EditorState, SelectionState } from "draft-js";
|
|
8
2
|
// when a maxBlocks-limit is set, all blocks exceeding this limit are removed completely (with the content)
|
|
9
3
|
//
|
|
10
4
|
var removeBlocksExceedingBlockLimit = function removeBlocksExceedingBlockLimit(newState, _ref) {
|
|
@@ -15,14 +9,14 @@ var removeBlocksExceedingBlockLimit = function removeBlocksExceedingBlockLimit(n
|
|
|
15
9
|
if (blockMap.count() > maxBlocks) {
|
|
16
10
|
var limitedBlocks = blockMap.take(maxBlocks);
|
|
17
11
|
var lastKey = limitedBlocks.last().getKey();
|
|
18
|
-
return
|
|
12
|
+
return EditorState.set(newState, {
|
|
19
13
|
currentContent: content.merge({
|
|
20
14
|
blockMap: limitedBlocks
|
|
21
15
|
}),
|
|
22
|
-
selection:
|
|
16
|
+
selection: SelectionState.createEmpty(lastKey)
|
|
23
17
|
});
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
20
|
return newState;
|
|
27
21
|
};
|
|
28
|
-
|
|
22
|
+
export default removeBlocksExceedingBlockLimit;
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _changeBlockType = _interopRequireDefault(require("./utils/changeBlockType"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
1
|
+
import changeBlockType from "./utils/changeBlockType";
|
|
9
2
|
var removeUnsupportedBlockTypes = function removeUnsupportedBlockTypes(newState, _ref) {
|
|
10
3
|
var supports = _ref.supports,
|
|
11
4
|
standardBlockType = _ref.standardBlockType;
|
|
@@ -37,6 +30,6 @@ var removeUnsupportedBlockTypes = function removeUnsupportedBlockTypes(newState,
|
|
|
37
30
|
if (standardBlockType !== "unstyled") {
|
|
38
31
|
blackListBlocks.push("unstyled");
|
|
39
32
|
}
|
|
40
|
-
return (
|
|
33
|
+
return changeBlockType(blackListBlocks, standardBlockType)(newState);
|
|
41
34
|
};
|
|
42
|
-
|
|
35
|
+
export default removeUnsupportedBlockTypes;
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _removeEntities = _interopRequireDefault(require("./utils/removeEntities"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
1
|
+
import removeEntities from "./utils/removeEntities";
|
|
9
2
|
var removeUnsupportedEntities = function removeUnsupportedEntities(newState, _ref) {
|
|
10
3
|
var supports = _ref.supports;
|
|
11
4
|
// remove links and images
|
|
12
|
-
return (
|
|
5
|
+
return removeEntities(function (entity) {
|
|
13
6
|
var unsupportedCoreEntities = ["IMAGE", "TOKEN", "PHOTO"];
|
|
14
7
|
if (unsupportedCoreEntities.includes(entity.getType())) {
|
|
15
8
|
return false;
|
|
@@ -22,4 +15,4 @@ var removeUnsupportedEntities = function removeUnsupportedEntities(newState, _re
|
|
|
22
15
|
return true;
|
|
23
16
|
})(newState);
|
|
24
17
|
};
|
|
25
|
-
|
|
18
|
+
export default removeUnsupportedEntities;
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _removeInlineStyles = _interopRequireDefault(require("./utils/removeInlineStyles"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
1
|
+
import removeInlineStyles from "./utils/removeInlineStyles";
|
|
9
2
|
var removeUnsupportedInlineStyles = function removeUnsupportedInlineStyles(newState, _ref) {
|
|
10
3
|
var supports = _ref.supports;
|
|
11
4
|
// unstyle all core-blocks which are not supported
|
|
@@ -28,6 +21,6 @@ var removeUnsupportedInlineStyles = function removeUnsupportedInlineStyles(newSt
|
|
|
28
21
|
}
|
|
29
22
|
}
|
|
30
23
|
});
|
|
31
|
-
return (
|
|
24
|
+
return removeInlineStyles(blackListInlineStyles)(newState);
|
|
32
25
|
};
|
|
33
|
-
|
|
26
|
+
export default removeUnsupportedInlineStyles;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _draftJs = require("draft-js");
|
|
1
|
+
import { EditorState } from "draft-js";
|
|
8
2
|
var removeUnsupportedListLevels = function removeUnsupportedListLevels(newState, _ref) {
|
|
9
3
|
var listLevelMax = _ref.listLevelMax;
|
|
10
4
|
var content = newState.getCurrentContent();
|
|
11
5
|
var blockMap = content.getBlockMap();
|
|
12
|
-
return
|
|
6
|
+
return EditorState.set(newState, {
|
|
13
7
|
currentContent: content.merge({
|
|
14
8
|
blockMap: blockMap.map(function (block) {
|
|
15
9
|
return block === null || block === void 0 ? void 0 : block.merge({
|
|
@@ -19,4 +13,4 @@ var removeUnsupportedListLevels = function removeUnsupportedListLevels(newState,
|
|
|
19
13
|
})
|
|
20
14
|
});
|
|
21
15
|
};
|
|
22
|
-
|
|
16
|
+
export default removeUnsupportedListLevels;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _draftJs = require("draft-js");
|
|
1
|
+
import { EditorState } from "draft-js";
|
|
8
2
|
// inspired by https://github.com/thibaudcolas/draftjs-filters/blob/master/src/lib/filters/blocks.js#L127
|
|
9
3
|
var changeBlockType = function changeBlockType(blockTypeList) {
|
|
10
4
|
var blockType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unstyled";
|
|
@@ -33,11 +27,11 @@ var changeBlockType = function changeBlockType(blockTypeList) {
|
|
|
33
27
|
depth: 0
|
|
34
28
|
});
|
|
35
29
|
});
|
|
36
|
-
return
|
|
30
|
+
return EditorState.set(nextState, {
|
|
37
31
|
currentContent: content.merge({
|
|
38
32
|
blockMap: blockMap.merge(changedBlocks)
|
|
39
33
|
})
|
|
40
34
|
});
|
|
41
35
|
};
|
|
42
36
|
};
|
|
43
|
-
|
|
37
|
+
export default changeBlockType;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _draftJs = require("draft-js");
|
|
8
1
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
9
2
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
3
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
11
4
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
12
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
6
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
import { EditorState } from "draft-js";
|
|
14
8
|
// if object is returned the entity data is updated with this object
|
|
15
9
|
|
|
16
10
|
// inspired by https://github.com/thibaudcolas/draftjs-filters/blob/31d89177090b815b968ac2d8ec95c89d975f1e44/src/lib/filters/entities.js#L179
|
|
@@ -41,9 +35,9 @@ var manipulateEntityData = function manipulateEntityData(updateEntityDataFn) {
|
|
|
41
35
|
content.replaceEntityData(key, maybeNewData);
|
|
42
36
|
}
|
|
43
37
|
});
|
|
44
|
-
return
|
|
38
|
+
return EditorState.set(nextState, {
|
|
45
39
|
currentContent: content
|
|
46
40
|
});
|
|
47
41
|
};
|
|
48
42
|
};
|
|
49
|
-
|
|
43
|
+
export default manipulateEntityData;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _draftJs = require("draft-js");
|
|
1
|
+
import { CharacterMetadata, EditorState } from "draft-js";
|
|
8
2
|
// when function returns false the entity is removed
|
|
9
3
|
|
|
10
4
|
// inspired by https://github.com/thibaudcolas/draftjs-filters/blob/31d89177090b815b968ac2d8ec95c89d975f1e44/src/lib/filters/entities.js#L77
|
|
@@ -23,18 +17,18 @@ var removeEntities = function removeEntities(filterFn) {
|
|
|
23
17
|
var _entity = content.getEntity(entityKey);
|
|
24
18
|
if (!filterFn(_entity)) {
|
|
25
19
|
altered = true;
|
|
26
|
-
return
|
|
20
|
+
return CharacterMetadata.applyEntity(_char, null);
|
|
27
21
|
}
|
|
28
22
|
}
|
|
29
23
|
return _char;
|
|
30
24
|
});
|
|
31
25
|
return altered ? block.set("characterList", chars) : block;
|
|
32
26
|
});
|
|
33
|
-
return
|
|
27
|
+
return EditorState.set(nextState, {
|
|
34
28
|
currentContent: content.merge({
|
|
35
29
|
blockMap: blockMap.merge(blocks)
|
|
36
30
|
})
|
|
37
31
|
});
|
|
38
32
|
};
|
|
39
33
|
};
|
|
40
|
-
|
|
34
|
+
export default removeEntities;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _draftJs = require("draft-js");
|
|
1
|
+
import { CharacterMetadata, EditorState } from "draft-js";
|
|
8
2
|
// inspired by export const filterInlineStyles = (
|
|
9
3
|
var removeInlineStyles = function removeInlineStyles(blockBlacklist) {
|
|
10
4
|
return function (nextState) {
|
|
@@ -18,17 +12,17 @@ var removeInlineStyles = function removeInlineStyles(blockBlacklist) {
|
|
|
18
12
|
return blockBlacklist.includes(type);
|
|
19
13
|
}).forEach(function (type) {
|
|
20
14
|
altered = true;
|
|
21
|
-
newChar =
|
|
15
|
+
newChar = CharacterMetadata.removeStyle(newChar, type);
|
|
22
16
|
});
|
|
23
17
|
return newChar;
|
|
24
18
|
});
|
|
25
19
|
return altered ? block.set("characterList", chars) : block;
|
|
26
20
|
});
|
|
27
|
-
return
|
|
21
|
+
return EditorState.set(nextState, {
|
|
28
22
|
currentContent: content.merge({
|
|
29
23
|
blockMap: blockMap.merge(changedBlocks)
|
|
30
24
|
})
|
|
31
25
|
});
|
|
32
26
|
};
|
|
33
27
|
};
|
|
34
|
-
|
|
28
|
+
export default removeInlineStyles;
|
package/lib/core/makeRteApi.js
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _draftJs = require("draft-js");
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _useDebounce = _interopRequireDefault(require("../useDebounce"));
|
|
10
|
-
var _usePrevious = _interopRequireDefault(require("../usePrevious"));
|
|
11
|
-
var _Decorator = _interopRequireDefault(require("./extension/Link/Decorator"));
|
|
12
|
-
var _Decorator2 = _interopRequireDefault(require("./extension/NonBreakingSpace/Decorator"));
|
|
13
|
-
var _Decorator3 = _interopRequireDefault(require("./extension/SoftHyphen/Decorator"));
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
15
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
16
2
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
17
3
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -24,33 +10,40 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
24
10
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
25
11
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
26
12
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
import { CompositeDecorator, convertFromRaw, convertToRaw, EditorState } from "draft-js";
|
|
14
|
+
import { useEffect, useState } from "react";
|
|
15
|
+
import useDebounce from "../useDebounce";
|
|
16
|
+
import usePrevious from "../usePrevious";
|
|
17
|
+
import LinkDecorator from "./extension/Link/Decorator";
|
|
18
|
+
import NonBreakingSpaceDecorator from "./extension/NonBreakingSpace/Decorator";
|
|
19
|
+
import SoftHyphenDecorator from "./extension/SoftHyphen/Decorator";
|
|
27
20
|
var defaultRteApiOptions = {
|
|
28
21
|
debounceDelay: 400
|
|
29
22
|
};
|
|
30
23
|
function defaultParseContent(v) {
|
|
31
24
|
var rawDraft = JSON.parse(v);
|
|
32
|
-
return
|
|
25
|
+
return convertFromRaw(rawDraft);
|
|
33
26
|
}
|
|
34
27
|
function defaultFormatContent(v) {
|
|
35
|
-
return JSON.stringify(
|
|
28
|
+
return JSON.stringify(convertToRaw(v));
|
|
36
29
|
}
|
|
37
30
|
function makeRteApi(o) {
|
|
38
31
|
var _ref = o || {},
|
|
39
32
|
_ref$decorators = _ref.decorators,
|
|
40
|
-
decorators = _ref$decorators === void 0 ? [
|
|
33
|
+
decorators = _ref$decorators === void 0 ? [LinkDecorator] : _ref$decorators,
|
|
41
34
|
_ref$parse = _ref.parse,
|
|
42
35
|
parse = _ref$parse === void 0 ? defaultParseContent : _ref$parse,
|
|
43
36
|
_ref$format = _ref.format,
|
|
44
37
|
format = _ref$format === void 0 ? defaultFormatContent : _ref$format;
|
|
45
38
|
|
|
46
39
|
// Add default decorators
|
|
47
|
-
decorators.push(
|
|
48
|
-
var decorator = new
|
|
40
|
+
decorators.push(NonBreakingSpaceDecorator, SoftHyphenDecorator);
|
|
41
|
+
var decorator = new CompositeDecorator(decorators);
|
|
49
42
|
function createEmptyState() {
|
|
50
|
-
return
|
|
43
|
+
return EditorState.createEmpty(decorator);
|
|
51
44
|
}
|
|
52
45
|
function createStateFromRawContent(rawContent) {
|
|
53
|
-
return
|
|
46
|
+
return EditorState.createWithContent(parse(rawContent), decorator);
|
|
54
47
|
}
|
|
55
48
|
function convertStateToRawContent(es) {
|
|
56
49
|
return format(es.getCurrentContent());
|
|
@@ -60,14 +53,14 @@ function makeRteApi(o) {
|
|
|
60
53
|
var defaultValue = options.defaultValue,
|
|
61
54
|
onDebouncedContentChange = options.onDebouncedContentChange,
|
|
62
55
|
debounceDelay = options.debounceDelay;
|
|
63
|
-
var _useState =
|
|
56
|
+
var _useState = useState(defaultValue ? createStateFromRawContent(defaultValue) : createEmptyState()),
|
|
64
57
|
_useState2 = _slicedToArray(_useState, 2),
|
|
65
58
|
editorState = _useState2[0],
|
|
66
59
|
setEditorState = _useState2[1];
|
|
67
|
-
var debouncedEditorState = (
|
|
68
|
-
var previousDebouncedContent = (
|
|
60
|
+
var debouncedEditorState = useDebounce(editorState, debounceDelay);
|
|
61
|
+
var previousDebouncedContent = usePrevious(debouncedEditorState.getCurrentContent());
|
|
69
62
|
var debouncedContent = debouncedEditorState.getCurrentContent();
|
|
70
|
-
|
|
63
|
+
useEffect(function () {
|
|
71
64
|
if (onDebouncedContentChange) {
|
|
72
65
|
if (previousDebouncedContent !== debouncedContent) {
|
|
73
66
|
onDebouncedContentChange(debouncedEditorState, convertStateToRawContent);
|
|
@@ -90,4 +83,4 @@ function makeRteApi(o) {
|
|
|
90
83
|
var api = [useRteApi, staticFunctions];
|
|
91
84
|
return api;
|
|
92
85
|
}
|
|
93
|
-
|
|
86
|
+
export default makeRteApi;
|
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.EditorStateTranslationDialog = void 0;
|
|
7
|
-
var _admin = require("@comet/admin");
|
|
8
|
-
var _Rte = require("../Rte");
|
|
9
|
-
var _RteReadOnly = _interopRequireDefault(require("../RteReadOnly"));
|
|
10
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
-
var EditorStateTranslationDialog = exports.EditorStateTranslationDialog = function EditorStateTranslationDialog(props) {
|
|
1
|
+
import { BaseTranslationDialog } from "@comet/admin";
|
|
2
|
+
import { Rte } from "../Rte";
|
|
3
|
+
import RteReadOnly from "../RteReadOnly";
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
export var EditorStateTranslationDialog = function EditorStateTranslationDialog(props) {
|
|
13
6
|
var open = props.open,
|
|
14
7
|
onClose = props.onClose,
|
|
15
8
|
originalText = props.originalText,
|
|
16
9
|
translatedText = props.translatedText,
|
|
17
10
|
onApplyTranslation = props.onApplyTranslation;
|
|
18
|
-
return /*#__PURE__*/(
|
|
11
|
+
return /*#__PURE__*/_jsx(BaseTranslationDialog, {
|
|
19
12
|
open: open,
|
|
20
13
|
onClose: onClose,
|
|
21
14
|
originalText: originalText,
|
|
22
15
|
translatedText: translatedText,
|
|
23
16
|
onApplyTranslation: onApplyTranslation,
|
|
24
17
|
renderOriginalText: function renderOriginalText(text) {
|
|
25
|
-
return /*#__PURE__*/(
|
|
18
|
+
return /*#__PURE__*/_jsx(RteReadOnly, {
|
|
26
19
|
value: text
|
|
27
20
|
});
|
|
28
21
|
},
|
|
29
22
|
renderTranslatedText: function renderTranslatedText(text, onChange) {
|
|
30
|
-
return /*#__PURE__*/(
|
|
23
|
+
return /*#__PURE__*/_jsx(Rte, {
|
|
31
24
|
value: text,
|
|
32
25
|
onChange: onChange,
|
|
33
26
|
options: {
|