@dextinity/admin-rte 2.0.0-canary-20260729062014
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/LICENSE +24 -0
- package/lib/core/BlockElement.d.ts +29 -0
- package/lib/core/BlockElement.d.ts.map +1 -0
- package/lib/core/BlockElement.js +43 -0
- package/lib/core/Controls/BlockTypesControls.d.ts +16 -0
- package/lib/core/Controls/BlockTypesControls.d.ts.map +1 -0
- package/lib/core/Controls/BlockTypesControls.js +91 -0
- package/lib/core/Controls/ControlButton.d.ts +28 -0
- package/lib/core/Controls/ControlButton.d.ts.map +1 -0
- package/lib/core/Controls/ControlButton.js +62 -0
- package/lib/core/Controls/Controls.d.ts +3 -0
- package/lib/core/Controls/Controls.d.ts.map +1 -0
- package/lib/core/Controls/Controls.js +30 -0
- package/lib/core/Controls/CustomControls.d.ts +3 -0
- package/lib/core/Controls/CustomControls.d.ts.map +1 -0
- package/lib/core/Controls/CustomControls.js +20 -0
- package/lib/core/Controls/FeaturesButtonGroup.d.ts +30 -0
- package/lib/core/Controls/FeaturesButtonGroup.d.ts.map +1 -0
- package/lib/core/Controls/FeaturesButtonGroup.js +147 -0
- package/lib/core/Controls/HistoryContols.d.ts +3 -0
- package/lib/core/Controls/HistoryContols.d.ts.map +1 -0
- package/lib/core/Controls/HistoryContols.js +24 -0
- package/lib/core/Controls/InlineStyleTypeControls.d.ts +3 -0
- package/lib/core/Controls/InlineStyleTypeControls.d.ts.map +1 -0
- package/lib/core/Controls/InlineStyleTypeControls.js +29 -0
- package/lib/core/Controls/LinkControls.d.ts +26 -0
- package/lib/core/Controls/LinkControls.d.ts.map +1 -0
- package/lib/core/Controls/LinkControls.js +54 -0
- package/lib/core/Controls/ListsControls.d.ts +3 -0
- package/lib/core/Controls/ListsControls.d.ts.map +1 -0
- package/lib/core/Controls/ListsControls.js +30 -0
- package/lib/core/Controls/ListsIndentControls.d.ts +3 -0
- package/lib/core/Controls/ListsIndentControls.d.ts.map +1 -0
- package/lib/core/Controls/ListsIndentControls.js +27 -0
- package/lib/core/Controls/SpecialCharactersControls.d.ts +4 -0
- package/lib/core/Controls/SpecialCharactersControls.d.ts.map +1 -0
- package/lib/core/Controls/SpecialCharactersControls.js +20 -0
- package/lib/core/Controls/Toolbar/Toolbar.d.ts +28 -0
- package/lib/core/Controls/Toolbar/Toolbar.d.ts.map +1 -0
- package/lib/core/Controls/Toolbar/Toolbar.js +41 -0
- package/lib/core/Controls/Toolbar/Toolbar.styles.d.ts +14 -0
- package/lib/core/Controls/Toolbar/Toolbar.styles.d.ts.map +1 -0
- package/lib/core/Controls/Toolbar/Toolbar.styles.js +21 -0
- package/lib/core/Controls/TranslationControls.d.ts +4 -0
- package/lib/core/Controls/TranslationControls.d.ts.map +1 -0
- package/lib/core/Controls/TranslationControls.js +20 -0
- package/lib/core/Controls/useBlockTypes.d.ts +23 -0
- package/lib/core/Controls/useBlockTypes.d.ts.map +1 -0
- package/lib/core/Controls/useBlockTypes.js +116 -0
- package/lib/core/Controls/useHistory.d.ts +13 -0
- package/lib/core/Controls/useHistory.d.ts.map +1 -0
- package/lib/core/Controls/useHistory.js +63 -0
- package/lib/core/Controls/useInlineStyleType.d.ts +16 -0
- package/lib/core/Controls/useInlineStyleType.d.ts.map +1 -0
- package/lib/core/Controls/useInlineStyleType.js +148 -0
- package/lib/core/Controls/useListIndent.d.ts +14 -0
- package/lib/core/Controls/useListIndent.d.ts.map +1 -0
- package/lib/core/Controls/useListIndent.js +114 -0
- package/lib/core/Rte.d.ts +72 -0
- package/lib/core/Rte.d.ts.map +1 -0
- package/lib/core/Rte.js +256 -0
- package/lib/core/RteReadOnly.d.ts +19 -0
- package/lib/core/RteReadOnly.d.ts.map +1 -0
- package/lib/core/RteReadOnly.js +62 -0
- package/lib/core/defaultBlocktypeMap.d.ts +6 -0
- package/lib/core/defaultBlocktypeMap.d.ts.map +1 -0
- package/lib/core/defaultBlocktypeMap.js +235 -0
- package/lib/core/extension/Link/Decorator.d.ts +5 -0
- package/lib/core/extension/Link/Decorator.d.ts.map +1 -0
- package/lib/core/extension/Link/Decorator.js +13 -0
- package/lib/core/extension/Link/EditorComponent.d.ts +12 -0
- package/lib/core/extension/Link/EditorComponent.d.ts.map +1 -0
- package/lib/core/extension/Link/EditorComponent.js +14 -0
- package/lib/core/extension/Link/ToolbarButton.d.ts +3 -0
- package/lib/core/extension/Link/ToolbarButton.d.ts.map +1 -0
- package/lib/core/extension/Link/ToolbarButton.js +162 -0
- package/lib/core/extension/LinksRemove/ToolbarButton.d.ts +3 -0
- package/lib/core/extension/LinksRemove/ToolbarButton.d.ts.map +1 -0
- package/lib/core/extension/LinksRemove/ToolbarButton.js +20 -0
- package/lib/core/extension/NonBreakingSpace/Decorator.d.ts +4 -0
- package/lib/core/extension/NonBreakingSpace/Decorator.d.ts.map +1 -0
- package/lib/core/extension/NonBreakingSpace/Decorator.js +17 -0
- package/lib/core/extension/NonBreakingSpace/EditorComponent.d.ts +9 -0
- package/lib/core/extension/NonBreakingSpace/EditorComponent.d.ts.map +1 -0
- package/lib/core/extension/NonBreakingSpace/EditorComponent.js +37 -0
- package/lib/core/extension/NonBreakingSpace/ToolbarButton.d.ts +4 -0
- package/lib/core/extension/NonBreakingSpace/ToolbarButton.d.ts.map +1 -0
- package/lib/core/extension/NonBreakingSpace/ToolbarButton.js +42 -0
- package/lib/core/extension/SoftHyphen/Decorator.d.ts +4 -0
- package/lib/core/extension/SoftHyphen/Decorator.d.ts.map +1 -0
- package/lib/core/extension/SoftHyphen/Decorator.js +17 -0
- package/lib/core/extension/SoftHyphen/EditorComponent.d.ts +9 -0
- package/lib/core/extension/SoftHyphen/EditorComponent.d.ts.map +1 -0
- package/lib/core/extension/SoftHyphen/EditorComponent.js +24 -0
- package/lib/core/extension/SoftHyphen/ToolbarButton.d.ts +3 -0
- package/lib/core/extension/SoftHyphen/ToolbarButton.d.ts.map +1 -0
- package/lib/core/extension/SoftHyphen/ToolbarButton.js +35 -0
- package/lib/core/filterEditor/composeFilterEditorFns.d.ts +4 -0
- package/lib/core/filterEditor/composeFilterEditorFns.d.ts.map +1 -0
- package/lib/core/filterEditor/composeFilterEditorFns.js +8 -0
- package/lib/core/filterEditor/default.d.ts +4 -0
- package/lib/core/filterEditor/default.d.ts.map +1 -0
- package/lib/core/filterEditor/default.js +16 -0
- package/lib/core/filterEditor/manageStandardBlockType.d.ts +4 -0
- package/lib/core/filterEditor/manageStandardBlockType.d.ts.map +1 -0
- package/lib/core/filterEditor/manageStandardBlockType.js +16 -0
- package/lib/core/filterEditor/removeBlocksExceedingBlockLimit.d.ts +4 -0
- package/lib/core/filterEditor/removeBlocksExceedingBlockLimit.d.ts.map +1 -0
- package/lib/core/filterEditor/removeBlocksExceedingBlockLimit.js +22 -0
- package/lib/core/filterEditor/removeUnsupportedBlockTypes.d.ts +4 -0
- package/lib/core/filterEditor/removeUnsupportedBlockTypes.d.ts.map +1 -0
- package/lib/core/filterEditor/removeUnsupportedBlockTypes.js +35 -0
- package/lib/core/filterEditor/removeUnsupportedEntities.d.ts +4 -0
- package/lib/core/filterEditor/removeUnsupportedEntities.d.ts.map +1 -0
- package/lib/core/filterEditor/removeUnsupportedEntities.js +18 -0
- package/lib/core/filterEditor/removeUnsupportedInlineStyles.d.ts +4 -0
- package/lib/core/filterEditor/removeUnsupportedInlineStyles.d.ts.map +1 -0
- package/lib/core/filterEditor/removeUnsupportedInlineStyles.js +26 -0
- package/lib/core/filterEditor/removeUnsupportedListLevels.d.ts +4 -0
- package/lib/core/filterEditor/removeUnsupportedListLevels.d.ts.map +1 -0
- package/lib/core/filterEditor/removeUnsupportedListLevels.js +16 -0
- package/lib/core/filterEditor/utils/changeBlockType.d.ts +9 -0
- package/lib/core/filterEditor/utils/changeBlockType.d.ts.map +1 -0
- package/lib/core/filterEditor/utils/changeBlockType.js +37 -0
- package/lib/core/filterEditor/utils/manipulateEntityData.d.ts +6 -0
- package/lib/core/filterEditor/utils/manipulateEntityData.d.ts.map +1 -0
- package/lib/core/filterEditor/utils/manipulateEntityData.js +43 -0
- package/lib/core/filterEditor/utils/removeEntities.d.ts +6 -0
- package/lib/core/filterEditor/utils/removeEntities.d.ts.map +1 -0
- package/lib/core/filterEditor/utils/removeEntities.js +34 -0
- package/lib/core/filterEditor/utils/removeInlineStyles.d.ts +5 -0
- package/lib/core/filterEditor/utils/removeInlineStyles.d.ts.map +1 -0
- package/lib/core/filterEditor/utils/removeInlineStyles.js +28 -0
- package/lib/core/makeRteApi.d.ts +26 -0
- package/lib/core/makeRteApi.d.ts.map +1 -0
- package/lib/core/makeRteApi.js +86 -0
- package/lib/core/translation/EditorStateTranslationDialog.d.ts +11 -0
- package/lib/core/translation/EditorStateTranslationDialog.d.ts.map +1 -0
- package/lib/core/translation/EditorStateTranslationDialog.js +32 -0
- package/lib/core/translation/ToolbarButton.d.ts +4 -0
- package/lib/core/translation/ToolbarButton.d.ts.map +1 -0
- package/lib/core/translation/ToolbarButton.js +98 -0
- package/lib/core/translation/htmlToState.d.ts +9 -0
- package/lib/core/translation/htmlToState.d.ts.map +1 -0
- package/lib/core/translation/htmlToState.js +53 -0
- package/lib/core/translation/htmlToState.spec.d.ts +2 -0
- package/lib/core/translation/htmlToState.spec.d.ts.map +1 -0
- package/lib/core/translation/stateToHtml.d.ts +13 -0
- package/lib/core/translation/stateToHtml.d.ts.map +1 -0
- package/lib/core/translation/stateToHtml.js +60 -0
- package/lib/core/translation/stateToHtml.spec.d.ts +2 -0
- package/lib/core/translation/stateToHtml.spec.d.ts.map +1 -0
- package/lib/core/types.d.ts +64 -0
- package/lib/core/types.d.ts.map +1 -0
- package/lib/core/types.js +1 -0
- package/lib/core/utils/createBlockRenderMap.d.ts +6 -0
- package/lib/core/utils/createBlockRenderMap.d.ts.map +1 -0
- package/lib/core/utils/createBlockRenderMap.js +22 -0
- package/lib/core/utils/findEntityDataInCurrentSelection.d.ts +3 -0
- package/lib/core/utils/findEntityDataInCurrentSelection.d.ts.map +1 -0
- package/lib/core/utils/findEntityDataInCurrentSelection.js +12 -0
- package/lib/core/utils/findEntityInCurrentSelection.d.ts +8 -0
- package/lib/core/utils/findEntityInCurrentSelection.d.ts.map +1 -0
- package/lib/core/utils/findEntityInCurrentSelection.js +81 -0
- package/lib/core/utils/findTextInCurrentSelection.d.ts +3 -0
- package/lib/core/utils/findTextInCurrentSelection.d.ts.map +1 -0
- package/lib/core/utils/findTextInCurrentSelection.js +16 -0
- package/lib/core/utils/getCurrentBlock.d.ts +3 -0
- package/lib/core/utils/getCurrentBlock.d.ts.map +1 -0
- package/lib/core/utils/getCurrentBlock.js +7 -0
- package/lib/core/utils/getRteTheme.d.ts +19 -0
- package/lib/core/utils/getRteTheme.d.ts.map +1 -0
- package/lib/core/utils/getRteTheme.js +18 -0
- package/lib/core/utils/pasteAndFilterText.d.ts +5 -0
- package/lib/core/utils/pasteAndFilterText.d.ts.map +1 -0
- package/lib/core/utils/pasteAndFilterText.js +17 -0
- package/lib/core/utils/rangesIntersect.d.ts +6 -0
- package/lib/core/utils/rangesIntersect.d.ts.map +1 -0
- package/lib/core/utils/rangesIntersect.js +22 -0
- package/lib/core/utils/selectionIsInOneBlock.d.ts +3 -0
- package/lib/core/utils/selectionIsInOneBlock.d.ts.map +1 -0
- package/lib/core/utils/selectionIsInOneBlock.js +6 -0
- package/lib/field/createFinalFormRte.d.ts +22 -0
- package/lib/field/createFinalFormRte.d.ts.map +1 -0
- package/lib/field/createFinalFormRte.js +84 -0
- package/lib/field/createRteField.d.ts +13 -0
- package/lib/field/createRteField.d.ts.map +1 -0
- package/lib/field/createRteField.js +44 -0
- package/lib/index.d.ts +31 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +29 -0
- package/lib/useDebounce.d.ts +2 -0
- package/lib/useDebounce.d.ts.map +1 -0
- package/lib/useDebounce.js +32 -0
- package/lib/usePrevious.d.ts +4 -0
- package/lib/usePrevious.d.ts.map +1 -0
- package/lib/usePrevious.js +20 -0
- package/lib/utils/requiredValidator.d.ts +4 -0
- package/lib/utils/requiredValidator.d.ts.map +1 -0
- package/lib/utils/requiredValidator.js +16 -0
- package/package.json +93 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Editor, type EditorState } from "draft-js";
|
|
2
|
+
import { type RefObject } from "react";
|
|
3
|
+
import type { SupportedThings } from "../Rte";
|
|
4
|
+
import type { CustomInlineStyles, IFeatureConfig } from "../types";
|
|
5
|
+
interface IProps {
|
|
6
|
+
editorState: EditorState;
|
|
7
|
+
setEditorState: (editorState: EditorState) => void;
|
|
8
|
+
supportedThings: SupportedThings[];
|
|
9
|
+
editorRef: RefObject<Editor | null>;
|
|
10
|
+
customInlineStyles?: CustomInlineStyles;
|
|
11
|
+
}
|
|
12
|
+
export default function useInlineStyleType({ editorState, setEditorState, supportedThings, editorRef, customInlineStyles }: IProps): {
|
|
13
|
+
features: IFeatureConfig<string>[];
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=useInlineStyleType.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInlineStyleType.d.ts","sourceRoot":"","sources":["../../../src/core/Controls/useInlineStyleType.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,WAAW,EAAa,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,KAAK,SAAS,EAAwB,MAAM,OAAO,CAAC;AAG7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAmB,MAAM,UAAU,CAAC;AAIpF,UAAU,MAAM;IACZ,WAAW,EAAE,WAAW,CAAC;IACzB,cAAc,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAC;IACnD,eAAe,EAAE,eAAe,EAAE,CAAC;IACnC,SAAS,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACpC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CAC3C;AAqDD,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAAE,MAAM;;EAgEjI"}
|
|
@@ -0,0 +1,148 @@
|
|
|
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); }
|
|
2
|
+
var _excluded = ["style"];
|
|
3
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
5
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
6
|
+
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."); }
|
|
7
|
+
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; } }
|
|
8
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
13
|
+
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); }
|
|
14
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
15
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
16
|
+
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; } }
|
|
17
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
18
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
19
|
+
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; }
|
|
20
|
+
import { RteBold, RteItalic, RteStrikethrough, RteSub, RteSup, RteUnderlined } from "@dextinity/admin-icons";
|
|
21
|
+
import * as detectBrowser from "detect-browser";
|
|
22
|
+
import { RichUtils } from "draft-js";
|
|
23
|
+
import { useCallback, useMemo } from "react";
|
|
24
|
+
import { FormattedMessage } from "react-intl";
|
|
25
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
26
|
+
var browser = detectBrowser.detect();
|
|
27
|
+
var defaultFeatures = [{
|
|
28
|
+
name: "BOLD",
|
|
29
|
+
label: /*#__PURE__*/_jsx(FormattedMessage, {
|
|
30
|
+
id: "comet.rte.controls.blockType.bold.label",
|
|
31
|
+
defaultMessage: "Bold"
|
|
32
|
+
}),
|
|
33
|
+
icon: RteBold,
|
|
34
|
+
tooltipText: (browser === null || browser === void 0 ? void 0 : browser.os) === "Mac OS" ? /*#__PURE__*/_jsx(FormattedMessage, {
|
|
35
|
+
id: "comet.rte.controls.blockType.bold.tooltipMac",
|
|
36
|
+
defaultMessage: "Cmd+B"
|
|
37
|
+
}) : /*#__PURE__*/_jsx(FormattedMessage, {
|
|
38
|
+
id: "comet.rte.controls.blockType.bold.tooltip",
|
|
39
|
+
defaultMessage: "Ctrl+B"
|
|
40
|
+
})
|
|
41
|
+
}, {
|
|
42
|
+
name: "ITALIC",
|
|
43
|
+
label: /*#__PURE__*/_jsx(FormattedMessage, {
|
|
44
|
+
id: "comet.rte.controls.blockType.italic.label",
|
|
45
|
+
defaultMessage: "Italic"
|
|
46
|
+
}),
|
|
47
|
+
icon: RteItalic,
|
|
48
|
+
tooltipText: (browser === null || browser === void 0 ? void 0 : browser.os) === "Mac OS" ? /*#__PURE__*/_jsx(FormattedMessage, {
|
|
49
|
+
id: "comet.rte.controls.blockType.italic.tooltipMac",
|
|
50
|
+
defaultMessage: "Cmd+I"
|
|
51
|
+
}) : /*#__PURE__*/_jsx(FormattedMessage, {
|
|
52
|
+
id: "comet.rte.controls.blockType.italic.tooltip",
|
|
53
|
+
defaultMessage: "Ctrl+I"
|
|
54
|
+
})
|
|
55
|
+
}, {
|
|
56
|
+
name: "UNDERLINE",
|
|
57
|
+
label: /*#__PURE__*/_jsx(FormattedMessage, {
|
|
58
|
+
id: "comet.rte.controls.blockType.underlined.label",
|
|
59
|
+
defaultMessage: "underlined"
|
|
60
|
+
}),
|
|
61
|
+
icon: RteUnderlined,
|
|
62
|
+
tooltipText: (browser === null || browser === void 0 ? void 0 : browser.os) === "Mac OS" ? /*#__PURE__*/_jsx(FormattedMessage, {
|
|
63
|
+
id: "comet.rte.controls.blockType.underlined.tooltipMac",
|
|
64
|
+
defaultMessage: "Cmd+U"
|
|
65
|
+
}) : /*#__PURE__*/_jsx(FormattedMessage, {
|
|
66
|
+
id: "comet.rte.controls.blockType.underlined.tooltip",
|
|
67
|
+
defaultMessage: "Ctrl+U"
|
|
68
|
+
})
|
|
69
|
+
}, {
|
|
70
|
+
name: "STRIKETHROUGH",
|
|
71
|
+
label: /*#__PURE__*/_jsx(FormattedMessage, {
|
|
72
|
+
id: "comet.rte.controls.blockType.strikethrough.label",
|
|
73
|
+
defaultMessage: "Strikethrough"
|
|
74
|
+
}),
|
|
75
|
+
icon: RteStrikethrough
|
|
76
|
+
}, {
|
|
77
|
+
name: "SUP",
|
|
78
|
+
label: /*#__PURE__*/_jsx(FormattedMessage, {
|
|
79
|
+
id: "comet.rte.controls.blockType.super.label",
|
|
80
|
+
defaultMessage: "Superscript"
|
|
81
|
+
}),
|
|
82
|
+
icon: RteSup
|
|
83
|
+
}, {
|
|
84
|
+
name: "SUB",
|
|
85
|
+
label: /*#__PURE__*/_jsx(FormattedMessage, {
|
|
86
|
+
id: "comet.rte.controls.blockType.sub.label",
|
|
87
|
+
defaultMessage: "Subscript"
|
|
88
|
+
}),
|
|
89
|
+
icon: RteSub
|
|
90
|
+
}];
|
|
91
|
+
export default function useInlineStyleType(_ref) {
|
|
92
|
+
var editorState = _ref.editorState,
|
|
93
|
+
setEditorState = _ref.setEditorState,
|
|
94
|
+
supportedThings = _ref.supportedThings,
|
|
95
|
+
editorRef = _ref.editorRef,
|
|
96
|
+
customInlineStyles = _ref.customInlineStyles;
|
|
97
|
+
// can check if inlineStyleType is supported by the editor
|
|
98
|
+
var supports = useCallback(function (inlineStyle) {
|
|
99
|
+
switch (inlineStyle) {
|
|
100
|
+
case "BOLD":
|
|
101
|
+
return supportedThings.includes("bold");
|
|
102
|
+
case "ITALIC":
|
|
103
|
+
return supportedThings.includes("italic");
|
|
104
|
+
case "UNDERLINE":
|
|
105
|
+
return supportedThings.includes("underline");
|
|
106
|
+
case "STRIKETHROUGH":
|
|
107
|
+
return supportedThings.includes("strikethrough");
|
|
108
|
+
case "SUB":
|
|
109
|
+
return supportedThings.includes("sub");
|
|
110
|
+
case "SUP":
|
|
111
|
+
return supportedThings.includes("sup");
|
|
112
|
+
default:
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}, [supportedThings]);
|
|
116
|
+
var inlineStyleActive = useCallback(function (draftInlineStyleType) {
|
|
117
|
+
var currentStyle = editorState.getCurrentInlineStyle();
|
|
118
|
+
return currentStyle.has(draftInlineStyleType);
|
|
119
|
+
}, [editorState]);
|
|
120
|
+
var handleInlineStyleButtonClick = useCallback(function (draftInlineStyleType, e) {
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
setEditorState(RichUtils.toggleInlineStyle(editorState, draftInlineStyleType));
|
|
123
|
+
}, [setEditorState, editorState]);
|
|
124
|
+
var features = useMemo(function () {
|
|
125
|
+
return [].concat(_toConsumableArray(defaultFeatures.filter(function (c) {
|
|
126
|
+
return supports(c.name);
|
|
127
|
+
}).map(function (c) {
|
|
128
|
+
return _objectSpread(_objectSpread({}, c), {}, {
|
|
129
|
+
selected: inlineStyleActive(c.name),
|
|
130
|
+
onButtonClick: handleInlineStyleButtonClick.bind(null, c.name)
|
|
131
|
+
});
|
|
132
|
+
})), _toConsumableArray(customInlineStyles ? Object.entries(customInlineStyles).map(function (_ref2) {
|
|
133
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
134
|
+
name = _ref3[0],
|
|
135
|
+
_ref3$ = _ref3[1],
|
|
136
|
+
style = _ref3$.style,
|
|
137
|
+
restOptions = _objectWithoutProperties(_ref3$, _excluded);
|
|
138
|
+
return _objectSpread(_objectSpread({}, restOptions), {}, {
|
|
139
|
+
name: name,
|
|
140
|
+
selected: inlineStyleActive(name),
|
|
141
|
+
onButtonClick: handleInlineStyleButtonClick.bind(null, name)
|
|
142
|
+
});
|
|
143
|
+
}) : []));
|
|
144
|
+
}, [supports, inlineStyleActive, handleInlineStyleButtonClick, customInlineStyles]);
|
|
145
|
+
return {
|
|
146
|
+
features: features
|
|
147
|
+
};
|
|
148
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EditorState } from "draft-js";
|
|
2
|
+
import type { SupportedThings } from "../Rte";
|
|
3
|
+
import type { IFeatureConfig } from "../types";
|
|
4
|
+
interface IProps {
|
|
5
|
+
editorState: EditorState;
|
|
6
|
+
setEditorState: (editorState: EditorState) => void;
|
|
7
|
+
supportedThings: SupportedThings[];
|
|
8
|
+
listLevelMax?: number;
|
|
9
|
+
}
|
|
10
|
+
export default function useListIndent({ editorState, setEditorState, supportedThings, listLevelMax }: IProps): {
|
|
11
|
+
features: IFeatureConfig<string>[];
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=useListIndent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useListIndent.d.ts","sourceRoot":"","sources":["../../../src/core/Controls/useListIndent.ts"],"names":[],"mappings":"AACA,OAAO,EAAoC,WAAW,EAAE,MAAM,UAAU,CAAC;AAIzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAwD/C,UAAU,MAAM;IACZ,WAAW,EAAE,WAAW,CAAC;IACzB,cAAc,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAC;IACnD,eAAe,EAAE,eAAe,EAAE,CAAC;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,YAAgB,EAAE,EAAE,MAAM;;EA4D/G"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { RteIndentDecrease, RteIndentIncrease } from "@dextinity/admin-icons";
|
|
2
|
+
import { EditorState } from "draft-js";
|
|
3
|
+
import { useCallback, useMemo } from "react";
|
|
4
|
+
import { useIntl } from "react-intl";
|
|
5
|
+
import getCurrentBlock from "../utils/getCurrentBlock";
|
|
6
|
+
import selectionIsInOneBlock from "../utils/selectionIsInOneBlock";
|
|
7
|
+
|
|
8
|
+
// https://github.com/facebook/draft-js/blob/v0.11.4/src/model/transaction/adjustBlockDepthForContentState.js
|
|
9
|
+
// https://github.com/facebook/draft-js/blob/v0.11.4/src/model/modifier/RichTextEditorUtil.js
|
|
10
|
+
|
|
11
|
+
// to keep a nested structure, check version 0.10.5, in current version 0.11.4 nesting is not forced
|
|
12
|
+
// https://github.com/facebook/draft-js/blob/v0.10.5/src/model/modifier/RichTextEditorUtil.js
|
|
13
|
+
function adjustBlockDepth(type, editorState, maxDepth) {
|
|
14
|
+
var selectionState = editorState.getSelection();
|
|
15
|
+
var contentState = editorState.getCurrentContent();
|
|
16
|
+
|
|
17
|
+
// check that only one block is selected, otherwise we cananot change depth
|
|
18
|
+
var key = selectionState.getAnchorKey();
|
|
19
|
+
if (key !== selectionState.getFocusKey()) {
|
|
20
|
+
return editorState;
|
|
21
|
+
}
|
|
22
|
+
var adjustment = type === "increase" ? 1 : -1;
|
|
23
|
+
|
|
24
|
+
// do not exceed max depth
|
|
25
|
+
var block = getCurrentBlock(editorState);
|
|
26
|
+
if (!block) {
|
|
27
|
+
return editorState;
|
|
28
|
+
}
|
|
29
|
+
var depth = block.getDepth();
|
|
30
|
+
if (adjustment === 1 && depth === maxDepth) {
|
|
31
|
+
return editorState;
|
|
32
|
+
}
|
|
33
|
+
var startKey = selectionState.getStartKey();
|
|
34
|
+
var endKey = selectionState.getEndKey();
|
|
35
|
+
var blockMap = contentState.getBlockMap();
|
|
36
|
+
var blocks = blockMap.toSeq().skipUntil(function (_, k) {
|
|
37
|
+
return k === startKey;
|
|
38
|
+
}).takeUntil(function (_, k) {
|
|
39
|
+
return k === endKey;
|
|
40
|
+
}).concat([[endKey, blockMap.get(endKey)]]).map(function (curBlock) {
|
|
41
|
+
var blockDepth = curBlock.getDepth() + adjustment;
|
|
42
|
+
blockDepth = Math.max(0, Math.min(blockDepth, maxDepth));
|
|
43
|
+
return curBlock.set("depth", blockDepth);
|
|
44
|
+
});
|
|
45
|
+
blockMap = blockMap.merge(blocks);
|
|
46
|
+
var newContent = contentState.merge({
|
|
47
|
+
blockMap: blockMap,
|
|
48
|
+
selectionBefore: selectionState,
|
|
49
|
+
selectionAfter: selectionState
|
|
50
|
+
});
|
|
51
|
+
return EditorState.push(editorState, newContent, "adjust-depth");
|
|
52
|
+
}
|
|
53
|
+
export default function useListIndent(_ref) {
|
|
54
|
+
var editorState = _ref.editorState,
|
|
55
|
+
setEditorState = _ref.setEditorState,
|
|
56
|
+
supportedThings = _ref.supportedThings,
|
|
57
|
+
_ref$listLevelMax = _ref.listLevelMax,
|
|
58
|
+
listLevelMax = _ref$listLevelMax === void 0 ? 4 : _ref$listLevelMax;
|
|
59
|
+
var intl = useIntl();
|
|
60
|
+
|
|
61
|
+
// can check if indenting lists is supported
|
|
62
|
+
var supported = useMemo(function () {
|
|
63
|
+
return supportedThings.some(function (c) {
|
|
64
|
+
return ["ordered-list", "unordered-list"].includes(c) && listLevelMax !== 0;
|
|
65
|
+
});
|
|
66
|
+
}, [supportedThings, listLevelMax]);
|
|
67
|
+
var active = useMemo(function () {
|
|
68
|
+
var currentBlock = getCurrentBlock(editorState);
|
|
69
|
+
if (!currentBlock) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return ["ordered-list-item", "unordered-list-item"].includes(currentBlock.getType()) && selectionIsInOneBlock(editorState);
|
|
73
|
+
}, [editorState]);
|
|
74
|
+
var canIndentLeft = useMemo(function () {
|
|
75
|
+
return active && getCurrentBlock(editorState).getDepth() > 0;
|
|
76
|
+
}, [active, editorState]);
|
|
77
|
+
var canIndentRight = useMemo(function () {
|
|
78
|
+
return active && getCurrentBlock(editorState).getDepth() < listLevelMax - 1;
|
|
79
|
+
}, [active, editorState, listLevelMax]);
|
|
80
|
+
var handleListIndentLeftClick = useCallback(function (e) {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
setEditorState(adjustBlockDepth("decrease", editorState, listLevelMax));
|
|
83
|
+
}, [editorState, setEditorState, listLevelMax]);
|
|
84
|
+
var handleListIndentRightClick = useCallback(function (e) {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
setEditorState(adjustBlockDepth("increase", editorState, listLevelMax));
|
|
87
|
+
}, [editorState, setEditorState, listLevelMax]);
|
|
88
|
+
var features = useMemo(function () {
|
|
89
|
+
return supported ? [{
|
|
90
|
+
name: "list-indent-right",
|
|
91
|
+
label: "",
|
|
92
|
+
disabled: !canIndentRight,
|
|
93
|
+
onButtonClick: handleListIndentRightClick,
|
|
94
|
+
icon: RteIndentIncrease,
|
|
95
|
+
tooltipText: intl.formatMessage({
|
|
96
|
+
id: "comet.rte.controls.listIndent.right.tooltip",
|
|
97
|
+
defaultMessage: "Tab"
|
|
98
|
+
})
|
|
99
|
+
}, {
|
|
100
|
+
name: "list-indent-left",
|
|
101
|
+
label: "",
|
|
102
|
+
disabled: !canIndentLeft,
|
|
103
|
+
onButtonClick: handleListIndentLeftClick,
|
|
104
|
+
icon: RteIndentDecrease,
|
|
105
|
+
tooltipText: intl.formatMessage({
|
|
106
|
+
id: "comet.rte.controls.listIndent.left.tooltip",
|
|
107
|
+
defaultMessage: "Shift+Tab"
|
|
108
|
+
})
|
|
109
|
+
}] : [];
|
|
110
|
+
}, [supported, canIndentLeft, canIndentRight, handleListIndentLeftClick, handleListIndentRightClick, intl]);
|
|
111
|
+
return {
|
|
112
|
+
features: features
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import "draft-js/dist/Draft.css";
|
|
2
|
+
import { type ThemedComponentBaseProps } from "@dextinity/admin";
|
|
3
|
+
import { type ComponentsOverrides, type Theme } from "@mui/material";
|
|
4
|
+
import { type DraftBlockType, type EditorProps as DraftJsEditorProps, type EditorState } from "draft-js";
|
|
5
|
+
import { type ForwardRefExoticComponent, type PropsWithoutRef, type RefAttributes } from "react";
|
|
6
|
+
import type { CustomInlineStyles, IBlocktypeMap, ICustomBlockTypeMap_Deprecated, ToolbarButtonComponent } from "./types";
|
|
7
|
+
import { type RteThemeColors } from "./utils/getRteTheme";
|
|
8
|
+
export type SupportedThings = "bold" | "italic" | "underline" | "strikethrough" | "sub" | "sup" | "header-one" | "header-two" | "header-three" | "header-four" | "header-five" | "header-six" | "ordered-list" | "unordered-list" | "blockquote" | "history" | "link" | "links-remove" | "non-breaking-space" | "soft-hyphen";
|
|
9
|
+
export interface IRteOptions {
|
|
10
|
+
supports: SupportedThings[];
|
|
11
|
+
listLevelMax: number;
|
|
12
|
+
blocktypeMap: IBlocktypeMap;
|
|
13
|
+
overwriteLinkButton?: ToolbarButtonComponent;
|
|
14
|
+
overwriteLinksRemoveButton?: ToolbarButtonComponent;
|
|
15
|
+
customToolbarButtons?: ToolbarButtonComponent[];
|
|
16
|
+
draftJsProps: Partial<Pick<DraftJsEditorProps, "placeholder" | "autoComplete" | "autoCorrect" | "readOnly" | "spellCheck" | "stripPastedStyles" | "tabIndex" | "editorKey" | "handlePastedText">>;
|
|
17
|
+
filterEditorStateBeforeUpdate?: FilterEditorStateBeforeUpdateFn;
|
|
18
|
+
maxBlocks?: number;
|
|
19
|
+
standardBlockType: DraftBlockType;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated use `blocktypeMap` instead
|
|
22
|
+
*/
|
|
23
|
+
customBlockMap?: ICustomBlockTypeMap_Deprecated;
|
|
24
|
+
customInlineStyles?: CustomInlineStyles;
|
|
25
|
+
disableContentTranslation?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type IOptions = Partial<IRteOptions>;
|
|
28
|
+
type OnEditorStateChangeFn = (newValue: EditorState) => void;
|
|
29
|
+
export type FilterEditorStateBeforeUpdateFn = (newState: EditorState, context: Pick<IRteOptions, "supports" | "listLevelMax" | "maxBlocks" | "standardBlockType">) => EditorState;
|
|
30
|
+
export interface RteProps extends ThemedComponentBaseProps<{
|
|
31
|
+
root: "div";
|
|
32
|
+
editor: "div";
|
|
33
|
+
}> {
|
|
34
|
+
value: EditorState;
|
|
35
|
+
onChange: OnEditorStateChangeFn;
|
|
36
|
+
options?: IOptions;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
minHeight?: number;
|
|
39
|
+
colors?: Partial<RteThemeColors>;
|
|
40
|
+
}
|
|
41
|
+
export declare const defaultOptions: IRteOptions;
|
|
42
|
+
export interface IRteRef {
|
|
43
|
+
focus: () => void;
|
|
44
|
+
}
|
|
45
|
+
export declare const styleMap: {
|
|
46
|
+
SUP: {
|
|
47
|
+
verticalAlign: string;
|
|
48
|
+
fontSize: string;
|
|
49
|
+
};
|
|
50
|
+
SUB: {
|
|
51
|
+
verticalAlign: string;
|
|
52
|
+
fontSize: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export declare const Rte: ForwardRefExoticComponent<PropsWithoutRef<RteProps> & RefAttributes<unknown>>;
|
|
56
|
+
export type RteClassKey = "root" | "disabled" | "editor";
|
|
57
|
+
declare module "@mui/material/styles" {
|
|
58
|
+
interface ComponentNameToClassKey {
|
|
59
|
+
CometAdminRte: RteClassKey;
|
|
60
|
+
}
|
|
61
|
+
interface ComponentsPropsList {
|
|
62
|
+
CometAdminRte: RteProps;
|
|
63
|
+
}
|
|
64
|
+
interface Components {
|
|
65
|
+
CometAdminRte?: {
|
|
66
|
+
defaultProps?: Partial<ComponentsPropsList["CometAdminRte"]>;
|
|
67
|
+
styleOverrides?: ComponentsOverrides<Theme>["CometAdminRte"];
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=Rte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rte.d.ts","sourceRoot":"","sources":["../../src/core/Rte.tsx"],"names":[],"mappings":"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"}
|
package/lib/core/Rte.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
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); }
|
|
2
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
3
|
+
var _excluded = ["value", "onChange", "options", "disabled", "minHeight", "colors", "slotProps"];
|
|
4
|
+
function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
|
|
5
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
6
|
+
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."); }
|
|
7
|
+
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; } }
|
|
8
|
+
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; }
|
|
9
|
+
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; } }
|
|
10
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
11
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
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; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
|
+
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); }
|
|
16
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
17
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
18
|
+
import "draft-js/dist/Draft.css"; // important for nesting of ul/ol
|
|
19
|
+
|
|
20
|
+
import { createComponentSlot } from "@dextinity/admin";
|
|
21
|
+
import { css, useThemeProps } from "@mui/material";
|
|
22
|
+
import { Editor as DraftJsEditor, getDefaultKeyBinding, RichUtils } from "draft-js";
|
|
23
|
+
import { onDraftEditorCopy, onDraftEditorCut } from "draftjs-conductor";
|
|
24
|
+
import { forwardRef, useCallback, useImperativeHandle, useRef } from "react";
|
|
25
|
+
import Controls from "./Controls/Controls";
|
|
26
|
+
import defaultBlocktypeMap, { cleanBlockTypeMap, mergeBlocktypeMaps } from "./defaultBlocktypeMap";
|
|
27
|
+
import composeFilterEditorFns from "./filterEditor/composeFilterEditorFns";
|
|
28
|
+
import defaultFilterEditorStateBeforeUpdate from "./filterEditor/default";
|
|
29
|
+
import manageDefaultBlockType from "./filterEditor/manageStandardBlockType";
|
|
30
|
+
import removeBlocksExceedingBlockLimit from "./filterEditor/removeBlocksExceedingBlockLimit";
|
|
31
|
+
import createBlockRenderMap from "./utils/createBlockRenderMap";
|
|
32
|
+
import getRteTheme from "./utils/getRteTheme";
|
|
33
|
+
import { pasteAndFilterText } from "./utils/pasteAndFilterText";
|
|
34
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
35
|
+
var mandatoryFilterEditorStateFn = composeFilterEditorFns([removeBlocksExceedingBlockLimit, manageDefaultBlockType]);
|
|
36
|
+
export var defaultOptions = {
|
|
37
|
+
supports: ["bold", "italic", "sub", "sup", "header-one", "header-two", "header-three", "ordered-list", "unordered-list", "history", "link", "links-remove"],
|
|
38
|
+
listLevelMax: 4,
|
|
39
|
+
customToolbarButtons: [],
|
|
40
|
+
draftJsProps: {},
|
|
41
|
+
filterEditorStateBeforeUpdate: defaultFilterEditorStateBeforeUpdate,
|
|
42
|
+
maxBlocks: undefined,
|
|
43
|
+
// standardBlockType can be set to any supported block-type,
|
|
44
|
+
// when set to something other than "unstyled" the unstyled-blockType is disabled (does not show up in the Dropdown)
|
|
45
|
+
standardBlockType: "unstyled",
|
|
46
|
+
blocktypeMap: defaultBlocktypeMap
|
|
47
|
+
};
|
|
48
|
+
export var styleMap = {
|
|
49
|
+
SUP: {
|
|
50
|
+
verticalAlign: "super",
|
|
51
|
+
fontSize: "smaller"
|
|
52
|
+
},
|
|
53
|
+
SUB: {
|
|
54
|
+
verticalAlign: "sub",
|
|
55
|
+
fontSize: "smaller"
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
export var Rte = /*#__PURE__*/forwardRef(function (inProps, ref) {
|
|
59
|
+
var _useThemeProps = useThemeProps({
|
|
60
|
+
props: inProps,
|
|
61
|
+
name: "CometAdminRte"
|
|
62
|
+
}),
|
|
63
|
+
editorState = _useThemeProps.value,
|
|
64
|
+
onChange = _useThemeProps.onChange,
|
|
65
|
+
passedOptions = _useThemeProps.options,
|
|
66
|
+
disabled = _useThemeProps.disabled,
|
|
67
|
+
minHeight = _useThemeProps.minHeight,
|
|
68
|
+
colors = _useThemeProps.colors,
|
|
69
|
+
slotProps = _useThemeProps.slotProps,
|
|
70
|
+
restProps = _objectWithoutProperties(_useThemeProps, _excluded);
|
|
71
|
+
var ownerState = {
|
|
72
|
+
disabled: disabled,
|
|
73
|
+
minHeight: minHeight
|
|
74
|
+
};
|
|
75
|
+
var editorRef = useRef(null);
|
|
76
|
+
var editorWrapperRef = useRef(null);
|
|
77
|
+
|
|
78
|
+
// merge default options with passed options
|
|
79
|
+
var options = passedOptions ? _objectSpread(_objectSpread({}, defaultOptions), passedOptions) : defaultOptions;
|
|
80
|
+
|
|
81
|
+
// extract deprecated options and handle them specially
|
|
82
|
+
var deprecatedCustomBlockMap = {};
|
|
83
|
+
if (options.customBlockMap) {
|
|
84
|
+
deprecatedCustomBlockMap = options.customBlockMap;
|
|
85
|
+
delete options.customBlockMap;
|
|
86
|
+
}
|
|
87
|
+
cleanBlockTypeMap(options.blocktypeMap); // mutate object and print warning when configuration is wrong
|
|
88
|
+
|
|
89
|
+
// blocktypes need an extra merge as they have their own merge strategy
|
|
90
|
+
options = _objectSpread(_objectSpread({}, options), {}, {
|
|
91
|
+
blocktypeMap: mergeBlocktypeMaps(defaultBlocktypeMap, deprecatedCustomBlockMap, options.blocktypeMap)
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// force draftjs to be readonly when rte is disabled
|
|
95
|
+
if (disabled) {
|
|
96
|
+
options.draftJsProps = _objectSpread(_objectSpread({}, options.draftJsProps), {}, {
|
|
97
|
+
readOnly: true
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Expose methods
|
|
103
|
+
*/
|
|
104
|
+
useImperativeHandle(ref, function () {
|
|
105
|
+
return {
|
|
106
|
+
focus: function focus() {
|
|
107
|
+
if (editorRef && editorRef.current) {
|
|
108
|
+
editorRef.current.focus();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
var _options = options,
|
|
114
|
+
filterEditorStateBeforeUpdate = _options.filterEditorStateBeforeUpdate,
|
|
115
|
+
supports = _options.supports,
|
|
116
|
+
listLevelMax = _options.listLevelMax,
|
|
117
|
+
maxBlocks = _options.maxBlocks,
|
|
118
|
+
standardBlockType = _options.standardBlockType;
|
|
119
|
+
var decoratedOnChange = useCallback(function (nextEditorState) {
|
|
120
|
+
var modifiedState = nextEditorState;
|
|
121
|
+
var context = {
|
|
122
|
+
supports: supports,
|
|
123
|
+
listLevelMax: listLevelMax,
|
|
124
|
+
maxBlocks: maxBlocks,
|
|
125
|
+
standardBlockType: standardBlockType
|
|
126
|
+
};
|
|
127
|
+
// apply optional filter to editorState
|
|
128
|
+
if (filterEditorStateBeforeUpdate) {
|
|
129
|
+
modifiedState = filterEditorStateBeforeUpdate(modifiedState, context);
|
|
130
|
+
}
|
|
131
|
+
// apply mandatory filter to editorState
|
|
132
|
+
modifiedState = mandatoryFilterEditorStateFn(modifiedState, context);
|
|
133
|
+
|
|
134
|
+
// pass the modified filter to original onChange
|
|
135
|
+
onChange(modifiedState);
|
|
136
|
+
}, [filterEditorStateBeforeUpdate, supports, listLevelMax, maxBlocks, standardBlockType, onChange]);
|
|
137
|
+
var blockRenderMap = createBlockRenderMap({
|
|
138
|
+
blocktypeMap: options.blocktypeMap
|
|
139
|
+
});
|
|
140
|
+
function handleKeyCommand(command) {
|
|
141
|
+
var commandToSupportsMap = {
|
|
142
|
+
bold: "bold",
|
|
143
|
+
italic: "italic",
|
|
144
|
+
strikethrough: "strikethrough",
|
|
145
|
+
underline: "underline"
|
|
146
|
+
};
|
|
147
|
+
var relevantSupports = commandToSupportsMap[command];
|
|
148
|
+
if (relevantSupports && options.supports.includes(relevantSupports)) {
|
|
149
|
+
var _newState = RichUtils.handleKeyCommand(editorState, command);
|
|
150
|
+
if (_newState) {
|
|
151
|
+
onChange(_newState);
|
|
152
|
+
return "handled";
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// disallow user to add a new block when block limit is already reached
|
|
157
|
+
if (command === "split-block" && options.maxBlocks) {
|
|
158
|
+
var content = editorState.getCurrentContent();
|
|
159
|
+
var blockSize = content.getBlockMap().count();
|
|
160
|
+
var userTriesToAddTooMuchBlocks = blockSize >= options.maxBlocks;
|
|
161
|
+
if (userTriesToAddTooMuchBlocks) {
|
|
162
|
+
return "handled"; // do nothing
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return "not-handled";
|
|
166
|
+
}
|
|
167
|
+
function handleReturn(e, innerEditorState) {
|
|
168
|
+
// inserts a newline "\n" on SHIFT+ENTER-key
|
|
169
|
+
if (e.shiftKey) {
|
|
170
|
+
onChange(RichUtils.insertSoftNewline(innerEditorState));
|
|
171
|
+
return "handled";
|
|
172
|
+
}
|
|
173
|
+
return "not-handled";
|
|
174
|
+
}
|
|
175
|
+
function keyBindingFn(event) {
|
|
176
|
+
if (event.key === "Tab") {
|
|
177
|
+
// nested lists for ol and ul
|
|
178
|
+
event.preventDefault();
|
|
179
|
+
var newEditorState = RichUtils.onTab(event, editorState, options.listLevelMax);
|
|
180
|
+
if (newEditorState !== editorState) {
|
|
181
|
+
onChange(newEditorState);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return getDefaultKeyBinding(event);
|
|
185
|
+
}
|
|
186
|
+
var customStyleMap = _objectSpread({}, styleMap);
|
|
187
|
+
if (options.customInlineStyles) {
|
|
188
|
+
Object.entries(options.customInlineStyles).forEach(function (_ref) {
|
|
189
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
190
|
+
name = _ref2[0],
|
|
191
|
+
style = _ref2[1].style;
|
|
192
|
+
customStyleMap[name] = style;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return /*#__PURE__*/_jsxs(Root, _objectSpread(_objectSpread(_objectSpread({
|
|
196
|
+
ref: editorWrapperRef,
|
|
197
|
+
ownerState: ownerState
|
|
198
|
+
}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.root), restProps), {}, {
|
|
199
|
+
children: [/*#__PURE__*/_jsx(Controls, {
|
|
200
|
+
editorRef: editorRef,
|
|
201
|
+
editorState: editorState,
|
|
202
|
+
setEditorState: onChange,
|
|
203
|
+
options: options,
|
|
204
|
+
disabled: disabled
|
|
205
|
+
}), /*#__PURE__*/_jsx(Editor, _objectSpread(_objectSpread({
|
|
206
|
+
ownerState: ownerState
|
|
207
|
+
}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.editor), {}, {
|
|
208
|
+
children: /*#__PURE__*/_jsx(DraftJsEditor, _objectSpread({
|
|
209
|
+
ref: editorRef,
|
|
210
|
+
editorState: editorState,
|
|
211
|
+
onChange: decoratedOnChange,
|
|
212
|
+
handleKeyCommand: handleKeyCommand,
|
|
213
|
+
handleReturn: handleReturn,
|
|
214
|
+
keyBindingFn: keyBindingFn,
|
|
215
|
+
customStyleMap: customStyleMap,
|
|
216
|
+
blockRenderMap: blockRenderMap,
|
|
217
|
+
onCopy: function onCopy(editor, event) {
|
|
218
|
+
onDraftEditorCopy(editor, event);
|
|
219
|
+
},
|
|
220
|
+
onCut: function onCut(editor, event) {
|
|
221
|
+
onDraftEditorCut(editor, event);
|
|
222
|
+
},
|
|
223
|
+
handlePastedText: function handlePastedText(text, html, editorState) {
|
|
224
|
+
var nextEditorState = pasteAndFilterText(html, editorState, options);
|
|
225
|
+
if (nextEditorState) {
|
|
226
|
+
decoratedOnChange(nextEditorState);
|
|
227
|
+
return "handled";
|
|
228
|
+
}
|
|
229
|
+
return "not-handled";
|
|
230
|
+
}
|
|
231
|
+
}, options.draftJsProps))
|
|
232
|
+
}))]
|
|
233
|
+
}));
|
|
234
|
+
});
|
|
235
|
+
var Root = createComponentSlot("div")({
|
|
236
|
+
componentName: "Rte",
|
|
237
|
+
slotName: "root",
|
|
238
|
+
classesResolver: function classesResolver(ownerState) {
|
|
239
|
+
return [ownerState.disabled && "disabled"];
|
|
240
|
+
}
|
|
241
|
+
})(function (_ref3) {
|
|
242
|
+
var _theme$components, _theme$components2, _theme$components3;
|
|
243
|
+
var theme = _ref3.theme;
|
|
244
|
+
return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --comet-admin-rte-outer-border-color: ", ";\n border: 1px solid var(--comet-admin-rte-outer-border-color);\n border-top-width: 0; // To prevent the top border from being hidden, when to toolbar is sticky, the top border must be handled by the Toolbar itself\n background-color: #fff;\n border-radius: 2px;\n\n &:hover {\n --comet-admin-rte-outer-border-color: ", ";\n }\n\n &:focus-within {\n --comet-admin-rte-outer-border-color: ", ";\n }\n "])), getRteTheme((_theme$components = theme.components) === null || _theme$components === void 0 || (_theme$components = _theme$components.CometAdminRte) === null || _theme$components === void 0 ? void 0 : _theme$components.defaultProps).colors.border, getRteTheme((_theme$components2 = theme.components) === null || _theme$components2 === void 0 || (_theme$components2 = _theme$components2.CometAdminRte) === null || _theme$components2 === void 0 ? void 0 : _theme$components2.defaultProps).colors.outerBorderOnHover, getRteTheme((_theme$components3 = theme.components) === null || _theme$components3 === void 0 || (_theme$components3 = _theme$components3.CometAdminRte) === null || _theme$components3 === void 0 ? void 0 : _theme$components3.defaultProps).colors.outerBorderOnFocus);
|
|
245
|
+
});
|
|
246
|
+
var Editor = createComponentSlot("div")({
|
|
247
|
+
componentName: "Rte",
|
|
248
|
+
slotName: "editor",
|
|
249
|
+
classesResolver: function classesResolver(ownerState) {
|
|
250
|
+
return [ownerState.disabled && "disabled"];
|
|
251
|
+
}
|
|
252
|
+
})(function (_ref4) {
|
|
253
|
+
var ownerState = _ref4.ownerState,
|
|
254
|
+
theme = _ref4.theme;
|
|
255
|
+
return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n & .public-DraftEditor-content {\n min-height: 240px;\n\n ", "\n\n padding: 20px;\n box-sizing: border-box;\n }\n\n ", "\n "])), ownerState.minHeight !== undefined && css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n min-height: ", ";\n "])), "".concat(ownerState.minHeight, "px")), ownerState.disabled && css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n color: ", ";\n "])), theme.palette.text.disabled));
|
|
256
|
+
});
|