@griddo/ax 1.75.161 → 1.75.163

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.161",
4
+ "version": "1.75.163",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -86,15 +86,14 @@
86
86
  "date-fns": "^2.21.3",
87
87
  "dotenv": "6.2.0",
88
88
  "dotenv-expand": "5.1.0",
89
+ "draft-convert": "^2.1.13",
89
90
  "draft-js": "^0.11.7",
90
91
  "draft-js-import-html": "^1.4.1",
91
- "draftjs-to-html": "^0.9.1",
92
92
  "enhanced-resolve": "^5.8.2",
93
93
  "env-cmd": "^10.1.0",
94
94
  "file-loader": "^6.2.0",
95
95
  "find-up": "^5.0.0",
96
96
  "fs-extra": "7.0.1",
97
- "html-to-draftjs": "^1.5.0",
98
97
  "html-to-image": "^1.9.0",
99
98
  "html-webpack-plugin": "4.5.0",
100
99
  "identity-obj-proxy": "3.0.0",
@@ -233,5 +232,5 @@
233
232
  "publishConfig": {
234
233
  "access": "public"
235
234
  },
236
- "gitHead": "49c079d51e314a57983e5e35e3c634af78283b1f"
235
+ "gitHead": "780f5a83b1e367801bde8124897faad20c207586"
237
236
  }
@@ -1,10 +1,10 @@
1
1
  import React, { useState, useEffect, memo, useRef } from "react";
2
2
  import { Editor } from "react-draft-wysiwyg";
3
- import { EditorState, convertFromRaw, convertToRaw, ContentState } from "draft-js";
3
+ import { EditorState, convertFromRaw, convertToRaw } from "draft-js";
4
4
  import { markdownToDraft, draftToMarkdown } from "markdown-draft-js";
5
- import draftToHtml from "draftjs-to-html";
6
- import htmlToDraft from "html-to-draftjs";
5
+ import { convertFromHTML, convertToHTML } from "draft-convert";
7
6
  import { stateFromHTML } from "draft-js-import-html";
7
+ import { formatIframe } from "./utils";
8
8
  import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
9
9
 
10
10
  import * as S from "./style";
@@ -12,17 +12,17 @@ import * as S from "./style";
12
12
  const RichText = (props: IRichTextProps): JSX.Element => {
13
13
  const { value, error, placeholder, onChange, disabled, editorID, handleValidation, html = false, delayed } = props;
14
14
 
15
- const rawData = html ? htmlToDraft(value || "") : markdownToDraft(value);
16
- const { contentBlocks, entityMap } = rawData;
17
- const contentState = html ? ContentState.createFromBlockArray(contentBlocks, entityMap) : convertFromRaw(rawData);
15
+ const valueUnformatted = formatIframe(value, true);
16
+
17
+ const rawData = html ? convertFromHTML(valueUnformatted || "") : markdownToDraft(value);
18
+ const contentState = html ? rawData : convertFromRaw(rawData);
18
19
 
19
20
  const [editorState, setEditorState] = useState(() => EditorState.createWithContent(contentState));
20
21
  const timeOutRef = useRef<ReturnType<typeof setTimeout>>();
21
22
 
22
23
  useEffect(() => {
23
- const rawData = html ? htmlToDraft(value || "") : markdownToDraft(value);
24
- const { contentBlocks, entityMap } = rawData;
25
- const contentState = html ? ContentState.createFromBlockArray(contentBlocks, entityMap) : convertFromRaw(rawData);
24
+ const rawData = html ? convertFromHTML(valueUnformatted || "") : markdownToDraft(value);
25
+ const contentState = html ? rawData : convertFromRaw(rawData);
26
26
  setEditorState(EditorState.createWithContent(contentState));
27
27
  // eslint-disable-next-line react-hooks/exhaustive-deps
28
28
  }, [editorID]);
@@ -47,7 +47,8 @@ const RichText = (props: IRichTextProps): JSX.Element => {
47
47
  const plainContent = content.getPlainText();
48
48
  const rawObject = convertToRaw(content);
49
49
  const markdownString =
50
- plainContent === "" ? plainContent : html ? draftToHtml(rawObject) : draftToMarkdown(rawObject);
50
+ plainContent === "" ? plainContent : html ? formatIframe(convertToHTML(content)) : draftToMarkdown(rawObject);
51
+
51
52
  onChange(markdownString);
52
53
  error && handleValidation && handleValidation(plainContent);
53
54
  };
@@ -56,7 +57,8 @@ const RichText = (props: IRichTextProps): JSX.Element => {
56
57
  const content = stateFromHTML(pastedValue);
57
58
  setEditorState(() => EditorState.createWithContent(content));
58
59
  const rawObject = convertToRaw(content);
59
- const markdownString = html ? draftToHtml(rawObject) : draftToMarkdown(rawObject);
60
+ const markdownString = html ? formatIframe(convertToHTML(content)) : draftToMarkdown(rawObject);
61
+
60
62
  onChange(markdownString);
61
63
  return false;
62
64
  };
@@ -0,0 +1,19 @@
1
+ const formatIframe = (iframeToFormat: string, firstConversion?: boolean) => {
2
+ let iframeFormatted = iframeToFormat;
3
+ if (firstConversion) {
4
+ if (iframeFormatted.match(/<iframe[^>]*?(?:\/>|>[^<]*?<\/iframe>)/g)) {
5
+ iframeFormatted = iframeToFormat.replaceAll("<iframe", "&lt;iframe");
6
+ iframeFormatted = iframeFormatted.replaceAll("></iframe>", "&gt;&lt;/iframe&gt;");
7
+ }
8
+ } else {
9
+ if (iframeToFormat.match(/(?:&lt;iframe[^>]*)/g)) {
10
+ iframeFormatted = iframeToFormat.replaceAll("&lt;iframe", "<iframe");
11
+ iframeFormatted = iframeFormatted.replaceAll("&gt;&lt;/iframe&gt;", "></iframe>");
12
+ iframeFormatted = iframeFormatted.replace(/&quot;/g, '"');
13
+ iframeFormatted = iframeFormatted.replace(/&amp;/g, "&");
14
+ }
15
+ }
16
+ return iframeFormatted;
17
+ };
18
+
19
+ export { formatIframe };
package/src/global.d.ts CHANGED
@@ -7,5 +7,4 @@ 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 "draftjs-to-html";
11
- declare module "html-to-draftjs";
10
+ declare module "draft-convert";