@kontakto/email-template-editor 1.3.0 → 1.3.2

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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import insane from 'insane';
1
+ import DOMPurify from 'dompurify';
2
2
  import { marked, Renderer } from 'marked';
3
- import React81, { createContext, forwardRef, useRef, useEffect, useImperativeHandle, useContext, useState, useCallback, useMemo, Fragment } from 'react';
3
+ import React81, { createContext, forwardRef, useRef, useEffect, useImperativeHandle, useMemo, useContext, useState, useCallback, Fragment } from 'react';
4
4
  import { z } from 'zod';
5
5
  import { renderToStaticMarkup as renderToStaticMarkup$1 } from 'react-dom/server';
6
6
  import { createTheme, alpha, lighten, darken } from '@mui/material/styles';
@@ -107,22 +107,23 @@ var ALLOWED_TAGS = [
107
107
  "u",
108
108
  "ul"
109
109
  ];
110
- var GENERIC_ALLOWED_ATTRIBUTES = ["style", "title"];
110
+ var ALLOWED_ATTR = [
111
+ "style",
112
+ "title",
113
+ "src",
114
+ "srcset",
115
+ "alt",
116
+ "width",
117
+ "height",
118
+ "href",
119
+ "target",
120
+ "align",
121
+ "start"
122
+ ];
111
123
  function sanitizer(html2) {
112
- return insane(html2, {
113
- allowedTags: ALLOWED_TAGS,
114
- allowedAttributes: __spreadProps(__spreadValues({}, ALLOWED_TAGS.reduce((res, tag) => {
115
- res[tag] = [...GENERIC_ALLOWED_ATTRIBUTES];
116
- return res;
117
- }, {})), {
118
- img: ["src", "srcset", "alt", "width", "height", ...GENERIC_ALLOWED_ATTRIBUTES],
119
- table: ["width", ...GENERIC_ALLOWED_ATTRIBUTES],
120
- td: ["align", "width", ...GENERIC_ALLOWED_ATTRIBUTES],
121
- th: ["align", "width", ...GENERIC_ALLOWED_ATTRIBUTES],
122
- a: ["href", "target", ...GENERIC_ALLOWED_ATTRIBUTES],
123
- ol: ["start", ...GENERIC_ALLOWED_ATTRIBUTES],
124
- ul: ["start", ...GENERIC_ALLOWED_ATTRIBUTES]
125
- })
124
+ return DOMPurify.sanitize(html2, {
125
+ ALLOWED_TAGS,
126
+ ALLOWED_ATTR
126
127
  });
127
128
  }
128
129
  var CustomRenderer = class extends Renderer {
@@ -4958,14 +4959,15 @@ var EmailEditor = forwardRef((props, ref) => {
4958
4959
  saveAs,
4959
4960
  theme
4960
4961
  } = props;
4961
- const resolvedTemplate = typeof initialTemplateProp === "string" ? htmlToEditorConfig(initialTemplateProp) : initialTemplateProp;
4962
- const initializedRef = useRef(false);
4962
+ const resolvedTemplate = useMemo(
4963
+ () => typeof initialTemplateProp === "string" ? htmlToEditorConfig(initialTemplateProp) : initialTemplateProp,
4964
+ [initialTemplateProp]
4965
+ );
4966
+ const prevTemplateRef = useRef(void 0);
4963
4967
  useEffect(() => {
4964
- if (!initializedRef.current) {
4965
- initializedRef.current = true;
4966
- if (resolvedTemplate) {
4967
- resetDocument(resolvedTemplate);
4968
- }
4968
+ if (resolvedTemplate && resolvedTemplate !== prevTemplateRef.current) {
4969
+ prevTemplateRef.current = resolvedTemplate;
4970
+ resetDocument(resolvedTemplate);
4969
4971
  }
4970
4972
  }, [resolvedTemplate]);
4971
4973
  useEffect(() => {