@kontakto/email-template-editor 1.2.0 → 1.3.0
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.cjs +71 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +74 -43
- package/dist/index.js.map +1 -1
- package/package.json +19 -9
package/dist/index.cjs
CHANGED
|
@@ -1677,6 +1677,9 @@ function resetDocument(document2) {
|
|
|
1677
1677
|
selectedBlockId: null
|
|
1678
1678
|
});
|
|
1679
1679
|
}
|
|
1680
|
+
function getDocument() {
|
|
1681
|
+
return editorStateStore.getState().document;
|
|
1682
|
+
}
|
|
1680
1683
|
function setDocument(document2) {
|
|
1681
1684
|
const originalDocument = editorStateStore.getState().document;
|
|
1682
1685
|
editorStateStore.setState({
|
|
@@ -1700,61 +1703,49 @@ function setPersistenceEnabled(persistenceEnabled) {
|
|
|
1700
1703
|
var EmailEditorContext = React81.createContext(null);
|
|
1701
1704
|
var EmailEditorProvider = ({
|
|
1702
1705
|
children,
|
|
1703
|
-
initialTemplate,
|
|
1704
1706
|
initialTemplateId = null,
|
|
1705
1707
|
initialTemplateName = null,
|
|
1706
|
-
onSave
|
|
1707
|
-
onChange
|
|
1708
|
+
onSave
|
|
1708
1709
|
}) => {
|
|
1709
|
-
const [template, setTemplate] = React81.useState(initialTemplate || {});
|
|
1710
1710
|
const [currentTemplateId, setCurrentTemplateId] = React81.useState(initialTemplateId);
|
|
1711
1711
|
const [currentTemplateName, setCurrentTemplateName] = React81.useState(initialTemplateName);
|
|
1712
|
-
const
|
|
1713
|
-
const
|
|
1714
|
-
|
|
1715
|
-
if (onChange) {
|
|
1716
|
-
onChange(newTemplate);
|
|
1717
|
-
}
|
|
1718
|
-
}, [onChange]);
|
|
1712
|
+
const saveListenersRef = React81.useRef([]);
|
|
1713
|
+
const onSaveRef = React81.useRef(onSave);
|
|
1714
|
+
onSaveRef.current = onSave;
|
|
1719
1715
|
const saveTemplate = React81.useCallback(() => {
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1716
|
+
const currentDoc = getDocument();
|
|
1717
|
+
saveListenersRef.current.forEach((listener) => listener(currentDoc));
|
|
1718
|
+
if (onSaveRef.current) {
|
|
1719
|
+
onSaveRef.current(currentDoc);
|
|
1723
1720
|
}
|
|
1724
|
-
return
|
|
1725
|
-
}, [
|
|
1721
|
+
return currentDoc;
|
|
1722
|
+
}, []);
|
|
1726
1723
|
const loadTemplate = React81.useCallback((newTemplate, templateId, templateName) => {
|
|
1727
|
-
setTemplate(newTemplate);
|
|
1728
1724
|
if (templateId !== void 0) {
|
|
1729
1725
|
setCurrentTemplateId(templateId);
|
|
1730
1726
|
}
|
|
1731
1727
|
if (templateName !== void 0) {
|
|
1732
1728
|
setCurrentTemplateName(templateName);
|
|
1733
1729
|
}
|
|
1734
|
-
|
|
1735
|
-
onChange(newTemplate);
|
|
1736
|
-
}
|
|
1737
|
-
}, [onChange]);
|
|
1730
|
+
}, []);
|
|
1738
1731
|
const setCurrentTemplate = React81.useCallback((templateId, templateName) => {
|
|
1739
1732
|
setCurrentTemplateId(templateId);
|
|
1740
1733
|
setCurrentTemplateName(templateName);
|
|
1741
1734
|
}, []);
|
|
1742
1735
|
const registerSaveListener = React81.useCallback((callback) => {
|
|
1743
|
-
|
|
1736
|
+
saveListenersRef.current = [...saveListenersRef.current, callback];
|
|
1744
1737
|
return () => {
|
|
1745
|
-
|
|
1738
|
+
saveListenersRef.current = saveListenersRef.current.filter((listener) => listener !== callback);
|
|
1746
1739
|
};
|
|
1747
1740
|
}, []);
|
|
1748
|
-
const value = {
|
|
1749
|
-
template,
|
|
1741
|
+
const value = React81.useMemo(() => ({
|
|
1750
1742
|
currentTemplateId,
|
|
1751
1743
|
currentTemplateName,
|
|
1752
|
-
updateTemplate,
|
|
1753
1744
|
saveTemplate,
|
|
1754
1745
|
loadTemplate,
|
|
1755
1746
|
registerSaveListener,
|
|
1756
1747
|
setCurrentTemplate
|
|
1757
|
-
};
|
|
1748
|
+
}), [currentTemplateId, currentTemplateName, saveTemplate, loadTemplate, registerSaveListener, setCurrentTemplate]);
|
|
1758
1749
|
return /* @__PURE__ */ React81__default.default.createElement(EmailEditorContext.Provider, { value }, children);
|
|
1759
1750
|
};
|
|
1760
1751
|
var useEmailEditor = () => {
|
|
@@ -4850,6 +4841,31 @@ function TemplatePanel2({ loadTemplates, saveAs }) {
|
|
|
4850
4841
|
}
|
|
4851
4842
|
|
|
4852
4843
|
// src/app/index.tsx
|
|
4844
|
+
function htmlToEditorConfig(html2) {
|
|
4845
|
+
return {
|
|
4846
|
+
root: {
|
|
4847
|
+
type: "EmailLayout",
|
|
4848
|
+
data: {
|
|
4849
|
+
backdropColor: "#F5F5F5",
|
|
4850
|
+
canvasColor: "#FFFFFF",
|
|
4851
|
+
textColor: "#262626",
|
|
4852
|
+
fontFamily: "MODERN_SANS",
|
|
4853
|
+
childrenIds: ["block-html-import"]
|
|
4854
|
+
}
|
|
4855
|
+
},
|
|
4856
|
+
"block-html-import": {
|
|
4857
|
+
type: "Html",
|
|
4858
|
+
data: {
|
|
4859
|
+
style: {
|
|
4860
|
+
padding: { top: 0, bottom: 0, right: 0, left: 0 }
|
|
4861
|
+
},
|
|
4862
|
+
props: {
|
|
4863
|
+
contents: html2
|
|
4864
|
+
}
|
|
4865
|
+
}
|
|
4866
|
+
}
|
|
4867
|
+
};
|
|
4868
|
+
}
|
|
4853
4869
|
function useDrawerTransition(cssProperty, open) {
|
|
4854
4870
|
const { transitions } = material.useTheme();
|
|
4855
4871
|
return transitions.create(cssProperty, {
|
|
@@ -4868,19 +4884,26 @@ var EmailEditorInternal = React81.forwardRef((props, ref) => {
|
|
|
4868
4884
|
loadTemplate,
|
|
4869
4885
|
deleteTemplate,
|
|
4870
4886
|
copyTemplate,
|
|
4871
|
-
saveAs
|
|
4887
|
+
saveAs,
|
|
4888
|
+
onChange
|
|
4872
4889
|
} = props;
|
|
4873
|
-
const {
|
|
4890
|
+
const { saveTemplate, loadTemplate: contextLoadTemplate, currentTemplateId } = useEmailEditor();
|
|
4874
4891
|
const currentDocument = useDocument();
|
|
4875
4892
|
const inspectorDrawerOpen = useInspectorDrawerOpen();
|
|
4876
4893
|
const samplesDrawerOpen = useSamplesDrawerOpen();
|
|
4877
4894
|
const marginLeftTransition = useDrawerTransition("margin-left", samplesDrawerOpen);
|
|
4878
4895
|
const marginRightTransition = useDrawerTransition("margin-right", inspectorDrawerOpen);
|
|
4896
|
+
const onChangeRef = React81.useRef(onChange);
|
|
4897
|
+
onChangeRef.current = onChange;
|
|
4898
|
+
const prevDocJsonRef = React81.useRef("");
|
|
4879
4899
|
React81.useEffect(() => {
|
|
4880
|
-
|
|
4881
|
-
|
|
4900
|
+
var _a;
|
|
4901
|
+
const docJson = JSON.stringify(currentDocument);
|
|
4902
|
+
if (docJson !== prevDocJsonRef.current) {
|
|
4903
|
+
prevDocJsonRef.current = docJson;
|
|
4904
|
+
(_a = onChangeRef.current) == null ? void 0 : _a.call(onChangeRef, currentDocument);
|
|
4882
4905
|
}
|
|
4883
|
-
}, [currentDocument
|
|
4906
|
+
}, [currentDocument]);
|
|
4884
4907
|
React81.useImperativeHandle(ref, () => ({
|
|
4885
4908
|
saveTemplate: () => {
|
|
4886
4909
|
return saveTemplate();
|
|
@@ -4890,7 +4913,7 @@ var EmailEditorInternal = React81.forwardRef((props, ref) => {
|
|
|
4890
4913
|
resetDocument(newTemplate);
|
|
4891
4914
|
},
|
|
4892
4915
|
getTemplate: () => {
|
|
4893
|
-
return
|
|
4916
|
+
return getDocument();
|
|
4894
4917
|
}
|
|
4895
4918
|
}));
|
|
4896
4919
|
return /* @__PURE__ */ React81__default.default.createElement(material.Stack, { position: "relative", id: "drawer-container", sx: { minHeight } }, /* @__PURE__ */ React81__default.default.createElement(
|
|
@@ -4927,7 +4950,7 @@ var EmailEditorInternal = React81.forwardRef((props, ref) => {
|
|
|
4927
4950
|
});
|
|
4928
4951
|
var EmailEditor = React81.forwardRef((props, ref) => {
|
|
4929
4952
|
const {
|
|
4930
|
-
initialTemplate,
|
|
4953
|
+
initialTemplate: initialTemplateProp,
|
|
4931
4954
|
initialTemplateId,
|
|
4932
4955
|
initialTemplateName,
|
|
4933
4956
|
onSave,
|
|
@@ -4945,16 +4968,23 @@ var EmailEditor = React81.forwardRef((props, ref) => {
|
|
|
4945
4968
|
saveAs,
|
|
4946
4969
|
theme
|
|
4947
4970
|
} = props;
|
|
4971
|
+
const resolvedTemplate = typeof initialTemplateProp === "string" ? htmlToEditorConfig(initialTemplateProp) : initialTemplateProp;
|
|
4972
|
+
const initializedRef = React81.useRef(false);
|
|
4948
4973
|
React81.useEffect(() => {
|
|
4949
|
-
if (
|
|
4950
|
-
|
|
4974
|
+
if (!initializedRef.current) {
|
|
4975
|
+
initializedRef.current = true;
|
|
4976
|
+
if (resolvedTemplate) {
|
|
4977
|
+
resetDocument(resolvedTemplate);
|
|
4978
|
+
}
|
|
4951
4979
|
}
|
|
4980
|
+
}, [resolvedTemplate]);
|
|
4981
|
+
React81.useEffect(() => {
|
|
4952
4982
|
setPersistenceEnabled(persistenceEnabled);
|
|
4953
|
-
}, [
|
|
4983
|
+
}, [persistenceEnabled]);
|
|
4954
4984
|
return /* @__PURE__ */ React81__default.default.createElement(material.ThemeProvider, { theme: theme || theme_default }, /* @__PURE__ */ React81__default.default.createElement(material.CssBaseline, null), /* @__PURE__ */ React81__default.default.createElement("div", { style: { height: "100%", overflow: "auto" } }, /* @__PURE__ */ React81__default.default.createElement(SnackbarProvider, null, /* @__PURE__ */ React81__default.default.createElement(
|
|
4955
4985
|
EmailEditorProvider,
|
|
4956
4986
|
{
|
|
4957
|
-
initialTemplate,
|
|
4987
|
+
initialTemplate: resolvedTemplate,
|
|
4958
4988
|
initialTemplateId,
|
|
4959
4989
|
initialTemplateName,
|
|
4960
4990
|
onSave,
|
|
@@ -4973,7 +5003,8 @@ var EmailEditor = React81.forwardRef((props, ref) => {
|
|
|
4973
5003
|
loadTemplate,
|
|
4974
5004
|
deleteTemplate,
|
|
4975
5005
|
copyTemplate,
|
|
4976
|
-
saveAs
|
|
5006
|
+
saveAs,
|
|
5007
|
+
onChange
|
|
4977
5008
|
}
|
|
4978
5009
|
)
|
|
4979
5010
|
))));
|
|
@@ -5033,6 +5064,7 @@ exports.TextPropsSchema = TextPropsSchema;
|
|
|
5033
5064
|
exports.buildBlockComponent = buildBlockComponent;
|
|
5034
5065
|
exports.buildBlockConfigurationDictionary = buildBlockConfigurationDictionary;
|
|
5035
5066
|
exports.buildBlockConfigurationSchema = buildBlockConfigurationSchema;
|
|
5067
|
+
exports.htmlToEditorConfig = htmlToEditorConfig;
|
|
5036
5068
|
exports.renderToStaticMarkup = renderToStaticMarkup;
|
|
5037
5069
|
exports.theme = theme_default;
|
|
5038
5070
|
exports.useEmailEditor = useEmailEditor;
|