@comet/admin-rte 9.0.0-canary-20251215091807 → 9.0.0-canary-20251223085410
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/translation/htmlToState.spec.d.ts +0 -3
- package/lib/core/translation/htmlToState.spec.d.ts.map +1 -1
- package/lib/field/createFinalFormRte.d.ts +6 -1
- package/lib/field/createFinalFormRte.d.ts.map +1 -1
- package/lib/field/createFinalFormRte.js +6 -0
- package/lib/field/createRteField.d.ts +13 -0
- package/lib/field/createRteField.d.ts.map +1 -0
- package/lib/field/createRteField.js +51 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -0
- package/package.json +9 -12
- package/lib/core/translation/htmlToState.spec.js +0 -306
- package/lib/core/translation/stateToHtml.spec.js +0 -498
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlToState.spec.d.ts","sourceRoot":"","sources":["../../../src/core/translation/htmlToState.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"htmlToState.spec.d.ts","sourceRoot":"","sources":["../../../src/core/translation/htmlToState.spec.ts"],"names":[],"mappings":""}
|
|
@@ -2,10 +2,15 @@ import { type FunctionComponent } from "react";
|
|
|
2
2
|
import { type FieldRenderProps } from "react-final-form";
|
|
3
3
|
import { type IMakeRteApiProps } from "../core/makeRteApi";
|
|
4
4
|
import { type IOptions as RteOptions, type RteProps } from "../core/Rte";
|
|
5
|
-
interface IConfig<T = any> {
|
|
5
|
+
export interface IConfig<T = any> {
|
|
6
6
|
rteApiOptions?: IMakeRteApiProps<T>;
|
|
7
7
|
rteOptions?: RteOptions;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Used to create a Final Form-compatible RTE component.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link createRteField} – preferred for typical form use. Use this only if no Field wrapper is needed.
|
|
13
|
+
*/
|
|
9
14
|
declare function createFinalFormRte<T = any>(config?: IConfig<T>): {
|
|
10
15
|
RteField: FunctionComponent<FieldRenderProps<T, HTMLInputElement, T> & Pick<RteProps, "options">>;
|
|
11
16
|
RteReadOnly: FunctionComponent<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFinalFormRte.d.ts","sourceRoot":"","sources":["../../src/field/createFinalFormRte.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,iBAAiB,EAAU,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAmB,EAAE,KAAK,gBAAgB,EAAmC,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,KAAK,QAAQ,IAAI,UAAU,EAAO,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG9E,
|
|
1
|
+
{"version":3,"file":"createFinalFormRte.d.ts","sourceRoot":"","sources":["../../src/field/createFinalFormRte.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,iBAAiB,EAAU,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAmB,EAAE,KAAK,gBAAgB,EAAmC,MAAM,oBAAoB,CAAC;AACxG,OAAO,EAAE,KAAK,QAAQ,IAAI,UAAU,EAAO,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG9E,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,GAAG;IAC5B,aAAa,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IACpC,UAAU,CAAC,EAAE,UAAU,CAAC;CAC3B;AAID;;;;GAIG;AACH,iBAAS,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,GAAE,OAAO,CAAC,CAAC,CAAiB;;;kBAmClB,CAAC;wBAAkB,OAAO;;EAiB9E;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -27,6 +27,12 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
27
27
|
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; } }
|
|
28
28
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
29
29
|
var defaultConfig = {};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Used to create a Final Form-compatible RTE component.
|
|
33
|
+
*
|
|
34
|
+
* @see {@link createRteField} – preferred for typical form use. Use this only if no Field wrapper is needed.
|
|
35
|
+
*/
|
|
30
36
|
function createFinalFormRte() {
|
|
31
37
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultConfig;
|
|
32
38
|
var rteApiOptions = config.rteApiOptions,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type FieldProps } from "@comet/admin";
|
|
2
|
+
import { type FunctionComponent } from "react";
|
|
3
|
+
import { type RteProps } from "../core/Rte";
|
|
4
|
+
import { type IConfig } from "./createFinalFormRte";
|
|
5
|
+
export type RteFieldProps = FieldProps<string, HTMLInputElement> & Partial<RteProps>;
|
|
6
|
+
export declare const createRteField: (config?: IConfig) => {
|
|
7
|
+
RteField: FunctionComponent<RteFieldProps>;
|
|
8
|
+
RteReadOnly: FunctionComponent<{
|
|
9
|
+
content?: any;
|
|
10
|
+
plainTextOnly?: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=createRteField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRteField.d.ts","sourceRoot":"","sources":["../../src/field/createRteField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAA2B,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAExE,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAQrF,eAAO,MAAM,cAAc,GAAI,SAAS,OAAO;;;;;;CAQ9C,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createRteField = void 0;
|
|
8
|
+
var _admin = require("@comet/admin");
|
|
9
|
+
var _requiredValidator = require("../utils/requiredValidator");
|
|
10
|
+
var _createFinalFormRte2 = _interopRequireDefault(require("./createFinalFormRte"));
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
var _excluded = ["required", "validate"];
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
14
|
+
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; }
|
|
15
|
+
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; }
|
|
16
|
+
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; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
|
+
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); }
|
|
19
|
+
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; }
|
|
20
|
+
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; }
|
|
21
|
+
// Same as in `Field` from `@comet/admin`
|
|
22
|
+
var composeValidators = function composeValidators() {
|
|
23
|
+
for (var _len = arguments.length, validators = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
24
|
+
validators[_key] = arguments[_key];
|
|
25
|
+
}
|
|
26
|
+
return function (value, allValues) {
|
|
27
|
+
return validators.reduce(function (error, validator) {
|
|
28
|
+
return error || validator(value, allValues);
|
|
29
|
+
}, undefined);
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
var createRteField = exports.createRteField = function createRteField(config) {
|
|
33
|
+
var _createFinalFormRte = (0, _createFinalFormRte2["default"])(config),
|
|
34
|
+
RteFieldComponent = _createFinalFormRte.RteField,
|
|
35
|
+
RteReadOnly = _createFinalFormRte.RteReadOnly;
|
|
36
|
+
var RteField = function RteField(_ref) {
|
|
37
|
+
var required = _ref.required,
|
|
38
|
+
validate = _ref.validate,
|
|
39
|
+
restProps = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
+
var validateError = required ? validate ? composeValidators(_requiredValidator.requiredValidator, validate) : _requiredValidator.requiredValidator : validate;
|
|
41
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_admin.Field, _objectSpread({
|
|
42
|
+
component: RteFieldComponent,
|
|
43
|
+
required: required,
|
|
44
|
+
validate: validateError
|
|
45
|
+
}, restProps));
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
RteField: RteField,
|
|
49
|
+
RteReadOnly: RteReadOnly
|
|
50
|
+
};
|
|
51
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -25,5 +25,6 @@ export { default as findTextInCurrentSelection } from "./core/utils/findTextInCu
|
|
|
25
25
|
export { pasteAndFilterText } from "./core/utils/pasteAndFilterText";
|
|
26
26
|
export { default as selectionIsInOneBlock } from "./core/utils/selectionIsInOneBlock";
|
|
27
27
|
export { default as createFinalFormRte } from "./field/createFinalFormRte";
|
|
28
|
+
export { createRteField, type RteFieldProps } from "./field/createRteField";
|
|
28
29
|
export { requiredValidator } from "./utils/requiredValidator";
|
|
29
30
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,uBAAuB,EAAE,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC5G,OAAO,E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M,IAAI,iBAAiB,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACpI,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AACtF,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -75,6 +75,12 @@ Object.defineProperty(exports, "createFinalFormRte", {
|
|
|
75
75
|
return _createFinalFormRte["default"];
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
|
+
Object.defineProperty(exports, "createRteField", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function get() {
|
|
81
|
+
return _createRteField.createRteField;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
78
84
|
Object.defineProperty(exports, "filterEditorStateDefault", {
|
|
79
85
|
enumerable: true,
|
|
80
86
|
get: function get() {
|
|
@@ -191,5 +197,6 @@ var _findTextInCurrentSelection = _interopRequireDefault(require("./core/utils/f
|
|
|
191
197
|
var _pasteAndFilterText = require("./core/utils/pasteAndFilterText");
|
|
192
198
|
var _selectionIsInOneBlock = _interopRequireDefault(require("./core/utils/selectionIsInOneBlock"));
|
|
193
199
|
var _createFinalFormRte = _interopRequireDefault(require("./field/createFinalFormRte"));
|
|
200
|
+
var _createRteField = require("./field/createRteField");
|
|
194
201
|
var _requiredValidator = require("./utils/requiredValidator");
|
|
195
202
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comet/admin-rte",
|
|
3
|
-
"version": "9.0.0-canary-
|
|
3
|
+
"version": "9.0.0-canary-20251223085410",
|
|
4
4
|
"description": "Comet Admin Rich Text Editor component",
|
|
5
5
|
"repository": {
|
|
6
6
|
"directory": "packages/admin/admin-rte",
|
|
@@ -20,22 +20,19 @@
|
|
|
20
20
|
"draft-js-import-html": "^1.4.1",
|
|
21
21
|
"draftjs-conductor": "^3.0.0",
|
|
22
22
|
"immutable": "~3.8.2",
|
|
23
|
-
"@comet/admin": "9.0.0-canary-
|
|
24
|
-
"@comet/admin-icons": "9.0.0-canary-
|
|
23
|
+
"@comet/admin": "9.0.0-canary-20251223085410",
|
|
24
|
+
"@comet/admin-icons": "9.0.0-canary-20251223085410"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@babel/cli": "^7.28.3",
|
|
28
28
|
"@babel/core": "^7.28.5",
|
|
29
29
|
"@mui/material": "^7.3.5",
|
|
30
30
|
"@types/draft-js": "^0.11.20",
|
|
31
|
-
"@types/
|
|
32
|
-
"@types/react": "^18.3.23",
|
|
31
|
+
"@types/react": "^18.3.27",
|
|
33
32
|
"@types/react-dom": "^18.3.7",
|
|
34
33
|
"draft-js": "^0.11.7",
|
|
35
34
|
"eslint": "^9.30.1",
|
|
36
35
|
"final-form": "^4.20.10",
|
|
37
|
-
"jest": "^29.7.0",
|
|
38
|
-
"jest-junit": "^16.0.0",
|
|
39
36
|
"npm-run-all2": "^8.0.0",
|
|
40
37
|
"prettier": "^3.6.2",
|
|
41
38
|
"react": "^18.3.1",
|
|
@@ -43,10 +40,10 @@
|
|
|
43
40
|
"react-final-form": "^6.5.9",
|
|
44
41
|
"react-intl": "^7.1.11",
|
|
45
42
|
"rimraf": "^6.1.2",
|
|
46
|
-
"ts-jest": "^29.4.0",
|
|
47
43
|
"typescript": "5.9.3",
|
|
48
|
-
"
|
|
49
|
-
"@comet/
|
|
44
|
+
"vitest": "^4.0.16",
|
|
45
|
+
"@comet/admin-babel-preset": "9.0.0-canary-20251223085410",
|
|
46
|
+
"@comet/eslint-config": "9.0.0-canary-20251223085410"
|
|
50
47
|
},
|
|
51
48
|
"peerDependencies": {
|
|
52
49
|
"@mui/material": "^7.0.0",
|
|
@@ -77,7 +74,7 @@
|
|
|
77
74
|
"start": "run-p start:babel start:types",
|
|
78
75
|
"start:babel": "pnpm exec babel ./src -x \".ts,.tsx\" -d lib -w",
|
|
79
76
|
"start:types": "tsc --project ./tsconfig.json --emitDeclarationOnly --watch --preserveWatchOutput",
|
|
80
|
-
"test": "
|
|
81
|
-
"test:watch": "
|
|
77
|
+
"test": "vitest --run",
|
|
78
|
+
"test:watch": "vitest --watch"
|
|
82
79
|
}
|
|
83
80
|
}
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _draftJs = require("draft-js");
|
|
4
|
-
var _htmlToState = require("./htmlToState");
|
|
5
|
-
var _stateToHtml3 = require("./stateToHtml");
|
|
6
|
-
/**
|
|
7
|
-
* @jest-environment jsdom
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// TODO Remove mock once we've updated the test setup to support ESM modules
|
|
11
|
-
jest.mock("../BlockElement", function () {
|
|
12
|
-
return {
|
|
13
|
-
BlockElement: function BlockElement() {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
describe("htmlToState", function () {
|
|
19
|
-
var options = {
|
|
20
|
-
customInlineStyles: {
|
|
21
|
-
HIGHLIGHT: {
|
|
22
|
-
label: "Highlight!",
|
|
23
|
-
style: {
|
|
24
|
-
backgroundColor: "yellow"
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
it("should convert html to state to html with the html staying the same", function () {
|
|
30
|
-
var blocks = [
|
|
31
|
-
// Basic stylings
|
|
32
|
-
{
|
|
33
|
-
key: "52cmg",
|
|
34
|
-
text: "Normal Text",
|
|
35
|
-
type: "unstyled",
|
|
36
|
-
depth: 0,
|
|
37
|
-
inlineStyleRanges: [],
|
|
38
|
-
entityRanges: [],
|
|
39
|
-
data: {}
|
|
40
|
-
}, {
|
|
41
|
-
key: "8psic",
|
|
42
|
-
text: "Bold Text",
|
|
43
|
-
type: "unstyled",
|
|
44
|
-
depth: 0,
|
|
45
|
-
inlineStyleRanges: [{
|
|
46
|
-
offset: 0,
|
|
47
|
-
length: 9,
|
|
48
|
-
style: "BOLD"
|
|
49
|
-
}],
|
|
50
|
-
entityRanges: [],
|
|
51
|
-
data: {}
|
|
52
|
-
}, {
|
|
53
|
-
key: "4m6ou",
|
|
54
|
-
text: "Italic Text",
|
|
55
|
-
type: "unstyled",
|
|
56
|
-
depth: 0,
|
|
57
|
-
inlineStyleRanges: [{
|
|
58
|
-
offset: 0,
|
|
59
|
-
length: 11,
|
|
60
|
-
style: "ITALIC"
|
|
61
|
-
}],
|
|
62
|
-
entityRanges: [],
|
|
63
|
-
data: {}
|
|
64
|
-
}, {
|
|
65
|
-
key: "fask6",
|
|
66
|
-
text: "Bold Italic Text",
|
|
67
|
-
type: "unstyled",
|
|
68
|
-
depth: 0,
|
|
69
|
-
inlineStyleRanges: [{
|
|
70
|
-
offset: 0,
|
|
71
|
-
length: 16,
|
|
72
|
-
style: "ITALIC"
|
|
73
|
-
}, {
|
|
74
|
-
offset: 0,
|
|
75
|
-
length: 16,
|
|
76
|
-
style: "BOLD"
|
|
77
|
-
}],
|
|
78
|
-
entityRanges: [],
|
|
79
|
-
data: {}
|
|
80
|
-
}, {
|
|
81
|
-
key: "fm23u",
|
|
82
|
-
text: "Strikethrough Text",
|
|
83
|
-
type: "unstyled",
|
|
84
|
-
depth: 0,
|
|
85
|
-
inlineStyleRanges: [{
|
|
86
|
-
offset: 0,
|
|
87
|
-
length: 18,
|
|
88
|
-
style: "STRIKETHROUGH"
|
|
89
|
-
}],
|
|
90
|
-
entityRanges: [],
|
|
91
|
-
data: {}
|
|
92
|
-
}, {
|
|
93
|
-
key: "9q8m5",
|
|
94
|
-
text: "A Subscript Text",
|
|
95
|
-
type: "unstyled",
|
|
96
|
-
depth: 0,
|
|
97
|
-
inlineStyleRanges: [{
|
|
98
|
-
offset: 2,
|
|
99
|
-
length: 14,
|
|
100
|
-
style: "SUB"
|
|
101
|
-
}],
|
|
102
|
-
entityRanges: [],
|
|
103
|
-
data: {}
|
|
104
|
-
}, {
|
|
105
|
-
key: "t3nk",
|
|
106
|
-
text: "B Superscript Text",
|
|
107
|
-
type: "unstyled",
|
|
108
|
-
depth: 0,
|
|
109
|
-
inlineStyleRanges: [{
|
|
110
|
-
offset: 2,
|
|
111
|
-
length: 16,
|
|
112
|
-
style: "SUP"
|
|
113
|
-
}],
|
|
114
|
-
entityRanges: [],
|
|
115
|
-
data: {}
|
|
116
|
-
}, {
|
|
117
|
-
key: "e6k04",
|
|
118
|
-
text: "Headline 1",
|
|
119
|
-
type: "header-one",
|
|
120
|
-
depth: 0,
|
|
121
|
-
inlineStyleRanges: [],
|
|
122
|
-
entityRanges: [],
|
|
123
|
-
data: {}
|
|
124
|
-
}, {
|
|
125
|
-
key: "ect4f",
|
|
126
|
-
text: "Headline 2",
|
|
127
|
-
type: "header-two",
|
|
128
|
-
depth: 0,
|
|
129
|
-
inlineStyleRanges: [],
|
|
130
|
-
entityRanges: [],
|
|
131
|
-
data: {}
|
|
132
|
-
}, {
|
|
133
|
-
key: "e038j",
|
|
134
|
-
text: "Headline 3",
|
|
135
|
-
type: "header-three",
|
|
136
|
-
depth: 0,
|
|
137
|
-
inlineStyleRanges: [],
|
|
138
|
-
entityRanges: [],
|
|
139
|
-
data: {}
|
|
140
|
-
}, {
|
|
141
|
-
key: "4bha8",
|
|
142
|
-
text: "Headline 4",
|
|
143
|
-
type: "header-four",
|
|
144
|
-
depth: 0,
|
|
145
|
-
inlineStyleRanges: [],
|
|
146
|
-
entityRanges: [],
|
|
147
|
-
data: {}
|
|
148
|
-
}, {
|
|
149
|
-
key: "aje6k",
|
|
150
|
-
text: "Headline 5",
|
|
151
|
-
type: "header-five",
|
|
152
|
-
depth: 0,
|
|
153
|
-
inlineStyleRanges: [],
|
|
154
|
-
entityRanges: [],
|
|
155
|
-
data: {}
|
|
156
|
-
}, {
|
|
157
|
-
key: "7u6on",
|
|
158
|
-
text: "Headline 6",
|
|
159
|
-
type: "header-six",
|
|
160
|
-
depth: 0,
|
|
161
|
-
inlineStyleRanges: [],
|
|
162
|
-
entityRanges: [],
|
|
163
|
-
data: {}
|
|
164
|
-
},
|
|
165
|
-
// Unordered List
|
|
166
|
-
{
|
|
167
|
-
key: "a9t3",
|
|
168
|
-
text: "Unordered List",
|
|
169
|
-
type: "unordered-list-item",
|
|
170
|
-
depth: 0,
|
|
171
|
-
inlineStyleRanges: [],
|
|
172
|
-
entityRanges: [],
|
|
173
|
-
data: {}
|
|
174
|
-
}, {
|
|
175
|
-
key: "f4o2c",
|
|
176
|
-
text: "123456",
|
|
177
|
-
type: "unordered-list-item",
|
|
178
|
-
depth: 1,
|
|
179
|
-
inlineStyleRanges: [{
|
|
180
|
-
offset: 3,
|
|
181
|
-
length: 3,
|
|
182
|
-
style: "SUB"
|
|
183
|
-
}],
|
|
184
|
-
entityRanges: [],
|
|
185
|
-
data: {}
|
|
186
|
-
}, {
|
|
187
|
-
key: "7v61p",
|
|
188
|
-
text: "234",
|
|
189
|
-
type: "unordered-list-item",
|
|
190
|
-
depth: 2,
|
|
191
|
-
inlineStyleRanges: [{
|
|
192
|
-
offset: 0,
|
|
193
|
-
length: 3,
|
|
194
|
-
style: "ITALIC"
|
|
195
|
-
}],
|
|
196
|
-
entityRanges: [],
|
|
197
|
-
data: {}
|
|
198
|
-
}, {
|
|
199
|
-
key: "1duir",
|
|
200
|
-
text: "345",
|
|
201
|
-
type: "unordered-list-item",
|
|
202
|
-
depth: 2,
|
|
203
|
-
inlineStyleRanges: [{
|
|
204
|
-
offset: 0,
|
|
205
|
-
length: 3,
|
|
206
|
-
style: "BOLD"
|
|
207
|
-
}],
|
|
208
|
-
entityRanges: [],
|
|
209
|
-
data: {}
|
|
210
|
-
},
|
|
211
|
-
// Ordered List
|
|
212
|
-
{
|
|
213
|
-
key: "1iahs",
|
|
214
|
-
text: "List",
|
|
215
|
-
type: "ordered-list-item",
|
|
216
|
-
depth: 0,
|
|
217
|
-
inlineStyleRanges: [],
|
|
218
|
-
entityRanges: [],
|
|
219
|
-
data: {}
|
|
220
|
-
}, {
|
|
221
|
-
key: "aqjhb",
|
|
222
|
-
text: "123456",
|
|
223
|
-
type: "ordered-list-item",
|
|
224
|
-
depth: 1,
|
|
225
|
-
inlineStyleRanges: [{
|
|
226
|
-
offset: 3,
|
|
227
|
-
length: 3,
|
|
228
|
-
style: "SUP"
|
|
229
|
-
}],
|
|
230
|
-
entityRanges: [],
|
|
231
|
-
data: {}
|
|
232
|
-
}, {
|
|
233
|
-
key: "c4js6",
|
|
234
|
-
text: "234",
|
|
235
|
-
type: "ordered-list-item",
|
|
236
|
-
depth: 2,
|
|
237
|
-
inlineStyleRanges: [{
|
|
238
|
-
offset: 0,
|
|
239
|
-
length: 3,
|
|
240
|
-
style: "ITALIC"
|
|
241
|
-
}],
|
|
242
|
-
entityRanges: [],
|
|
243
|
-
data: {}
|
|
244
|
-
}, {
|
|
245
|
-
key: "3qjfc",
|
|
246
|
-
text: "345",
|
|
247
|
-
type: "ordered-list-item",
|
|
248
|
-
depth: 2,
|
|
249
|
-
inlineStyleRanges: [{
|
|
250
|
-
offset: 0,
|
|
251
|
-
length: 3,
|
|
252
|
-
style: "BOLD"
|
|
253
|
-
}],
|
|
254
|
-
entityRanges: [],
|
|
255
|
-
data: {}
|
|
256
|
-
},
|
|
257
|
-
// Custom Style
|
|
258
|
-
{
|
|
259
|
-
key: "7l333",
|
|
260
|
-
text: "A rte text with custom styling",
|
|
261
|
-
type: "unstyled",
|
|
262
|
-
depth: 0,
|
|
263
|
-
inlineStyleRanges: [{
|
|
264
|
-
offset: 0,
|
|
265
|
-
length: 30,
|
|
266
|
-
style: "HIGHLIGHT"
|
|
267
|
-
}],
|
|
268
|
-
entityRanges: [],
|
|
269
|
-
data: {}
|
|
270
|
-
},
|
|
271
|
-
// Custom Block Style
|
|
272
|
-
{
|
|
273
|
-
key: "7l334",
|
|
274
|
-
text: "A rte text with custom block styling",
|
|
275
|
-
type: "header-custom-green",
|
|
276
|
-
depth: 0,
|
|
277
|
-
inlineStyleRanges: [],
|
|
278
|
-
entityRanges: [],
|
|
279
|
-
data: {}
|
|
280
|
-
}];
|
|
281
|
-
var rawContent = {
|
|
282
|
-
entityMap: {},
|
|
283
|
-
blocks: blocks
|
|
284
|
-
};
|
|
285
|
-
var content = (0, _draftJs.convertFromRaw)(rawContent);
|
|
286
|
-
var editorState = _draftJs.EditorState.createWithContent(content);
|
|
287
|
-
var _stateToHtml = (0, _stateToHtml3.stateToHtml)({
|
|
288
|
-
editorState: editorState,
|
|
289
|
-
options: options
|
|
290
|
-
}),
|
|
291
|
-
html = _stateToHtml.html,
|
|
292
|
-
entities = _stateToHtml.entities;
|
|
293
|
-
var state = (0, _htmlToState.htmlToState)({
|
|
294
|
-
html: html,
|
|
295
|
-
entities: entities
|
|
296
|
-
});
|
|
297
|
-
var _stateToHtml2 = (0, _stateToHtml3.stateToHtml)({
|
|
298
|
-
editorState: state,
|
|
299
|
-
options: options
|
|
300
|
-
}),
|
|
301
|
-
html2 = _stateToHtml2.html,
|
|
302
|
-
linkDataList2 = _stateToHtml2.entities;
|
|
303
|
-
expect(html).toEqual(html2);
|
|
304
|
-
expect(entities).toEqual(linkDataList2);
|
|
305
|
-
});
|
|
306
|
-
});
|
|
@@ -1,498 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _draftJs = require("draft-js");
|
|
4
|
-
var _stateToHtml7 = require("./stateToHtml");
|
|
5
|
-
// Remove all newlines and spaces to compare the html strings
|
|
6
|
-
function trimHtml(html) {
|
|
7
|
-
return html.replace(/\s|\n/g, "");
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
// TODO Remove mock once we've updated the test setup to support ESM modules
|
|
11
|
-
jest.mock("../BlockElement", function () {
|
|
12
|
-
return {
|
|
13
|
-
BlockElement: function BlockElement() {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
describe("stateToHtml", function () {
|
|
19
|
-
var options = {
|
|
20
|
-
customInlineStyles: {
|
|
21
|
-
HIGHLIGHT: {
|
|
22
|
-
label: "Highlight!",
|
|
23
|
-
style: {
|
|
24
|
-
backgroundColor: "yellow"
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
blocktypeMap: {
|
|
29
|
-
"header-custom-green": {
|
|
30
|
-
label: "Header Custom Green",
|
|
31
|
-
renderConfig: {
|
|
32
|
-
element: "p"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
it("should convert the rte editor state with styling into html while keeping the format via tags - formats part 1", function () {
|
|
38
|
-
var blocks = [{
|
|
39
|
-
key: "52cmg",
|
|
40
|
-
text: "Normal Text",
|
|
41
|
-
type: "unstyled",
|
|
42
|
-
depth: 0,
|
|
43
|
-
inlineStyleRanges: [],
|
|
44
|
-
entityRanges: [],
|
|
45
|
-
data: {}
|
|
46
|
-
}, {
|
|
47
|
-
key: "8psic",
|
|
48
|
-
text: "Bold Text",
|
|
49
|
-
type: "unstyled",
|
|
50
|
-
depth: 0,
|
|
51
|
-
inlineStyleRanges: [{
|
|
52
|
-
offset: 0,
|
|
53
|
-
length: 9,
|
|
54
|
-
style: "BOLD"
|
|
55
|
-
}],
|
|
56
|
-
entityRanges: [],
|
|
57
|
-
data: {}
|
|
58
|
-
}, {
|
|
59
|
-
key: "4m6ou",
|
|
60
|
-
text: "Italic Text",
|
|
61
|
-
type: "unstyled",
|
|
62
|
-
depth: 0,
|
|
63
|
-
inlineStyleRanges: [{
|
|
64
|
-
offset: 0,
|
|
65
|
-
length: 11,
|
|
66
|
-
style: "ITALIC"
|
|
67
|
-
}],
|
|
68
|
-
entityRanges: [],
|
|
69
|
-
data: {}
|
|
70
|
-
}, {
|
|
71
|
-
key: "fask6",
|
|
72
|
-
text: "Bold Italic Text",
|
|
73
|
-
type: "unstyled",
|
|
74
|
-
depth: 0,
|
|
75
|
-
inlineStyleRanges: [{
|
|
76
|
-
offset: 0,
|
|
77
|
-
length: 16,
|
|
78
|
-
style: "ITALIC"
|
|
79
|
-
}, {
|
|
80
|
-
offset: 0,
|
|
81
|
-
length: 16,
|
|
82
|
-
style: "BOLD"
|
|
83
|
-
}],
|
|
84
|
-
entityRanges: [],
|
|
85
|
-
data: {}
|
|
86
|
-
}, {
|
|
87
|
-
key: "fm23u",
|
|
88
|
-
text: "Strikethrough Text",
|
|
89
|
-
type: "unstyled",
|
|
90
|
-
depth: 0,
|
|
91
|
-
inlineStyleRanges: [{
|
|
92
|
-
offset: 0,
|
|
93
|
-
length: 18,
|
|
94
|
-
style: "STRIKETHROUGH"
|
|
95
|
-
}],
|
|
96
|
-
entityRanges: [],
|
|
97
|
-
data: {}
|
|
98
|
-
}, {
|
|
99
|
-
key: "9q8m5",
|
|
100
|
-
text: "A Subscript Text",
|
|
101
|
-
type: "unstyled",
|
|
102
|
-
depth: 0,
|
|
103
|
-
inlineStyleRanges: [{
|
|
104
|
-
offset: 2,
|
|
105
|
-
length: 14,
|
|
106
|
-
style: "SUB"
|
|
107
|
-
}],
|
|
108
|
-
entityRanges: [],
|
|
109
|
-
data: {}
|
|
110
|
-
}, {
|
|
111
|
-
key: "t3nk",
|
|
112
|
-
text: "B Superscript Text",
|
|
113
|
-
type: "unstyled",
|
|
114
|
-
depth: 0,
|
|
115
|
-
inlineStyleRanges: [{
|
|
116
|
-
offset: 2,
|
|
117
|
-
length: 16,
|
|
118
|
-
style: "SUP"
|
|
119
|
-
}],
|
|
120
|
-
entityRanges: [],
|
|
121
|
-
data: {}
|
|
122
|
-
}, {
|
|
123
|
-
key: "e6k04",
|
|
124
|
-
text: "Headline 1",
|
|
125
|
-
type: "header-one",
|
|
126
|
-
depth: 0,
|
|
127
|
-
inlineStyleRanges: [],
|
|
128
|
-
entityRanges: [],
|
|
129
|
-
data: {}
|
|
130
|
-
}, {
|
|
131
|
-
key: "ect4f",
|
|
132
|
-
text: "Headline 2",
|
|
133
|
-
type: "header-two",
|
|
134
|
-
depth: 0,
|
|
135
|
-
inlineStyleRanges: [],
|
|
136
|
-
entityRanges: [],
|
|
137
|
-
data: {}
|
|
138
|
-
}, {
|
|
139
|
-
key: "e038j",
|
|
140
|
-
text: "Headline 3",
|
|
141
|
-
type: "header-three",
|
|
142
|
-
depth: 0,
|
|
143
|
-
inlineStyleRanges: [],
|
|
144
|
-
entityRanges: [],
|
|
145
|
-
data: {}
|
|
146
|
-
}, {
|
|
147
|
-
key: "4bha8",
|
|
148
|
-
text: "Headline 4",
|
|
149
|
-
type: "header-four",
|
|
150
|
-
depth: 0,
|
|
151
|
-
inlineStyleRanges: [],
|
|
152
|
-
entityRanges: [],
|
|
153
|
-
data: {}
|
|
154
|
-
}, {
|
|
155
|
-
key: "aje6k",
|
|
156
|
-
text: "Headline 5",
|
|
157
|
-
type: "header-five",
|
|
158
|
-
depth: 0,
|
|
159
|
-
inlineStyleRanges: [],
|
|
160
|
-
entityRanges: [],
|
|
161
|
-
data: {}
|
|
162
|
-
}, {
|
|
163
|
-
key: "7u6on",
|
|
164
|
-
text: "Headline 6",
|
|
165
|
-
type: "header-six",
|
|
166
|
-
depth: 0,
|
|
167
|
-
inlineStyleRanges: [],
|
|
168
|
-
entityRanges: [],
|
|
169
|
-
data: {}
|
|
170
|
-
}];
|
|
171
|
-
var rawContent = {
|
|
172
|
-
entityMap: {},
|
|
173
|
-
blocks: blocks
|
|
174
|
-
};
|
|
175
|
-
var content = (0, _draftJs.convertFromRaw)(rawContent);
|
|
176
|
-
var editorState = _draftJs.EditorState.createWithContent(content);
|
|
177
|
-
var _stateToHtml = (0, _stateToHtml7.stateToHtml)({
|
|
178
|
-
editorState: editorState,
|
|
179
|
-
options: options
|
|
180
|
-
}),
|
|
181
|
-
html = _stateToHtml.html;
|
|
182
|
-
var expectedHtml = "<p>Normal Text</p><p><strong>Bold Text</strong></p><p><em>Italic Text</em></p><p><em><strong>Bold Italic Text</strong></em></p><p><del>Strikethrough Text</del></p><p>A <sub>Subscript Text</sub></p><p>B <sup>Superscript Text</sup></p><h1>Headline 1</h1><h2>Headline 2</h2><h3>Headline 3</h3><h4>Headline 4</h4><h5>Headline 5</h5><h6>Headline 6</h6>";
|
|
183
|
-
expect(trimHtml(html)).toEqual(trimHtml(expectedHtml));
|
|
184
|
-
});
|
|
185
|
-
it("should convert the rte editor state with formating into html while keeping the format via tags - formats part 2 (unordered list)", function () {
|
|
186
|
-
var blocks = [{
|
|
187
|
-
key: "a9t3",
|
|
188
|
-
text: "Unordered List",
|
|
189
|
-
type: "unordered-list-item",
|
|
190
|
-
depth: 0,
|
|
191
|
-
inlineStyleRanges: [],
|
|
192
|
-
entityRanges: [],
|
|
193
|
-
data: {}
|
|
194
|
-
}, {
|
|
195
|
-
key: "f4o2c",
|
|
196
|
-
text: "123456",
|
|
197
|
-
type: "unordered-list-item",
|
|
198
|
-
depth: 1,
|
|
199
|
-
inlineStyleRanges: [{
|
|
200
|
-
offset: 3,
|
|
201
|
-
length: 3,
|
|
202
|
-
style: "SUB"
|
|
203
|
-
}],
|
|
204
|
-
entityRanges: [],
|
|
205
|
-
data: {}
|
|
206
|
-
}, {
|
|
207
|
-
key: "7v61p",
|
|
208
|
-
text: "234",
|
|
209
|
-
type: "unordered-list-item",
|
|
210
|
-
depth: 2,
|
|
211
|
-
inlineStyleRanges: [{
|
|
212
|
-
offset: 0,
|
|
213
|
-
length: 3,
|
|
214
|
-
style: "ITALIC"
|
|
215
|
-
}],
|
|
216
|
-
entityRanges: [],
|
|
217
|
-
data: {}
|
|
218
|
-
}, {
|
|
219
|
-
key: "1duir",
|
|
220
|
-
text: "345",
|
|
221
|
-
type: "unordered-list-item",
|
|
222
|
-
depth: 2,
|
|
223
|
-
inlineStyleRanges: [{
|
|
224
|
-
offset: 0,
|
|
225
|
-
length: 3,
|
|
226
|
-
style: "BOLD"
|
|
227
|
-
}],
|
|
228
|
-
entityRanges: [],
|
|
229
|
-
data: {}
|
|
230
|
-
}];
|
|
231
|
-
var rawContent = {
|
|
232
|
-
entityMap: {},
|
|
233
|
-
blocks: blocks
|
|
234
|
-
};
|
|
235
|
-
var content = (0, _draftJs.convertFromRaw)(rawContent);
|
|
236
|
-
var editorState = _draftJs.EditorState.createWithContent(content);
|
|
237
|
-
var _stateToHtml2 = (0, _stateToHtml7.stateToHtml)({
|
|
238
|
-
editorState: editorState,
|
|
239
|
-
options: options
|
|
240
|
-
}),
|
|
241
|
-
html = _stateToHtml2.html;
|
|
242
|
-
var expectedHtml = "<ul><li>Unordered List<ul><li>123<sub>456</sub><ul><li><em>234</em></li><li><strong>345</strong></li></ul></li></ul></li></ul>";
|
|
243
|
-
expect(trimHtml(html)).toEqual(trimHtml(expectedHtml));
|
|
244
|
-
});
|
|
245
|
-
it("should convert the rte editor state with formating into html while keeping the format via tags - formats part 3 (ordered list)", function () {
|
|
246
|
-
var blocks = [{
|
|
247
|
-
key: "1iahs",
|
|
248
|
-
text: "List",
|
|
249
|
-
type: "ordered-list-item",
|
|
250
|
-
depth: 0,
|
|
251
|
-
inlineStyleRanges: [],
|
|
252
|
-
entityRanges: [],
|
|
253
|
-
data: {}
|
|
254
|
-
}, {
|
|
255
|
-
key: "aqjhb",
|
|
256
|
-
text: "123456",
|
|
257
|
-
type: "ordered-list-item",
|
|
258
|
-
depth: 1,
|
|
259
|
-
inlineStyleRanges: [{
|
|
260
|
-
offset: 3,
|
|
261
|
-
length: 3,
|
|
262
|
-
style: "SUP"
|
|
263
|
-
}],
|
|
264
|
-
entityRanges: [],
|
|
265
|
-
data: {}
|
|
266
|
-
}, {
|
|
267
|
-
key: "c4js6",
|
|
268
|
-
text: "234",
|
|
269
|
-
type: "ordered-list-item",
|
|
270
|
-
depth: 2,
|
|
271
|
-
inlineStyleRanges: [{
|
|
272
|
-
offset: 0,
|
|
273
|
-
length: 3,
|
|
274
|
-
style: "ITALIC"
|
|
275
|
-
}],
|
|
276
|
-
entityRanges: [],
|
|
277
|
-
data: {}
|
|
278
|
-
}, {
|
|
279
|
-
key: "3qjfc",
|
|
280
|
-
text: "345",
|
|
281
|
-
type: "ordered-list-item",
|
|
282
|
-
depth: 2,
|
|
283
|
-
inlineStyleRanges: [{
|
|
284
|
-
offset: 0,
|
|
285
|
-
length: 3,
|
|
286
|
-
style: "BOLD"
|
|
287
|
-
}],
|
|
288
|
-
entityRanges: [],
|
|
289
|
-
data: {}
|
|
290
|
-
}];
|
|
291
|
-
var rawContent = {
|
|
292
|
-
entityMap: {},
|
|
293
|
-
blocks: blocks
|
|
294
|
-
};
|
|
295
|
-
var content = (0, _draftJs.convertFromRaw)(rawContent);
|
|
296
|
-
var editorState = _draftJs.EditorState.createWithContent(content);
|
|
297
|
-
var _stateToHtml3 = (0, _stateToHtml7.stateToHtml)({
|
|
298
|
-
editorState: editorState,
|
|
299
|
-
options: options
|
|
300
|
-
}),
|
|
301
|
-
html = _stateToHtml3.html;
|
|
302
|
-
var expectedHtml = "<ol><li>List<ol><li>123<sup>456</sup><ol><li><em>234</em></li><li><strong>345</strong></li></ol></li></ol></li></ol>";
|
|
303
|
-
expect(trimHtml(html)).toEqual(trimHtml(expectedHtml));
|
|
304
|
-
});
|
|
305
|
-
it("should convert the rte editor state with formating into html while keeping the format via tags - formats part 4 (links)", function () {
|
|
306
|
-
var entityMap = {
|
|
307
|
-
"0": {
|
|
308
|
-
type: "LINK",
|
|
309
|
-
mutability: "MUTABLE",
|
|
310
|
-
data: {
|
|
311
|
-
activeType: "external",
|
|
312
|
-
attachedBlocks: [{
|
|
313
|
-
type: "external",
|
|
314
|
-
props: {
|
|
315
|
-
targetUrl: "https://www.vivid-planet.com/",
|
|
316
|
-
openInNewWindow: false
|
|
317
|
-
}
|
|
318
|
-
}]
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
"1": {
|
|
322
|
-
type: "LINK",
|
|
323
|
-
mutability: "MUTABLE",
|
|
324
|
-
data: {
|
|
325
|
-
activeType: "internal",
|
|
326
|
-
attachedBlocks: [{
|
|
327
|
-
type: "internal",
|
|
328
|
-
props: {
|
|
329
|
-
targetPage: {
|
|
330
|
-
id: "5aab378c-7a8f-4442-aa33-4aff950d0233",
|
|
331
|
-
name: "RTE Save",
|
|
332
|
-
path: "/rte-save",
|
|
333
|
-
documentType: "Page"
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}]
|
|
337
|
-
}
|
|
338
|
-
},
|
|
339
|
-
"2": {
|
|
340
|
-
type: "LINK",
|
|
341
|
-
mutability: "MUTABLE",
|
|
342
|
-
data: {
|
|
343
|
-
activeType: "news",
|
|
344
|
-
attachedBlocks: [{
|
|
345
|
-
type: "news",
|
|
346
|
-
props: {
|
|
347
|
-
id: "3d90dd58-f880-4fd8-a4b8-9ff690655a5b"
|
|
348
|
-
}
|
|
349
|
-
}]
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
var blocks = [{
|
|
354
|
-
key: "b40ve",
|
|
355
|
-
text: "External Link",
|
|
356
|
-
type: "unstyled",
|
|
357
|
-
depth: 0,
|
|
358
|
-
inlineStyleRanges: [],
|
|
359
|
-
entityRanges: [{
|
|
360
|
-
offset: 0,
|
|
361
|
-
length: 13,
|
|
362
|
-
key: 0
|
|
363
|
-
}],
|
|
364
|
-
data: {}
|
|
365
|
-
}, {
|
|
366
|
-
key: "67hve",
|
|
367
|
-
text: "Internal Link",
|
|
368
|
-
type: "unstyled",
|
|
369
|
-
depth: 0,
|
|
370
|
-
inlineStyleRanges: [],
|
|
371
|
-
entityRanges: [{
|
|
372
|
-
offset: 0,
|
|
373
|
-
length: 13,
|
|
374
|
-
key: 1
|
|
375
|
-
}],
|
|
376
|
-
data: {}
|
|
377
|
-
}, {
|
|
378
|
-
key: "8mn26",
|
|
379
|
-
text: "Internal News Link",
|
|
380
|
-
type: "unstyled",
|
|
381
|
-
depth: 0,
|
|
382
|
-
inlineStyleRanges: [],
|
|
383
|
-
entityRanges: [{
|
|
384
|
-
offset: 0,
|
|
385
|
-
length: 18,
|
|
386
|
-
key: 2
|
|
387
|
-
}],
|
|
388
|
-
data: {}
|
|
389
|
-
}];
|
|
390
|
-
var rawContent = {
|
|
391
|
-
entityMap: entityMap,
|
|
392
|
-
blocks: blocks
|
|
393
|
-
};
|
|
394
|
-
var content = (0, _draftJs.convertFromRaw)(rawContent);
|
|
395
|
-
var editorState = _draftJs.EditorState.createWithContent(content);
|
|
396
|
-
var _stateToHtml4 = (0, _stateToHtml7.stateToHtml)({
|
|
397
|
-
editorState: editorState,
|
|
398
|
-
options: options
|
|
399
|
-
}),
|
|
400
|
-
html = _stateToHtml4.html,
|
|
401
|
-
entities = _stateToHtml4.entities;
|
|
402
|
-
var expectedHtml = "<p><a id=\"0\">External Link</a></p><p><a id=\"1\">Internal Link</a></p><p><a id=\"2\">Internal News Link</a></p>";
|
|
403
|
-
expect(trimHtml(html)).toEqual(trimHtml(expectedHtml));
|
|
404
|
-
var expectedLinkDataList = [{
|
|
405
|
-
id: "0",
|
|
406
|
-
data: {
|
|
407
|
-
activeType: "external",
|
|
408
|
-
attachedBlocks: [{
|
|
409
|
-
type: "external",
|
|
410
|
-
props: {
|
|
411
|
-
targetUrl: "https://www.vivid-planet.com/",
|
|
412
|
-
openInNewWindow: false
|
|
413
|
-
}
|
|
414
|
-
}]
|
|
415
|
-
}
|
|
416
|
-
}, {
|
|
417
|
-
id: "1",
|
|
418
|
-
data: {
|
|
419
|
-
activeType: "internal",
|
|
420
|
-
attachedBlocks: [{
|
|
421
|
-
type: "internal",
|
|
422
|
-
props: {
|
|
423
|
-
targetPage: {
|
|
424
|
-
id: "5aab378c-7a8f-4442-aa33-4aff950d0233",
|
|
425
|
-
name: "RTE Save",
|
|
426
|
-
path: "/rte-save",
|
|
427
|
-
documentType: "Page"
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}]
|
|
431
|
-
}
|
|
432
|
-
}, {
|
|
433
|
-
id: "2",
|
|
434
|
-
data: {
|
|
435
|
-
activeType: "news",
|
|
436
|
-
attachedBlocks: [{
|
|
437
|
-
type: "news",
|
|
438
|
-
props: {
|
|
439
|
-
id: "3d90dd58-f880-4fd8-a4b8-9ff690655a5b"
|
|
440
|
-
}
|
|
441
|
-
}]
|
|
442
|
-
}
|
|
443
|
-
}];
|
|
444
|
-
expect(entities).toEqual(expectedLinkDataList);
|
|
445
|
-
});
|
|
446
|
-
it("should convert the rte editor state with formating into html while keeping the format via tags - formats part 5 (custom styles)", function () {
|
|
447
|
-
var blocks = [{
|
|
448
|
-
key: "7l333",
|
|
449
|
-
text: "A rte text with custom styling",
|
|
450
|
-
type: "unstyled",
|
|
451
|
-
depth: 0,
|
|
452
|
-
inlineStyleRanges: [{
|
|
453
|
-
offset: 0,
|
|
454
|
-
length: 30,
|
|
455
|
-
style: "HIGHLIGHT"
|
|
456
|
-
}],
|
|
457
|
-
entityRanges: [],
|
|
458
|
-
data: {}
|
|
459
|
-
}];
|
|
460
|
-
var rawContent = {
|
|
461
|
-
entityMap: {},
|
|
462
|
-
blocks: blocks
|
|
463
|
-
};
|
|
464
|
-
var content = (0, _draftJs.convertFromRaw)(rawContent);
|
|
465
|
-
var editorState = _draftJs.EditorState.createWithContent(content);
|
|
466
|
-
var _stateToHtml5 = (0, _stateToHtml7.stateToHtml)({
|
|
467
|
-
editorState: editorState,
|
|
468
|
-
options: options
|
|
469
|
-
}),
|
|
470
|
-
html = _stateToHtml5.html;
|
|
471
|
-
var expectedHtml = "<p><span class=\"HIGHLIGHT\">A rte text with custom styling</span></p>";
|
|
472
|
-
expect(trimHtml(html)).toEqual(trimHtml(expectedHtml));
|
|
473
|
-
});
|
|
474
|
-
it("should convert the rte editor state with formating into html while keeping the format via tags - formats part 6 (custom block styles)", function () {
|
|
475
|
-
var blocks = [{
|
|
476
|
-
key: "7l334",
|
|
477
|
-
text: "A rte text with custom block styling",
|
|
478
|
-
type: "header-custom-green",
|
|
479
|
-
depth: 0,
|
|
480
|
-
inlineStyleRanges: [],
|
|
481
|
-
entityRanges: [],
|
|
482
|
-
data: {}
|
|
483
|
-
}];
|
|
484
|
-
var rawContent = {
|
|
485
|
-
entityMap: {},
|
|
486
|
-
blocks: blocks
|
|
487
|
-
};
|
|
488
|
-
var content = (0, _draftJs.convertFromRaw)(rawContent);
|
|
489
|
-
var editorState = _draftJs.EditorState.createWithContent(content);
|
|
490
|
-
var _stateToHtml6 = (0, _stateToHtml7.stateToHtml)({
|
|
491
|
-
editorState: editorState,
|
|
492
|
-
options: options
|
|
493
|
-
}),
|
|
494
|
-
html = _stateToHtml6.html;
|
|
495
|
-
var expectedHtml = "<p class=\"header-custom-green\">A rte text with custom block styling</p>";
|
|
496
|
-
expect(trimHtml(html)).toEqual(trimHtml(expectedHtml));
|
|
497
|
-
});
|
|
498
|
-
});
|