@flozy/editor 10.4.4 → 10.4.6

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.
Files changed (165) hide show
  1. package/dist/Editor/ChatEditor.js +17 -16
  2. package/dist/Editor/CommonEditor.js +131 -16
  3. package/dist/Editor/DialogWrapper.js +31 -25
  4. package/dist/Editor/Editor.css +46 -8
  5. package/dist/Editor/Elements/AI/PopoverAIInput.js +11 -3
  6. package/dist/Editor/Elements/Accordion/Accordion.js +46 -9
  7. package/dist/Editor/Elements/Accordion/AccordionSummary.js +1 -23
  8. package/dist/Editor/Elements/AppHeader/AppHeader.js +10 -5
  9. package/dist/Editor/Elements/Button/EditorButton.js +27 -9
  10. package/dist/Editor/Elements/Carousel/CarouselItem.js +2 -1
  11. package/dist/Editor/Elements/Color Picker/ColorButtons.js +61 -14
  12. package/dist/Editor/Elements/Color Picker/ColorPicker.css +25 -1
  13. package/dist/Editor/Elements/Color Picker/ColorPicker.js +10 -7
  14. package/dist/Editor/Elements/Color Picker/Styles.js +15 -13
  15. package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/MultiSelect.js +27 -26
  16. package/dist/Editor/Elements/DataView/Layouts/DataTypes/MultiSelectType.js +5 -5
  17. package/dist/Editor/Elements/DataView/Layouts/Options/AddOptions.js +10 -4
  18. package/dist/Editor/Elements/Embed/Video.js +1 -1
  19. package/dist/Editor/Elements/Form/Form.js +3 -3
  20. package/dist/Editor/Elements/Form/FormElements/FormTextArea.js +0 -1
  21. package/dist/Editor/Elements/Form/FormField.js +3 -2
  22. package/dist/Editor/Elements/Form/Workflow/Styles.js +24 -22
  23. package/dist/Editor/Elements/FreeGrid/FreeGrid.js +35 -31
  24. package/dist/Editor/Elements/FreeGrid/FreeGridBox.js +7 -4
  25. package/dist/Editor/Elements/FreeGrid/FreeGridItem.js +1 -0
  26. package/dist/Editor/Elements/FreeGrid/Options/More.js +7 -7
  27. package/dist/Editor/Elements/FreeGrid/Options/sectionItemOptions.js +1 -1
  28. package/dist/Editor/Elements/FreeGrid/helper.js +115 -0
  29. package/dist/Editor/Elements/FreeGrid/styles.js +14 -0
  30. package/dist/Editor/Elements/Grid/Grid.js +14 -2
  31. package/dist/Editor/Elements/Grid/GridItem.js +1 -1
  32. package/dist/Editor/Elements/Signature/Signature.css +2 -1
  33. package/dist/Editor/Elements/Signature/SignatureOptions/DrawSignature.js +18 -5
  34. package/dist/Editor/Elements/Signature/SignatureOptions/UploadSignature.js +16 -3
  35. package/dist/Editor/Elements/SimpleText/style.js +2 -2
  36. package/dist/Editor/Elements/Table/DragButton.js +0 -1
  37. package/dist/Editor/Elements/Table/Draggable.js +6 -2
  38. package/dist/Editor/Elements/Table/Styles.js +7 -0
  39. package/dist/Editor/Elements/Table/Table.js +3 -3
  40. package/dist/Editor/Elements/Table/TableCell.js +24 -5
  41. package/dist/Editor/Elements/Title/title.js +6 -6
  42. package/dist/Editor/Elements/Variables/VariableButton.js +10 -1
  43. package/dist/Editor/MiniEditor.js +2 -1
  44. package/dist/Editor/Styles/EditorStyles.js +5 -5
  45. package/dist/Editor/Toolbar/FormatTools/Dropdown.js +27 -3
  46. package/dist/Editor/Toolbar/FormatTools/FontFamilyAutocomplete.js +4 -3
  47. package/dist/Editor/Toolbar/FormatTools/MarkButton.js +2 -2
  48. package/dist/Editor/Toolbar/FormatTools/TextSize.js +10 -13
  49. package/dist/Editor/Toolbar/Mini/MiniToolbar.js +2 -1
  50. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/MiniColorPicker.js +4 -2
  51. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectFontSize.js +6 -13
  52. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectTypography.js +167 -42
  53. package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +7 -4
  54. package/dist/Editor/Toolbar/PopupTool/PopperHeader.js +2 -1
  55. package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +72 -12
  56. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +58 -10
  57. package/dist/Editor/Toolbar/PopupTool/ThemeTextFormat.js +439 -0
  58. package/dist/Editor/Toolbar/PopupTool/index.js +1 -1
  59. package/dist/Editor/Toolbar/toolbarGroups.js +48 -6
  60. package/dist/Editor/assets/svg/BackIcon.js +18 -0
  61. package/dist/Editor/assets/svg/ThemeIcons.js +293 -0
  62. package/dist/Editor/common/Checkbox/index.js +46 -0
  63. package/dist/Editor/common/Checkbox/styles.js +45 -0
  64. package/dist/Editor/common/ColorPickerButton.js +41 -16
  65. package/dist/Editor/common/CustomColorPicker/index.js +130 -0
  66. package/dist/Editor/common/CustomColorPicker/style.js +53 -0
  67. package/dist/Editor/common/CustomDialog2/index.js +94 -0
  68. package/dist/Editor/common/CustomDialog2/style.js +67 -0
  69. package/dist/Editor/common/CustomSelect.js +43 -0
  70. package/dist/Editor/common/DnD/DragHandleButton.js +1 -1
  71. package/dist/Editor/common/FontLoader/FontLoader.js +3 -0
  72. package/dist/Editor/common/Icon.js +28 -0
  73. package/dist/Editor/common/ImageSelector/ImageSelector.js +2 -2
  74. package/dist/Editor/common/ImageSelector/Styles.js +3 -9
  75. package/dist/Editor/common/LinkSettings/NavComponents.js +45 -65
  76. package/dist/Editor/common/LinkSettings/index.js +14 -28
  77. package/dist/Editor/common/LinkSettings/navOptions.js +2 -2
  78. package/dist/Editor/common/LinkSettings/style.js +164 -244
  79. package/dist/Editor/common/MentionsPopup/index.js +4 -1
  80. package/dist/Editor/common/RadioGroup/index.js +48 -0
  81. package/dist/Editor/common/RadioGroup/styles.js +29 -0
  82. package/dist/Editor/common/RnD/ElementOptions/Actions.js +4 -5
  83. package/dist/Editor/common/RnD/ElementSettings/OtherSettings/Settings.js +2 -1
  84. package/dist/Editor/common/RnD/ElementSettings/OtherSettings/Signature.js +4 -3
  85. package/dist/Editor/common/RnD/ElementSettings/Settings/AppHeaderSettings.js +3 -2
  86. package/dist/Editor/common/RnD/ElementSettings/Settings/BoxSettings.js +3 -2
  87. package/dist/Editor/common/RnD/ElementSettings/Settings/ButtonSettings.js +3 -2
  88. package/dist/Editor/common/RnD/ElementSettings/Settings/CodeSettings.js +3 -2
  89. package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +4 -2
  90. package/dist/Editor/common/RnD/ElementSettings/Settings/ImageSettings.js +3 -2
  91. package/dist/Editor/common/RnD/ElementSettings/Settings/TableSettings.js +3 -2
  92. package/dist/Editor/common/RnD/ElementSettings/Settings/TextSettings.js +3 -1
  93. package/dist/Editor/common/RnD/ElementSettings/Settings/VideoSettings.js +3 -2
  94. package/dist/Editor/common/RnD/ElementSettings/styles.js +0 -1
  95. package/dist/Editor/common/RnD/OptionsPopup/style.js +0 -1
  96. package/dist/Editor/common/RnD/SwitchViewport/SwitchViewport.js +11 -2
  97. package/dist/Editor/common/RnD/Theme/MainThemeProvider.js +17 -0
  98. package/dist/Editor/common/RnD/Theme/ViewportStimulator.js +6 -3
  99. package/dist/Editor/common/RnD/Utils/gridDropItem.js +28 -19
  100. package/dist/Editor/common/RnD/Utils/index.js +3 -1
  101. package/dist/Editor/common/RnD/VirtualElement/VirtualTextElement.js +42 -58
  102. package/dist/Editor/common/RnD/VirtualElement/helper.js +323 -132
  103. package/dist/Editor/common/RnD/VirtualElement/styles.js +16 -0
  104. package/dist/Editor/common/RnD/index.js +67 -38
  105. package/dist/Editor/common/Select/index.js +44 -7
  106. package/dist/Editor/common/Select/styles.js +30 -2
  107. package/dist/Editor/common/Shorthands/elements.js +54 -0
  108. package/dist/Editor/common/StyleBuilder/accordionTitleBtnStyle.js +2 -2
  109. package/dist/Editor/common/StyleBuilder/accordionTitleStyle.js +12 -9
  110. package/dist/Editor/common/StyleBuilder/buttonStyle.js +4 -2
  111. package/dist/Editor/common/StyleBuilder/embedVideoStyle.js +4 -0
  112. package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +5 -0
  113. package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +12 -2
  114. package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +15 -7
  115. package/dist/Editor/common/StyleBuilder/fieldTypes/card.js +16 -8
  116. package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +36 -10
  117. package/dist/Editor/common/StyleBuilder/fieldTypes/embedUpload.js +115 -0
  118. package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +16 -7
  119. package/dist/Editor/common/StyleBuilder/fieldTypes/index.js +3 -1
  120. package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +15 -7
  121. package/dist/Editor/common/SwipeableDrawer/style.js +14 -12
  122. package/dist/Editor/common/Uploader.js +16 -0
  123. package/dist/Editor/common/iconListV2.js +76 -0
  124. package/dist/Editor/common/iconslist.js +21 -0
  125. package/dist/Editor/commonStyle.js +116 -61
  126. package/dist/Editor/helper/index.js +5 -1
  127. package/dist/Editor/helper/textIndeces.js +58 -0
  128. package/dist/Editor/helper/theme.js +203 -2
  129. package/dist/Editor/hooks/useEditorTheme.js +153 -0
  130. package/dist/Editor/hooks/useMouseMove.js +9 -3
  131. package/dist/Editor/hooks/useTable.js +5 -4
  132. package/dist/Editor/hooks/useThemeValues.js +63 -0
  133. package/dist/Editor/plugins/withEmbeds.js +1 -1
  134. package/dist/Editor/plugins/withHTML.js +3 -1
  135. package/dist/Editor/plugins/withTable.js +1 -1
  136. package/dist/Editor/theme/ThemeList.js +50 -173
  137. package/dist/Editor/theme/index.js +149 -0
  138. package/dist/Editor/themeSettings/ActiveTheme.js +82 -0
  139. package/dist/Editor/themeSettings/buttons/index.js +300 -0
  140. package/dist/Editor/themeSettings/buttons/style.js +23 -0
  141. package/dist/Editor/themeSettings/colorTheme/index.js +310 -0
  142. package/dist/Editor/themeSettings/colorTheme/style.js +81 -0
  143. package/dist/Editor/themeSettings/fonts/PreviewElement.js +121 -0
  144. package/dist/Editor/themeSettings/fonts/index.js +240 -0
  145. package/dist/Editor/themeSettings/fonts/style.js +62 -0
  146. package/dist/Editor/themeSettings/icons.js +60 -0
  147. package/dist/Editor/themeSettings/index.js +380 -0
  148. package/dist/Editor/themeSettings/style.js +299 -0
  149. package/dist/Editor/themeSettingsAI/icons.js +96 -0
  150. package/dist/Editor/themeSettingsAI/index.js +355 -0
  151. package/dist/Editor/themeSettingsAI/saveTheme.js +202 -0
  152. package/dist/Editor/themeSettingsAI/style.js +332 -0
  153. package/dist/Editor/utils/SlateUtilityFunctions.js +161 -37
  154. package/dist/Editor/utils/accordion.js +14 -4
  155. package/dist/Editor/utils/button.js +1 -17
  156. package/dist/Editor/utils/customHooks/useTableResize.js +49 -9
  157. package/dist/Editor/utils/draftToSlate.js +3 -2
  158. package/dist/Editor/utils/events.js +50 -6
  159. package/dist/Editor/utils/font.js +40 -37
  160. package/dist/Editor/utils/formfield.js +1 -0
  161. package/dist/Editor/utils/helper.js +210 -26
  162. package/dist/Editor/utils/insertAppHeader.js +1 -1
  163. package/dist/Editor/utils/signature.js +2 -9
  164. package/dist/Editor/utils/updateFormName.js +22 -0
  165. package/package.json +4 -4
