@griddo/ax 1.75.168 → 1.75.169

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/ax",
3
3
  "description": "Griddo Author Experience",
4
- "version": "1.75.168",
4
+ "version": "1.75.169",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -87,14 +87,15 @@
87
87
  "date-fns": "^2.21.3",
88
88
  "dotenv": "6.2.0",
89
89
  "dotenv-expand": "5.1.0",
90
- "draft-convert": "^2.1.13",
91
90
  "draft-js": "^0.11.7",
92
91
  "draft-js-import-html": "^1.4.1",
92
+ "draftjs-to-html": "^0.9.1",
93
93
  "enhanced-resolve": "^5.8.2",
94
94
  "env-cmd": "^10.1.0",
95
95
  "file-loader": "^6.2.0",
96
96
  "find-up": "^5.0.0",
97
97
  "fs-extra": "7.0.1",
98
+ "html-to-draftjs": "^1.5.0",
98
99
  "html-to-image": "^1.9.0",
99
100
  "html-webpack-plugin": "4.5.0",
100
101
  "identity-obj-proxy": "3.0.0",
@@ -233,5 +234,5 @@
233
234
  "publishConfig": {
234
235
  "access": "public"
235
236
  },
236
- "gitHead": "77bd4bb799b614574187a9772e4fa1f84dec1d65"
237
+ "gitHead": "db5f28a576b8bae9193121620f538db55f6e2278"
237
238
  }
@@ -1,10 +1,11 @@
1
1
  import React, { useState, useEffect, memo, useRef } from "react";
2
2
  import { Editor } from "react-draft-wysiwyg";
3
- import { EditorState, convertFromRaw, convertToRaw } from "draft-js";
3
+ import { EditorState, convertFromRaw, convertToRaw, ContentState } from "draft-js";
4
4
  import { markdownToDraft, draftToMarkdown } from "markdown-draft-js";
5
- import { convertFromHTML, convertToHTML } from "draft-convert";
5
+ import draftToHtml from "draftjs-to-html";
6
+ import htmlToDraft from "html-to-draftjs";
6
7
  import { stateFromHTML } from "draft-js-import-html";
7
- import { formatIframe } from "./utils";
8
+ import { formatIframe, customEntityTransformFunc } from "./utils";
8
9
  import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
9
10
 
10
11
  import * as S from "./style";
@@ -14,15 +15,17 @@ const RichText = (props: IRichTextProps): JSX.Element => {
14
15
 
15
16
  const valueUnformatted = value ? formatIframe(value, true) : "";
16
17
 
17
- const rawData = html ? convertFromHTML(valueUnformatted || "") : markdownToDraft(value);
18
- const contentState = html ? rawData : convertFromRaw(rawData);
18
+ const rawData = html ? htmlToDraft(valueUnformatted) : markdownToDraft(value);
19
+ const { contentBlocks, entityMap } = rawData;
20
+ const contentState = html ? ContentState.createFromBlockArray(contentBlocks, entityMap) : convertFromRaw(rawData);
19
21
 
20
22
  const [editorState, setEditorState] = useState(() => EditorState.createWithContent(contentState));
21
23
  const timeOutRef = useRef<ReturnType<typeof setTimeout>>();
22
24
 
23
25
  useEffect(() => {
24
- const rawData = html ? convertFromHTML(valueUnformatted || "") : markdownToDraft(value);
25
- const contentState = html ? rawData : convertFromRaw(rawData);
26
+ const rawData = html ? htmlToDraft(valueUnformatted) : markdownToDraft(value);
27
+ const { contentBlocks, entityMap } = rawData;
28
+ const contentState = html ? ContentState.createFromBlockArray(contentBlocks, entityMap) : convertFromRaw(rawData);
26
29
  setEditorState(EditorState.createWithContent(contentState));
27
30
  // eslint-disable-next-line react-hooks/exhaustive-deps
28
31
  }, [editorID]);
@@ -47,7 +50,11 @@ const RichText = (props: IRichTextProps): JSX.Element => {
47
50
  const plainContent = content.getPlainText();
48
51
  const rawObject = convertToRaw(content);
49
52
  const markdownString =
50
- plainContent === "" ? plainContent : html ? formatIframe(convertToHTML(content)) : draftToMarkdown(rawObject);
53
+ plainContent === ""
54
+ ? plainContent
55
+ : html
56
+ ? formatIframe(draftToHtml(rawObject, undefined, undefined, customEntityTransformFunc))
57
+ : draftToMarkdown(rawObject);
51
58
 
52
59
  onChange(markdownString);
53
60
  error && handleValidation && handleValidation(plainContent);
@@ -57,7 +64,9 @@ const RichText = (props: IRichTextProps): JSX.Element => {
57
64
  const content = stateFromHTML(pastedValue);
58
65
  setEditorState(() => EditorState.createWithContent(content));
59
66
  const rawObject = convertToRaw(content);
60
- const markdownString = html ? formatIframe(convertToHTML(content)) : draftToMarkdown(rawObject);
67
+ const markdownString = html
68
+ ? formatIframe(draftToHtml(rawObject, undefined, undefined, customEntityTransformFunc))
69
+ : draftToMarkdown(rawObject);
61
70
 
62
71
  onChange(markdownString);
63
72
  return false;
@@ -1,3 +1,17 @@
1
+ import { DraftEntityMutability, DraftEntityType } from "draft-js";
2
+
3
+ type DraftEntity = {
4
+ type: DraftEntityType;
5
+ mutability: DraftEntityMutability;
6
+ data: any;
7
+ };
8
+ const customEntityTransformFunc = (entity: DraftEntity, text: string): string | undefined => {
9
+ if (entity.type === "LINK" && entity.data.href) {
10
+ return entity.data.url;
11
+ }
12
+ return `<a href="${entity.data.url}" target="${entity.data.targetOption}">${text}</a>`;
13
+ };
14
+
1
15
  const formatIframe = (iframeToFormat: string, firstConversion?: boolean) => {
2
16
  let iframeFormatted = iframeToFormat;
3
17
  if (firstConversion) {
@@ -16,4 +30,4 @@ const formatIframe = (iframeToFormat: string, firstConversion?: boolean) => {
16
30
  return iframeFormatted;
17
31
  };
18
32
 
19
- export { formatIframe };
33
+ export { formatIframe, customEntityTransformFunc };
package/src/global.d.ts CHANGED
@@ -7,4 +7,5 @@ declare module "is-wsl";
7
7
  declare module "react-draft-wysiwyg";
8
8
  declare module "history";
9
9
  declare module "@griddo/core";
10
- declare module "draft-convert";
10
+ declare module "draftjs-to-html";
11
+ declare module "html-to-draftjs";