@griddo/ax 1.75.210 → 1.75.212

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.210",
4
+ "version": "1.75.212",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -235,5 +235,5 @@
235
235
  "publishConfig": {
236
236
  "access": "public"
237
237
  },
238
- "gitHead": "2b9df0e7e16083025b24814e8952c45078a732a8"
238
+ "gitHead": "ea263310a45b718e25b02b662d57d6dd3c341f02"
239
239
  }
@@ -5,7 +5,7 @@ import { markdownToDraft, draftToMarkdown } from "markdown-draft-js";
5
5
  import draftToHtml from "draftjs-to-html";
6
6
  import htmlToDraft from "html-to-draftjs";
7
7
  import { stateFromHTML } from "draft-js-import-html";
8
- import { formatIframe, customEntityTransformFunc } from "./utils";
8
+ import { formatIframe } from "./utils";
9
9
  import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";
10
10
 
11
11
  import * as S from "./style";
@@ -50,11 +50,7 @@ const RichText = (props: IRichTextProps): JSX.Element => {
50
50
  const plainContent = content.getPlainText();
51
51
  const rawObject = convertToRaw(content);
52
52
  const markdownString =
53
- plainContent === ""
54
- ? plainContent
55
- : html
56
- ? formatIframe(draftToHtml(rawObject, undefined, undefined, customEntityTransformFunc))
57
- : draftToMarkdown(rawObject);
53
+ plainContent === "" ? plainContent : html ? formatIframe(draftToHtml(rawObject)) : draftToMarkdown(rawObject);
58
54
 
59
55
  onChange(markdownString);
60
56
  error && handleValidation && handleValidation(plainContent);
@@ -64,9 +60,7 @@ const RichText = (props: IRichTextProps): JSX.Element => {
64
60
  const content = stateFromHTML(pastedValue);
65
61
  setEditorState(() => EditorState.createWithContent(content));
66
62
  const rawObject = convertToRaw(content);
67
- const markdownString = html
68
- ? formatIframe(draftToHtml(rawObject, undefined, undefined, customEntityTransformFunc))
69
- : draftToMarkdown(rawObject);
63
+ const markdownString = html ? formatIframe(draftToHtml(rawObject)) : draftToMarkdown(rawObject);
70
64
 
71
65
  onChange(markdownString);
72
66
  return false;
@@ -1,19 +1,6 @@
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
-
15
1
  const formatIframe = (iframeToFormat: string, firstConversion?: boolean) => {
16
- let iframeFormatted = iframeToFormat;
2
+ let iframeFormatted: string = iframeToFormat;
3
+
17
4
  if (firstConversion) {
18
5
  if (iframeFormatted.match(/<iframe[^>]*?(?:\/>|>[^<]*?<\/iframe>)/g)) {
19
6
  iframeFormatted = iframeToFormat.replaceAll("<iframe", "&lt;iframe");
@@ -25,9 +12,19 @@ const formatIframe = (iframeToFormat: string, firstConversion?: boolean) => {
25
12
  iframeFormatted = iframeFormatted.replaceAll("&gt;&lt;/iframe&gt;", "></iframe>");
26
13
  iframeFormatted = iframeFormatted.replace(/&quot;/g, '"');
27
14
  iframeFormatted = iframeFormatted.replace(/&amp;/g, "&");
15
+
16
+ const urlFromIframe: string =
17
+ iframeFormatted.split("src=")[1].split(/"/g)[1] === "<a href="
18
+ ? iframeFormatted.split("src=")[1].split(/"/g)[2]
19
+ : iframeFormatted.split("src=")[1].split(/"/g)[1];
20
+
21
+ iframeFormatted = iframeFormatted.replace(
22
+ /(src="|src='|src=”<a.*?>).*?(<\/a>'|<\/a>"|<\/a>”)/,
23
+ `src="${urlFromIframe}"`
24
+ );
28
25
  }
29
26
  }
30
27
  return iframeFormatted;
31
28
  };
32
29
 
33
- export { formatIframe, customEntityTransformFunc };
30
+ export { formatIframe };