@@ -0,0 +1,153 @@
1
+ import { useSlate } from "slate-react";
2
+ import { defaultTheme } from "../theme";
3
+ import { getPageSettings, updatePageSettings } from "../utils/pageSettings";
4
+ import { HEADING_THEME_FIELDS, PARAGRAPH_THEME_FIELDS } from "../helper/theme";
5
+ import { useEditorContext } from "./useMouseMove";
6
+ const MAP_FIELDS = {
7
+ HEADING: HEADING_THEME_FIELDS,
8
+ PARAGRAPH: PARAGRAPH_THEME_FIELDS
9
+ };
10
+ const MAP_FONT_FIELD_KEYS = {
11
+ HEADING: "headingFontFamily",
12
+ PARAGRAPH: "paragraphFontFamily"
13
+ };
14
+ function getUpdatePayload(prevTheme = {}, update, actionData) {
15
+ const {
16
+ action,
17
+ fieldName
18
+ } = actionData || {};
19
+ const {
20
+ theme: prev
21
+ } = prevTheme;
22
+ let theme = {};
23
+ let themeProps = {};
24
+ switch (action) {
25
+ case "THEME_CHANGE":
26
+ theme = update;
27
+ break;
28
+ case "CSS_VAR_CHANGE":
29
+ const prevCssVars = prev?.cssVars || {};
30
+ const prevValue = prevCssVars[fieldName] || {};
31
+ themeProps = {
32
+ ...(prev || {}),
33
+ cssVars: {
34
+ ...prevCssVars,
35
+ [fieldName]: {
36
+ ...prevValue,
37
+ ...update
38
+ }
39
+ }
40
+ };
41
+ theme = {
42
+ ...prevTheme,
43
+ theme: themeProps
44
+ };
45
+ break;
46
+ case "ELEMENT_PROPS_CHANGE":
47
+ const prevEleProps = prev?.elementProps || {};
48
+ const prevEleValue = prevEleProps[fieldName] || {};
49
+ themeProps = {
50
+ ...(prev || {}),
51
+ elementProps: {
52
+ ...prevEleProps,
53
+ [fieldName]: {
54
+ ...prevEleValue,
55
+ ...update
56
+ }
57
+ }
58
+ };
59
+ theme = {
60
+ ...prevTheme,
61
+ theme: themeProps
62
+ };
63
+ break;
64
+ case "OTHER_PROPS_CHANGE":
65
+ themeProps = {
66
+ ...(prev || {}),
67
+ otherProps: {
68
+ ...(prev.otherProps || {}),
69
+ ...update
70
+ }
71
+ };
72
+ theme = {
73
+ ...prevTheme,
74
+ theme: themeProps
75
+ };
76
+ break;
77
+ case "FONT_CHANGE":
78
+ const {
79
+ elementProps = {},
80
+ otherProps = {}
81
+ } = prev;
82
+ const {
83
+ fieldType
84
+ } = actionData || {};
85
+ const fields = MAP_FIELDS[fieldType];
86
+ const fontFieldsUpdate = {};
87
+ fields?.forEach(field => {
88
+ const prevFieldData = elementProps[field];
89
+ fontFieldsUpdate[field] = {
90
+ ...prevFieldData,
91
+ ...update
92
+ };
93
+ });
94
+ const FONT_KEY_FOR_FIELD = MAP_FONT_FIELD_KEYS[fieldType];
95
+ themeProps = {
96
+ ...(prev || {}),
97
+ elementProps: {
98
+ ...elementProps,
99
+ ...fontFieldsUpdate
100
+ },
101
+ otherProps: {
102
+ ...otherProps,
103
+ [FONT_KEY_FOR_FIELD]: update?.fontFamily
104
+ }
105
+ };
106
+ theme = {
107
+ ...prevTheme,
108
+ theme: themeProps
109
+ };
110
+ break;
111
+ default:
112
+ theme = {
113
+ ...prevTheme,
114
+ ...(update || {})
115
+ };
116
+ break;
117
+ }
118
+ return theme;
119
+ }
120
+ const updateTheme = (editor, pageSt, update, actionData, triggerRender) => {
121
+ const {
122
+ pageProps
123
+ } = pageSt || {};
124
+ const {
125
+ theme
126
+ } = pageProps || {};
127
+ const updatedTheme = getUpdatePayload(theme, update, actionData);
128
+ updatePageSettings(editor, {
129
+ ...(pageProps || {}),
130
+ theme: updatedTheme
131
+ });
132
+ triggerRender();
133
+ };
134
+ export const useEditorTheme = () => {
135
+ const editor = useSlate();
136
+ const {
137
+ triggerRender
138
+ } = useEditorContext();
139
+ const {
140
+ element: pageSt
141
+ } = getPageSettings(editor) || {};
142
+ const {
143
+ pageProps
144
+ } = pageSt || {};
145
+ const {
146
+ theme
147
+ } = pageProps || {};
148
+ return {
149
+ selectedTheme: theme?.theme || defaultTheme?.theme,
150
+ updateTheme: (update, actionData) => updateTheme(editor, pageSt, update, actionData, triggerRender),
151
+ theme
152
+ };
153
+ };
@@ -21,7 +21,10 @@ export const useEditorSelection = editor => {
21
21
  export const EditorProvider = ({
22
22
  editor,
23
23
  theme,
24
- children
24
+ children,
25
+ openTheme = false,
26
+ setOpenTheme = () => {},
27
+ triggerRender
25
28
  }) => {
26
29
  const [previous, setPrevious] = useState("");
27
30
  const [drop, setDrop] = useState(0);
@@ -98,8 +101,11 @@ export const EditorProvider = ({
98
101
  setOpenAI,
99
102
  updateDragging,
100
103
  fontFamilies,
101
- setFontFamilies
102
- }), [path, editor?.selection, selectedPath, selectedElement, contextMenu, openAI, popupType, drop]);
104
+ setFontFamilies,
105
+ openTheme,
106
+ setOpenTheme,
107
+ triggerRender
108
+ }), [path, editor?.selection, selectedPath, selectedElement, contextMenu, openAI, popupType, drop, openTheme]);
103
109
  return /*#__PURE__*/_jsx(EditorContext.Provider, {
104
110
  value: otherValues,
105
111
  children: children
@@ -190,16 +190,17 @@ export const TableProvider = ({
190
190
  // selectFirstCell(tablePath, editor, updateTableSelection);
191
191
  // }, []);
192
192
 
193
+ const onClickAway = () => {
194
+ setTableSelection(getDefaultTableSelection());
195
+ setHoverPath(null);
196
+ };
193
197
  return /*#__PURE__*/_jsx(TableContext.Provider, {
194
198
  value: values,
195
199
  children: /*#__PURE__*/_jsxs(DndContext, {
196
200
  sensors: sensors,
197
201
  onDragEnd: data => handleDragEnd(data, editor, resetAll),
198
202
  children: [/*#__PURE__*/_jsx(ClickAwayListener, {
199
- onClickAway: () => {
200
- setTableSelection(getDefaultTableSelection());
201
- setHoverPath(null);
202
- },
203
+ onClickAway: onClickAway,
203
204
  children: /*#__PURE__*/_jsx("div", {
204
205
  children: children
205
206
  })
@@ -0,0 +1,63 @@
1
+ import { useEffect, useState } from "react";
2
+ import { getElementProperty } from "../helper/theme";
3
+ import { ReactEditor } from "slate-react";
4
+ import { Node } from "slate";
5
+ import { useEditorTheme } from "./useEditorTheme";
6
+ function useThemeValues() {
7
+ return {};
8
+ }
9
+ export default useThemeValues;
10
+ export function useButtonStyle(value, key, element) {
11
+ const [buttonStyle, setButtonStyle] = useState(value);
12
+ const {
13
+ selectedTheme
14
+ } = useEditorTheme();
15
+ const themeBtnProps = selectedTheme?.elementProps?.button || {};
16
+ useEffect(() => {
17
+ const color = getColorValue(value, key, element, themeBtnProps);
18
+ setButtonStyle({
19
+ color
20
+ });
21
+ }, [value, key, element]);
22
+ return {
23
+ buttonStyle
24
+ };
25
+ }
26
+ const DEFAULT_MAP_THEMES = {
27
+ textColor: "color",
28
+ bgColor: "backgroundColor"
29
+ };
30
+ const hoverMap = (theme, format) => {
31
+ const hover = theme?.hover || {};
32
+ const key = DEFAULT_MAP_THEMES[format];
33
+ return hover[key];
34
+ };
35
+ const MAP_THEME_KEYS = {
36
+ ...DEFAULT_MAP_THEMES,
37
+ textColorHover: hoverMap,
38
+ bgColorHover: hoverMap
39
+ };
40
+ const getColorValue = (val, key, elementProps, themeBtnProps) => {
41
+ const themeKey = MAP_THEME_KEYS[key];
42
+ if (elementProps?.type === "button" && !val && themeKey) {
43
+ if (typeof themeKey === "string") {
44
+ return themeBtnProps[themeKey];
45
+ } else {
46
+ return themeKey(themeBtnProps, key);
47
+ }
48
+ }
49
+ return val;
50
+ };
51
+ export function getButtonElementStyle(editor, element, stylePropertyName) {
52
+ try {
53
+ const path = ReactEditor.findPath(editor, element);
54
+ if (path?.length) {
55
+ const currentEle = Node.get(editor, path);
56
+ const dom = ReactEditor.toDOMNode(editor, currentEle);
57
+ const editorBtn = dom?.querySelector(".button.theme-element");
58
+ return getElementProperty(editorBtn, stylePropertyName);
59
+ }
60
+ } catch (err) {
61
+ // console.log(err);
62
+ }
63
+ }
@@ -1,5 +1,5 @@
1
1
  import { Transforms, Path, Node } from "slate";
2
- const AvoidCopying = ["headingOne", "headingTwo", "headingThree", "blockquote"];
2
+ const AvoidCopying = ["headingOne", "headingTwo", "headingThree", "headingFour", "headingFive", "headingSix", "paragraphOne", "paragraphTwo", "paragraphThree", "blockquote"];
3
3
  const BlockTypes = ["grid"];
4
4
  const withEmbeds = editor => {
5
5
  const {
@@ -30,6 +30,8 @@ const parseCopiedHTML = html => {
30
30
 
31
31
  // claude.ai, copy list inbetween, some li tags are not wrapped with ul or ol
32
32
  parsed.querySelectorAll("li").forEach(li => {
33
+ li.innerHTML = li.innerHTML.replace(/^\n+|\n+$/g, ""); // Removes leading and trailing newlines
34
+
33
35
  // Check if the parent of <li> is not a <ul> or <ol>
34
36
  if (!li.parentElement || li.parentElement.tagName !== "UL" && li.parentElement.tagName !== "OL") {
35
37
  // Create a <ul> element
@@ -55,7 +57,7 @@ const loopChildren = (children = [], defaultInsert) => {
55
57
  }
56
58
  return defaultInsert;
57
59
  };
58
- const getCurrentElement = editor => {
60
+ export const getCurrentElement = editor => {
59
61
  try {
60
62
  if (editor.selection) {
61
63
  return Node.parent(editor, editor?.selection?.anchor?.path);
@@ -1,6 +1,6 @@
1
1
  import { Editor, Range, Point, Element, Transforms, Node } from "slate";
2
2
  import { TableUtil, createTableCell } from "../utils/table";
3
- const NON_DELETABLE_BLOCKS = ["table-cell", "carousel-item"];
3
+ const NON_DELETABLE_BLOCKS = ["table-cell", "carousel-item", "page-settings"];
4
4
  const withTable = editor => {
5
5
  const {
6
6
  deleteBackward,
@@ -1,181 +1,58 @@
1
- import { MenuItem, Select, useTheme } from "@mui/material";
2
- import { fontOptions } from "../utils/font";
3
- import { toolbarGroups } from "../Toolbar/toolbarGroups";
1
+ import { Box, MenuItem, Select } from "@mui/material";
2
+ import { defaultTheme } from ".";
3
+ import { useEditorTheme } from "../hooks/useEditorTheme";
4
+ import { useEffect, useState } from "react";
4
5
  import { jsx as _jsx } from "react/jsx-runtime";
5
6
  import { jsxs as _jsxs } from "react/jsx-runtime";
6
- const themes = [{
7
- label: "Theme 1",
8
- colors: ["#c90c1f", "#ff5d05"]
9
- }, {
10
- label: "Theme 2",
11
- colors: ["#4c0be3", "#43f7ee"]
12
- }, {
13
- label: "Theme 3",
14
- colors: ["#22f20f", "#fff705"]
15
- }];
16
- const allTools = toolbarGroups.flat();
17
- function ThemeList(props) {
7
+ function ThemeList({
8
+ editor,
9
+ services = () => {}
10
+ }) {
11
+ const [themes, setThemes] = useState([]);
12
+ const [loading, setLoading] = useState(false);
13
+ console.log("loading", loading);
14
+ const getThemesList = async () => {
15
+ setLoading(true);
16
+ try {
17
+ const result = await services("getThemes", {});
18
+ setThemes(result?.data || []);
19
+ } catch (err) {
20
+ console.log(err);
21
+ }
22
+ setLoading(false);
23
+ };
18
24
  const {
19
- selectedTheme,
20
- setSelectedTheme
21
- } = props;
22
- const fontWeight = allTools.find(f => f.format === "fontWeight");
23
- const fontStyles = [{
24
- text: "Bold",
25
- value: "bold",
26
- styleField: "fontWeight"
27
- }, {
28
- text: "Italic",
29
- value: "italic",
30
- styleField: "fontStyle"
31
- }
32
- // {
33
- // text: "Underline",
34
- // value: "underline",
35
- // styleField: "textDecoration",
36
- // },
37
- // {
38
- // text: "Line through",
39
- // value: "line-through",
40
- // styleField: "textDecoration",
41
- // },
42
- ];
43
-
44
- const theme = useTheme();
45
- const colorVars = theme?.vars?.colors || {};
46
- const handleTypographyTheme = (key, value, elementType) => {
47
- setSelectedTheme(prev => {
48
- const newValue = {
49
- ...prev,
50
- typography: {
51
- ...(prev.typography || {}),
52
- [elementType]: {
53
- ...(prev?.typography?.[elementType] || {}),
54
- [key]: value
55
- }
56
- }
57
- };
58
- if (!value) {
59
- delete newValue?.typography?.[elementType]?.[key];
60
- }
61
- return newValue;
62
- });
25
+ updateTheme
26
+ } = useEditorTheme();
27
+ useEffect(() => {
28
+ getThemesList();
29
+ }, []);
30
+ const handleThemeChange = e => {
31
+ const {
32
+ value
33
+ } = e.target;
34
+ const selectedTheme = themes.find(t => t.id === value) || defaultTheme;
35
+ updateTheme(selectedTheme, "THEME_CHANGE");
63
36
  };
64
- return /*#__PURE__*/_jsxs("div", {
65
- children: [themes.map((theme, i) => {
66
- return /*#__PURE__*/_jsxs("button", {
67
- style: {
68
- margin: "10px"
69
- },
70
- onClick: () => setSelectedTheme(prev => ({
71
- ...prev,
72
- colors: theme.colors
73
- })),
74
- children: [theme.label, /*#__PURE__*/_jsx("div", {
75
- children: theme.colors.map((c, j) => {
76
- return /*#__PURE__*/_jsx("div", {
77
- style: {
78
- width: "20px",
79
- height: "20px",
80
- background: c,
81
- margin: "10px"
82
- }
83
- }, j);
84
- })
85
- })]
86
- }, i);
87
- }), /*#__PURE__*/_jsxs("div", {
88
- children: ["Heading 1 Font Family", /*#__PURE__*/_jsx(Select
89
- // value={""}
90
- , {
91
- label: "Font Family",
92
- onChange: e => {
93
- handleTypographyTheme("fontFamily", e.target.value, "h1");
94
- },
95
- children: fontOptions.map((font, i) => {
96
- const {
97
- text,
98
- value
99
- } = font;
100
- return /*#__PURE__*/_jsx(MenuItem, {
101
- value: value,
102
- children: text
103
- }, i);
104
- })
105
- }), "Font Weight", /*#__PURE__*/_jsx(Select
106
- // value={""}
107
- , {
108
- label: "Font Weight",
109
- onChange: e => {
110
- handleTypographyTheme("fontWeight", e.target.value, "h1");
111
- },
112
- children: fontWeight.options.map((option, i) => {
113
- const {
114
- text,
115
- value
116
- } = option;
117
- return /*#__PURE__*/_jsx(MenuItem, {
118
- value: value,
119
- children: text
120
- }, i);
121
- })
122
- }), /*#__PURE__*/_jsx("input", {
123
- type: "number",
124
- placeholder: "font size",
125
- onChange: e => {
126
- handleTypographyTheme("fontSize", e.target.value, "h1");
127
- }
128
- }), /*#__PURE__*/_jsxs("div", {
129
- children: ["Text", /*#__PURE__*/_jsx("br", {}), "Theme color", Object.values(colorVars).map((colorVar, i) => {
130
- return /*#__PURE__*/_jsx("button", {
131
- style: {
132
- width: "20px",
133
- height: "20px",
134
- background: colorVar,
135
- margin: "10px",
136
- outline: "none"
137
- },
138
- onClick: () => handleTypographyTheme("color", colorVar, "h1")
139
- }, i);
140
- }), "normal color", /*#__PURE__*/_jsx("button", {
141
- style: {
142
- width: "20px",
143
- height: "20px",
144
- background: "#ff00e1",
145
- margin: "10px",
146
- outline: "none"
147
- },
148
- onClick: () => handleTypographyTheme("color", "#ff00e1", "h1")
149
- })]
150
- }), /*#__PURE__*/_jsxs("div", {
151
- children: ["Font styles", fontStyles.map((option, i) => {
152
- const styles = selectedTheme?.typography?.h1 || {};
153
- const {
154
- text,
155
- value,
156
- styleField
157
- } = option;
158
- return /*#__PURE__*/_jsxs("button", {
159
- onClick: () => {
160
- handleTypographyTheme(styleField, styles[styleField] === value ? null : value, "h1");
161
- },
162
- children: [text, " ", styles[styleField] === value]
163
- }, i);
164
- })]
165
- }), /*#__PURE__*/_jsx("input", {
166
- type: "number",
167
- placeholder: "Margin text Spacing",
168
- onChange: e => {
169
- handleTypographyTheme("letterSpacing", e.target.value, "h1");
170
- }
171
- }), /*#__PURE__*/_jsx("input", {
172
- type: "number",
173
- placeholder: "Line spacing",
174
- onChange: e => {
175
- handleTypographyTheme("lineHeight", e.target.value, "h1");
176
- }
37
+ return /*#__PURE__*/_jsx(Box, {
38
+ sx: {
39
+ padding: "10px",
40
+ background: "#efefef",
41
+ borderRadius: "6px"
42
+ },
43
+ children: /*#__PURE__*/_jsxs(Select, {
44
+ onChange: handleThemeChange,
45
+ defaultValue: 0,
46
+ children: [/*#__PURE__*/_jsx(MenuItem, {
47
+ value: 0,
48
+ children: "Default Theme"
49
+ }), themes.map((theme, i) => {
50
+ return /*#__PURE__*/_jsx(MenuItem, {
51
+ value: theme?.id,
52
+ children: theme?.name
53
+ }, i);
177
54
  })]
178
- })]
55
+ })
179
56
  });
180
57
  }
181
58
  export default ThemeList;
@@ -0,0 +1,149 @@
1
+ import { getDevice } from "../helper/theme";
2
+ const themeClassName = ".theme-element";
3
+ function getTextStyles(props) {
4
+ const {
5
+ fontSize,
6
+ textDecoration,
7
+ color,
8
+ ...rest
9
+ } = props;
10
+ const device = getDevice();
11
+ const fontS = typeof fontSize === "object" ? fontSize[device] : fontSize;
12
+ return {
13
+ ...rest,
14
+ '& span[data-slate-string="true"]': {
15
+ textDecoration,
16
+ fontSize: fontS,
17
+ color: color || "inherit"
18
+ }
19
+
20
+ // "&::after": {
21
+ // // for placeholder
22
+ // fontSize,
23
+ // },
24
+ };
25
+ }
26
+
27
+ const transformHeading = (props, elementType) => {
28
+ return {
29
+ [`& ${elementType}${themeClassName}`]: getTextStyles(props)
30
+ };
31
+ };
32
+ const transformParagraph = (props, paraType) => {
33
+ return {
34
+ [`& p${themeClassName}.${paraType}`]: getTextStyles(props)
35
+ };
36
+ };
37
+ const transformButton = props => {
38
+ const {
39
+ borderRadius,
40
+ lockRadius,
41
+ bannerSpacing,
42
+ buttonIcon,
43
+ hover,
44
+ ...classProps
45
+ } = props;
46
+ return {
47
+ [`& .button${themeClassName}`]: {
48
+ ...classProps,
49
+ "&:hover": hover
50
+ },
51
+ buttonTheme: {
52
+ borderRadius,
53
+ lockRadius,
54
+ bannerSpacing,
55
+ buttonIcon
56
+ }
57
+ };
58
+ };
59
+ const transformProps = (elementType, props) => {
60
+ let transformedProp = {};
61
+ let otherProps = {};
62
+ switch (elementType) {
63
+ case "h1":
64
+ case "h2":
65
+ case "h3":
66
+ case "h4":
67
+ case "h5":
68
+ case "h6":
69
+ transformedProp = transformHeading(props, elementType);
70
+ break;
71
+ case "para1":
72
+ case "para2":
73
+ case "para3":
74
+ transformedProp = transformParagraph(props, elementType);
75
+ break;
76
+ case "button":
77
+ const {
78
+ buttonTheme,
79
+ ...classProps
80
+ } = transformButton(props, elementType);
81
+ transformedProp = classProps;
82
+ otherProps = {
83
+ buttonTheme
84
+ };
85
+ break;
86
+ default:
87
+ }
88
+ return {
89
+ transformedProp,
90
+ otherProps
91
+ };
92
+ };
93
+ export const transformTheme = (selectedTheme = {}) => {
94
+ let sxProps = {};
95
+ let others = {};
96
+ const {
97
+ elementProps
98
+ } = selectedTheme;
99
+ if (elementProps) {
100
+ Object.entries(elementProps).forEach(([key, value]) => {
101
+ const {
102
+ transformedProp,
103
+ otherProps
104
+ } = transformProps(key, value);
105
+ sxProps = {
106
+ ...sxProps,
107
+ ...transformedProp
108
+ };
109
+ others = {
110
+ ...others,
111
+ ...otherProps
112
+ };
113
+ });
114
+ }
115
+ return {
116
+ sxProps,
117
+ ...others
118
+ };
119
+ };
120
+ export const defaultTheme = {
121
+ theme: {
122
+ cssVars: {},
123
+ elementProps: {
124
+ button: {
125
+ color: "#FFFFFF",
126
+ background: "#2563EB",
127
+ fontFamily: "PoppinsRegular",
128
+ fontWeight: 400,
129
+ fontSize: "inherit",
130
+ borderColor: "transparent",
131
+ borderRadius: {
132
+ topLeft: 30,
133
+ topRight: 30,
134
+ bottomLeft: 30,
135
+ bottomRight: 30
136
+ },
137
+ bannerSpacing: {
138
+ left: 16,
139
+ top: 8,
140
+ right: 16,
141
+ bottom: 8
142
+ }
143
+ }
144
+ }
145
+ }
146
+ };
147
+ export function getTheme(selectedTheme) {
148
+ return transformTheme(selectedTheme?.theme || defaultTheme.theme);
149
+ }