@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 @@
|
|
|
1
|
+
{"version":3,"file":"removeInlineStyles.d.ts","sourceRoot":"","sources":["../../../../src/core/filterEditor/utils/removeInlineStyles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAExE,KAAK,cAAc,GAAG,eAAe,EAAE,CAAC;AAGxC,QAAA,MAAM,kBAAkB,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,mBA6B7D,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CharacterMetadata, EditorState } from "draft-js";
|
|
2
|
+
// inspired by export const filterInlineStyles = (
|
|
3
|
+
var removeInlineStyles = function removeInlineStyles(blockBlacklist) {
|
|
4
|
+
return function (nextState) {
|
|
5
|
+
var content = nextState.getCurrentContent();
|
|
6
|
+
var blockMap = content.getBlockMap();
|
|
7
|
+
var changedBlocks = blockMap.map(function (block) {
|
|
8
|
+
var altered = false;
|
|
9
|
+
var chars = block.getCharacterList().map(function (_char) {
|
|
10
|
+
var newChar = _char;
|
|
11
|
+
_char.getStyle().filter(function (type) {
|
|
12
|
+
return blockBlacklist.includes(type);
|
|
13
|
+
}).forEach(function (type) {
|
|
14
|
+
altered = true;
|
|
15
|
+
newChar = CharacterMetadata.removeStyle(newChar, type);
|
|
16
|
+
});
|
|
17
|
+
return newChar;
|
|
18
|
+
});
|
|
19
|
+
return altered ? block.set("characterList", chars) : block;
|
|
20
|
+
});
|
|
21
|
+
return EditorState.set(nextState, {
|
|
22
|
+
currentContent: content.merge({
|
|
23
|
+
blockMap: blockMap.merge(changedBlocks)
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export default removeInlineStyles;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ContentState, type DraftDecorator, EditorState } from "draft-js";
|
|
2
|
+
export interface IMakeRteApiProps<T = any> {
|
|
3
|
+
decorators?: DraftDecorator[];
|
|
4
|
+
parse?: (v: T) => ContentState;
|
|
5
|
+
format?: (v: ContentState) => T;
|
|
6
|
+
}
|
|
7
|
+
export type IRteApiProps<T = any> = Partial<IRteApiOptions<T>>;
|
|
8
|
+
interface IRteApiOptions<T = any> {
|
|
9
|
+
defaultValue?: T;
|
|
10
|
+
onDebouncedContentChange?: OnDebouncedContentChangeFn<T>;
|
|
11
|
+
debounceDelay: number;
|
|
12
|
+
}
|
|
13
|
+
export type OnDebouncedContentChangeFn<T = any> = (debouncedEditorState: EditorState, convertStateToRawContent: (e: EditorState) => T) => void;
|
|
14
|
+
declare function makeRteApi<T = any>(o?: IMakeRteApiProps<T>): [(passedProps?: IRteApiProps<T>) => {
|
|
15
|
+
createEmptyState: () => EditorState;
|
|
16
|
+
createStateFromRawContent: (rawContent: T) => EditorState;
|
|
17
|
+
convertStateToRawContent: (es: EditorState) => T;
|
|
18
|
+
editorState: EditorState;
|
|
19
|
+
setEditorState: import("react").Dispatch<import("react").SetStateAction<EditorState>>;
|
|
20
|
+
}, {
|
|
21
|
+
createEmptyState: () => EditorState;
|
|
22
|
+
createStateFromRawContent: (rawContent: T) => EditorState;
|
|
23
|
+
convertStateToRawContent: (es: EditorState) => T;
|
|
24
|
+
}];
|
|
25
|
+
export default makeRteApi;
|
|
26
|
+
//# sourceMappingURL=makeRteApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeRteApi.d.ts","sourceRoot":"","sources":["../../src/core/makeRteApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,YAAY,EAGjB,KAAK,cAAc,EACnB,WAAW,EAEd,MAAM,UAAU,CAAC;AASlB,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,GAAG;IACrC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,YAAY,CAAC;IAC/B,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,YAAY,CAAC,CAAC,GAAG,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/D,UAAU,cAAc,CAAC,CAAC,GAAG,GAAG;IAC5B,YAAY,CAAC,EAAE,CAAC,CAAC;IACjB,wBAAwB,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAC;IACzD,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,MAAM,0BAA0B,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,oBAAoB,EAAE,WAAW,EAAE,wBAAwB,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,CAAC,KAAK,IAAI,CAAC;AAe/I,iBAAS,UAAU,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,mBAoBf,YAAY,CAAC,CAAC,CAAC;;4CARD,CAAC;mCAIV,WAAW;;;;;4CAJF,CAAC;mCAIV,WAAW;GAiCpD;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
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."); }
|
|
4
|
+
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; } }
|
|
5
|
+
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; }
|
|
6
|
+
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; } }
|
|
7
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
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; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
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";
|
|
20
|
+
var defaultRteApiOptions = {
|
|
21
|
+
debounceDelay: 400
|
|
22
|
+
};
|
|
23
|
+
function defaultParseContent(v) {
|
|
24
|
+
var rawDraft = JSON.parse(v);
|
|
25
|
+
return convertFromRaw(rawDraft);
|
|
26
|
+
}
|
|
27
|
+
function defaultFormatContent(v) {
|
|
28
|
+
return JSON.stringify(convertToRaw(v));
|
|
29
|
+
}
|
|
30
|
+
function makeRteApi(o) {
|
|
31
|
+
var _ref = o || {},
|
|
32
|
+
_ref$decorators = _ref.decorators,
|
|
33
|
+
decorators = _ref$decorators === void 0 ? [LinkDecorator] : _ref$decorators,
|
|
34
|
+
_ref$parse = _ref.parse,
|
|
35
|
+
parse = _ref$parse === void 0 ? defaultParseContent : _ref$parse,
|
|
36
|
+
_ref$format = _ref.format,
|
|
37
|
+
format = _ref$format === void 0 ? defaultFormatContent : _ref$format;
|
|
38
|
+
|
|
39
|
+
// Add default decorators
|
|
40
|
+
decorators.push(NonBreakingSpaceDecorator, SoftHyphenDecorator);
|
|
41
|
+
var decorator = new CompositeDecorator(decorators);
|
|
42
|
+
function createEmptyState() {
|
|
43
|
+
return EditorState.createEmpty(decorator);
|
|
44
|
+
}
|
|
45
|
+
function createStateFromRawContent(rawContent) {
|
|
46
|
+
return EditorState.createWithContent(parse(rawContent), decorator);
|
|
47
|
+
}
|
|
48
|
+
function convertStateToRawContent(es) {
|
|
49
|
+
return format(es.getCurrentContent());
|
|
50
|
+
}
|
|
51
|
+
function useRteApi(passedProps) {
|
|
52
|
+
var options = passedProps ? _objectSpread(_objectSpread({}, defaultRteApiOptions), passedProps) : defaultRteApiOptions; // merge default options with passed props
|
|
53
|
+
var defaultValue = options.defaultValue,
|
|
54
|
+
onDebouncedContentChange = options.onDebouncedContentChange,
|
|
55
|
+
debounceDelay = options.debounceDelay;
|
|
56
|
+
var _useState = useState(defaultValue ? createStateFromRawContent(defaultValue) : createEmptyState()),
|
|
57
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
58
|
+
editorState = _useState2[0],
|
|
59
|
+
setEditorState = _useState2[1];
|
|
60
|
+
var debouncedEditorState = useDebounce(editorState, debounceDelay);
|
|
61
|
+
var previousDebouncedContent = usePrevious(debouncedEditorState.getCurrentContent());
|
|
62
|
+
var debouncedContent = debouncedEditorState.getCurrentContent();
|
|
63
|
+
useEffect(function () {
|
|
64
|
+
if (onDebouncedContentChange) {
|
|
65
|
+
if (previousDebouncedContent !== debouncedContent) {
|
|
66
|
+
onDebouncedContentChange(debouncedEditorState, convertStateToRawContent);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, [debouncedContent, previousDebouncedContent, debouncedEditorState, onDebouncedContentChange]);
|
|
70
|
+
return {
|
|
71
|
+
createEmptyState: createEmptyState,
|
|
72
|
+
createStateFromRawContent: createStateFromRawContent,
|
|
73
|
+
convertStateToRawContent: convertStateToRawContent,
|
|
74
|
+
editorState: editorState,
|
|
75
|
+
setEditorState: setEditorState
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
var staticFunctions = {
|
|
79
|
+
createEmptyState: createEmptyState,
|
|
80
|
+
createStateFromRawContent: createStateFromRawContent,
|
|
81
|
+
convertStateToRawContent: convertStateToRawContent
|
|
82
|
+
};
|
|
83
|
+
var api = [useRteApi, staticFunctions];
|
|
84
|
+
return api;
|
|
85
|
+
}
|
|
86
|
+
export default makeRteApi;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EditorState } from "draft-js";
|
|
2
|
+
interface EditorStateTranslationDialogProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
originalText: EditorState;
|
|
6
|
+
translatedText: EditorState;
|
|
7
|
+
onApplyTranslation: (newValue: EditorState) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const EditorStateTranslationDialog: (props: EditorStateTranslationDialogProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=EditorStateTranslationDialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditorStateTranslationDialog.d.ts","sourceRoot":"","sources":["../../../src/core/translation/EditorStateTranslationDialog.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAK5C,UAAU,iCAAiC;IACvC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,YAAY,EAAE,WAAW,CAAC;IAC1B,cAAc,EAAE,WAAW,CAAC;IAC5B,kBAAkB,EAAE,CAAC,QAAQ,EAAE,WAAW,KAAK,IAAI,CAAC;CACvD;AAED,eAAO,MAAM,4BAA4B,GAAI,OAAO,iCAAiC,4CAcpF,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BaseTranslationDialog } from "@dextinity/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) {
|
|
6
|
+
var open = props.open,
|
|
7
|
+
onClose = props.onClose,
|
|
8
|
+
originalText = props.originalText,
|
|
9
|
+
translatedText = props.translatedText,
|
|
10
|
+
onApplyTranslation = props.onApplyTranslation;
|
|
11
|
+
return /*#__PURE__*/_jsx(BaseTranslationDialog, {
|
|
12
|
+
open: open,
|
|
13
|
+
onClose: onClose,
|
|
14
|
+
originalText: originalText,
|
|
15
|
+
translatedText: translatedText,
|
|
16
|
+
onApplyTranslation: onApplyTranslation,
|
|
17
|
+
renderOriginalText: function renderOriginalText(text) {
|
|
18
|
+
return /*#__PURE__*/_jsx(RteReadOnly, {
|
|
19
|
+
value: text
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
renderTranslatedText: function renderTranslatedText(text, onChange) {
|
|
23
|
+
return /*#__PURE__*/_jsx(Rte, {
|
|
24
|
+
value: text,
|
|
25
|
+
onChange: onChange,
|
|
26
|
+
options: {
|
|
27
|
+
disableContentTranslation: true
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolbarButton.d.ts","sourceRoot":"","sources":["../../../src/core/translation/ToolbarButton.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAK9C,iBAAS,aAAa,CAAC,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,aAAa,2CA6C7E;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
2
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
3
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
4
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
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
|
+
import { Tooltip, useContentTranslationService } from "@dextinity/admin";
|
|
12
|
+
import { Translate } from "@dextinity/admin-icons";
|
|
13
|
+
import { useState } from "react";
|
|
14
|
+
import { FormattedMessage } from "react-intl";
|
|
15
|
+
import { ControlButton } from "../Controls/ControlButton";
|
|
16
|
+
import { EditorStateTranslationDialog } from "./EditorStateTranslationDialog";
|
|
17
|
+
import { htmlToState } from "./htmlToState";
|
|
18
|
+
import { stateToHtml } from "./stateToHtml";
|
|
19
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
function ToolbarButton(_ref) {
|
|
21
|
+
var editorState = _ref.editorState,
|
|
22
|
+
setEditorState = _ref.setEditorState,
|
|
23
|
+
options = _ref.options;
|
|
24
|
+
var translationContext = useContentTranslationService();
|
|
25
|
+
var _useState = useState(false),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
open = _useState2[0],
|
|
28
|
+
setOpen = _useState2[1];
|
|
29
|
+
var _useState3 = useState(undefined),
|
|
30
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
31
|
+
pendingTranslation = _useState4[0],
|
|
32
|
+
setPendingTranslation = _useState4[1];
|
|
33
|
+
function handleClick(_x) {
|
|
34
|
+
return _handleClick.apply(this, arguments);
|
|
35
|
+
}
|
|
36
|
+
function _handleClick() {
|
|
37
|
+
_handleClick = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(event) {
|
|
38
|
+
var _stateToHtml, html, entities, translation, translatedEditorState;
|
|
39
|
+
return _regenerator().w(function (_context) {
|
|
40
|
+
while (1) switch (_context.n) {
|
|
41
|
+
case 0:
|
|
42
|
+
if (translationContext) {
|
|
43
|
+
_context.n = 1;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
return _context.a(2);
|
|
47
|
+
case 1:
|
|
48
|
+
event.preventDefault();
|
|
49
|
+
_stateToHtml = stateToHtml({
|
|
50
|
+
editorState: editorState,
|
|
51
|
+
options: options
|
|
52
|
+
}), html = _stateToHtml.html, entities = _stateToHtml.entities;
|
|
53
|
+
_context.n = 2;
|
|
54
|
+
return translationContext.translate(html);
|
|
55
|
+
case 2:
|
|
56
|
+
translation = _context.v;
|
|
57
|
+
translatedEditorState = htmlToState({
|
|
58
|
+
html: translation,
|
|
59
|
+
entities: entities
|
|
60
|
+
});
|
|
61
|
+
if (translationContext.showApplyTranslationDialog) {
|
|
62
|
+
setPendingTranslation(translatedEditorState);
|
|
63
|
+
setOpen(true);
|
|
64
|
+
} else {
|
|
65
|
+
setEditorState(translatedEditorState);
|
|
66
|
+
}
|
|
67
|
+
case 3:
|
|
68
|
+
return _context.a(2);
|
|
69
|
+
}
|
|
70
|
+
}, _callee);
|
|
71
|
+
}));
|
|
72
|
+
return _handleClick.apply(this, arguments);
|
|
73
|
+
}
|
|
74
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
75
|
+
children: [/*#__PURE__*/_jsx(Tooltip, {
|
|
76
|
+
title: /*#__PURE__*/_jsx(FormattedMessage, {
|
|
77
|
+
id: "comet.rte.translation.buttonTooltip",
|
|
78
|
+
defaultMessage: "Translate"
|
|
79
|
+
}),
|
|
80
|
+
placement: "top",
|
|
81
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
82
|
+
children: /*#__PURE__*/_jsx(ControlButton, {
|
|
83
|
+
icon: Translate,
|
|
84
|
+
onButtonClick: handleClick
|
|
85
|
+
})
|
|
86
|
+
})
|
|
87
|
+
}), open && pendingTranslation && /*#__PURE__*/_jsx(EditorStateTranslationDialog, {
|
|
88
|
+
open: open,
|
|
89
|
+
onClose: function onClose() {
|
|
90
|
+
return setOpen(false);
|
|
91
|
+
},
|
|
92
|
+
originalText: editorState,
|
|
93
|
+
translatedText: pendingTranslation,
|
|
94
|
+
onApplyTranslation: setEditorState
|
|
95
|
+
})]
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
export default ToolbarButton;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlToState.d.ts","sourceRoot":"","sources":["../../../src/core/translation/htmlToState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgC,WAAW,EAAE,MAAM,UAAU,CAAC;AAGrE,wBAAgB,WAAW,CAAC,EACxB,IAAI,EACJ,QAAQ,GACX,EAAE;IACC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QACN,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,GAAG,CAAC;KACb,EAAE,CAAC;CACP,eAkCA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { convertFromRaw, convertToRaw, EditorState } from "draft-js";
|
|
2
|
+
import { stateFromHTML } from "draft-js-import-html";
|
|
3
|
+
export function htmlToState(_ref) {
|
|
4
|
+
var html = _ref.html,
|
|
5
|
+
entities = _ref.entities;
|
|
6
|
+
var translatedContentState = stateFromHTML(html, {
|
|
7
|
+
customBlockFn: function customBlockFn(element) {
|
|
8
|
+
if (element.className) {
|
|
9
|
+
return {
|
|
10
|
+
type: element.className
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
customInlineFn: function customInlineFn(element, _ref2) {
|
|
15
|
+
var Style = _ref2.Style,
|
|
16
|
+
Entity = _ref2.Entity;
|
|
17
|
+
if (element.tagName === "SUB") {
|
|
18
|
+
return Style("SUB");
|
|
19
|
+
}
|
|
20
|
+
if (element.tagName === "SUP") {
|
|
21
|
+
return Style("SUP");
|
|
22
|
+
}
|
|
23
|
+
if (element.tagName == "SPAN") {
|
|
24
|
+
return Style(element.attributes["class"].value);
|
|
25
|
+
}
|
|
26
|
+
if (element.tagName === "A") {
|
|
27
|
+
return Entity("LINK", {
|
|
28
|
+
id: element.attributes.id.value
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
var _convertToRaw = convertToRaw(translatedContentState),
|
|
34
|
+
entityMap = _convertToRaw.entityMap,
|
|
35
|
+
blocks = _convertToRaw.blocks;
|
|
36
|
+
var _loop = function _loop() {
|
|
37
|
+
var key = _Object$keys[_i];
|
|
38
|
+
if ("id" in entityMap[key].data) {
|
|
39
|
+
var _entities$find;
|
|
40
|
+
entityMap[key].data = (_entities$find = entities.find(function (item) {
|
|
41
|
+
return item.id == entityMap[key].data.id;
|
|
42
|
+
})) === null || _entities$find === void 0 ? void 0 : _entities$find.data;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
for (var _i = 0, _Object$keys = Object.keys(entityMap); _i < _Object$keys.length; _i++) {
|
|
46
|
+
_loop();
|
|
47
|
+
}
|
|
48
|
+
var translatedContentStateWithLinkData = convertFromRaw({
|
|
49
|
+
entityMap: entityMap,
|
|
50
|
+
blocks: blocks
|
|
51
|
+
});
|
|
52
|
+
return EditorState.createWithContent(translatedContentStateWithLinkData);
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlToState.spec.d.ts","sourceRoot":"","sources":["../../../src/core/translation/htmlToState.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EditorState } from "draft-js";
|
|
2
|
+
import type { IOptions } from "../Rte";
|
|
3
|
+
export declare function stateToHtml({ editorState, options }: {
|
|
4
|
+
editorState: EditorState;
|
|
5
|
+
options: IOptions;
|
|
6
|
+
}): {
|
|
7
|
+
html: string;
|
|
8
|
+
entities: {
|
|
9
|
+
id: string;
|
|
10
|
+
data: any;
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=stateToHtml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateToHtml.d.ts","sourceRoot":"","sources":["../../../src/core/translation/stateToHtml.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAI5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC,wBAAgB,WAAW,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE;IAAE,WAAW,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE;;;YAc3E,MAAM;cAAQ,GAAG;;EA0B1C"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { stateToHTML } from "draft-js-export-html";
|
|
2
|
+
import defaultBlocktypeMap from "../defaultBlocktypeMap";
|
|
3
|
+
export function stateToHtml(_ref) {
|
|
4
|
+
var editorState = _ref.editorState,
|
|
5
|
+
options = _ref.options;
|
|
6
|
+
var contentState = editorState.getCurrentContent();
|
|
7
|
+
var customInlineStyleKeys = options !== null && options !== void 0 && options.customInlineStyles ? Object.keys(options.customInlineStyles) : [];
|
|
8
|
+
var inlineStyles = {
|
|
9
|
+
SUB: {
|
|
10
|
+
element: "sub"
|
|
11
|
+
},
|
|
12
|
+
SUP: {
|
|
13
|
+
element: "sup"
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
customInlineStyleKeys.forEach(function (item) {
|
|
17
|
+
inlineStyles[item] = {
|
|
18
|
+
element: "span",
|
|
19
|
+
attributes: {
|
|
20
|
+
"class": [item]
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
var entities = [];
|
|
25
|
+
var html = stateToHTML(contentState, {
|
|
26
|
+
inlineStyles: inlineStyles,
|
|
27
|
+
blockStyleFn: function blockStyleFn(block) {
|
|
28
|
+
var type = block.getType();
|
|
29
|
+
if (!Object.keys(defaultBlocktypeMap).includes(type)) {
|
|
30
|
+
return {
|
|
31
|
+
attributes: {
|
|
32
|
+
"class": type
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
entityStyleFn: function entityStyleFn(entity) {
|
|
38
|
+
var entityType = entity.getType();
|
|
39
|
+
var data = entity.getData();
|
|
40
|
+
if (entityType === "LINK") {
|
|
41
|
+
var id = "".concat(entities.length);
|
|
42
|
+
entities.push({
|
|
43
|
+
id: id,
|
|
44
|
+
data: data
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
element: "a",
|
|
48
|
+
attributes: {
|
|
49
|
+
id: id
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
throw Error("The entityType ".concat(entityType, " is not supported."));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
html: html,
|
|
58
|
+
entities: entities
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateToHtml.spec.d.ts","sourceRoot":"","sources":["../../../src/core/translation/stateToHtml.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { SvgIconProps } from "@mui/material/SvgIcon";
|
|
2
|
+
import type { DraftInlineStyleType, Editor, EditorState } from "draft-js";
|
|
3
|
+
import type { ComponentType, CSSProperties, ForwardRefExoticComponent, JSX, MouseEvent, ReactNode, RefAttributes, RefObject } from "react";
|
|
4
|
+
import type { IRteOptions, SupportedThings } from "./Rte";
|
|
5
|
+
interface DraftBlockRenderConfig {
|
|
6
|
+
element: string | ComponentType;
|
|
7
|
+
wrapper?: ReactNode;
|
|
8
|
+
aliasedElements?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface IBlocktypeConfig {
|
|
11
|
+
renderConfig?: DraftBlockRenderConfig;
|
|
12
|
+
label?: string | ReactNode;
|
|
13
|
+
group?: "dropdown" | "button";
|
|
14
|
+
icon?: ForwardRefExoticComponent<Omit<SvgIconProps, "ref"> & RefAttributes<SVGSVGElement>>;
|
|
15
|
+
supportedBy?: SupportedThings;
|
|
16
|
+
}
|
|
17
|
+
export interface IBlocktypeMap {
|
|
18
|
+
[key: string]: IBlocktypeConfig;
|
|
19
|
+
}
|
|
20
|
+
export interface IFeatureConfig<T extends string = string> {
|
|
21
|
+
name: T;
|
|
22
|
+
label: ReactNode;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
selected?: boolean;
|
|
25
|
+
onButtonClick?: (e: MouseEvent) => void;
|
|
26
|
+
icon?: ForwardRefExoticComponent<Omit<SvgIconProps, "ref"> & RefAttributes<SVGSVGElement>>;
|
|
27
|
+
tooltipText?: ReactNode;
|
|
28
|
+
/** @deprecated use icon instead */
|
|
29
|
+
Icon?: ForwardRefExoticComponent<Omit<SvgIconProps, "ref"> & RefAttributes<SVGSVGElement>>;
|
|
30
|
+
}
|
|
31
|
+
type CustomInlineStyleType = "SUP" | "SUB" | string;
|
|
32
|
+
export type InlineStyleType = CustomInlineStyleType | DraftInlineStyleType;
|
|
33
|
+
export interface IControlProps {
|
|
34
|
+
editorState: EditorState;
|
|
35
|
+
setEditorState: (editorState: EditorState) => void;
|
|
36
|
+
options: IRteOptions;
|
|
37
|
+
editorRef: RefObject<Editor | null>;
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export type ToolbarButtonComponent = (props: IControlProps) => JSX.Element;
|
|
41
|
+
export type FilterEditorStateFn = (nextState: EditorState) => EditorState;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated use IBlocktypeConfig instead
|
|
44
|
+
*/
|
|
45
|
+
interface ICustomBlockType_Deprecated {
|
|
46
|
+
renderConfig: DraftBlockRenderConfig;
|
|
47
|
+
label: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated use IBlocktypeMap instead
|
|
51
|
+
*/
|
|
52
|
+
export interface ICustomBlockTypeMap_Deprecated {
|
|
53
|
+
[key: string]: ICustomBlockType_Deprecated;
|
|
54
|
+
}
|
|
55
|
+
export interface CustomInlineStyles {
|
|
56
|
+
[name: string]: {
|
|
57
|
+
label: ReactNode;
|
|
58
|
+
icon?: ForwardRefExoticComponent<Omit<SvgIconProps, "ref"> & RefAttributes<SVGSVGElement>>;
|
|
59
|
+
tooltipText?: ReactNode;
|
|
60
|
+
style: CSSProperties;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
64
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as Immutable from "immutable";
|
|
2
|
+
import type { IBlocktypeMap } from "../types";
|
|
3
|
+
export default function createBlockRenderMap({ blocktypeMap }: {
|
|
4
|
+
blocktypeMap: IBlocktypeMap;
|
|
5
|
+
}): Immutable.Map<any, any>;
|
|
6
|
+
//# sourceMappingURL=createBlockRenderMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBlockRenderMap.d.ts","sourceRoot":"","sources":["../../../src/core/utils/createBlockRenderMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,UAAU,CAAC;AAEhE,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,EAAE,YAAY,EAAE,EAAE;IAAE,YAAY,EAAE,aAAa,CAAA;CAAE,2BAY7F"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
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."); }
|
|
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; } }
|
|
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; }
|
|
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; } }
|
|
6
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
import { DefaultDraftBlockRenderMap } from "draft-js";
|
|
8
|
+
import * as Immutable from "immutable";
|
|
9
|
+
export default function createBlockRenderMap(_ref) {
|
|
10
|
+
var blocktypeMap = _ref.blocktypeMap;
|
|
11
|
+
var customBlockRenderMapObject = Object.entries(blocktypeMap).reduce(function (a, _ref2) {
|
|
12
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
13
|
+
key = _ref3[0],
|
|
14
|
+
config = _ref3[1];
|
|
15
|
+
if (config.renderConfig) {
|
|
16
|
+
a[key] = config.renderConfig; // draftjs types do not match our type, but our type is more accurate
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
}, {});
|
|
20
|
+
var customBlockRenderMap = Immutable.Map(customBlockRenderMapObject);
|
|
21
|
+
return customBlockRenderMap ? DefaultDraftBlockRenderMap.merge(customBlockRenderMap) : DefaultDraftBlockRenderMap;
|
|
22
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { EditorState } from "draft-js";
|
|
2
|
+
export default function findEntityDataInCurrentSelection<T extends Record<string, any> = Record<string, any>>(editorState: EditorState, entityType: string): T | null;
|
|
3
|
+
//# sourceMappingURL=findEntityDataInCurrentSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findEntityDataInCurrentSelection.d.ts","sourceRoot":"","sources":["../../../src/core/utils/findEntityDataInCurrentSelection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAK5C,MAAM,CAAC,OAAO,UAAU,gCAAgC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACxG,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,GACnB,CAAC,GAAG,IAAI,CASV"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import findEntityInCurrentSelection from "./findEntityInCurrentSelection";
|
|
2
|
+
|
|
3
|
+
// get data for the entity
|
|
4
|
+
export default function findEntityDataInCurrentSelection(editorState, entityType) {
|
|
5
|
+
var _findEntityInCurrentS = findEntityInCurrentSelection(editorState, entityType),
|
|
6
|
+
entity = _findEntityInCurrentS.entity;
|
|
7
|
+
if (entity) {
|
|
8
|
+
var data = entity.getData();
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type EditorState, type EntityInstance, SelectionState } from "draft-js";
|
|
2
|
+
export default function findEntityInCurrentSelection(editorState: EditorState, entityType: string): {
|
|
3
|
+
entity: EntityInstance | null;
|
|
4
|
+
entitySelection: SelectionState | null;
|
|
5
|
+
entityText: string | null;
|
|
6
|
+
entityKey: null | string;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=findEntityInCurrentSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findEntityInCurrentSelection.d.ts","sourceRoot":"","sources":["../../../src/core/utils/findEntityInCurrentSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AASjF,MAAM,CAAC,OAAO,UAAU,4BAA4B,CAChD,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,GACnB;IAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAAC,eAAe,EAAE,cAAc,GAAG,IAAI,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,SAAS,EAAE,IAAI,GAAG,MAAM,CAAA;CAAE,CA4DhI"}
|