@flozy/editor 7.0.7 → 7.0.8
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/Editor/ChatEditor.js +7 -7
- package/dist/Editor/CommonEditor.js +74 -25
- package/dist/Editor/DialogWrapper.js +31 -25
- package/dist/Editor/Editor.css +33 -16
- package/dist/Editor/Elements/AI/PopoverAIInput.js +2 -12
- package/dist/Editor/Elements/AppHeader/AppHeader.js +3 -3
- package/dist/Editor/Elements/Button/EditorButton.js +26 -9
- package/dist/Editor/Elements/Color Picker/ColorButtons.js +57 -12
- package/dist/Editor/Elements/Color Picker/ColorPicker.css +25 -1
- package/dist/Editor/Elements/Color Picker/ColorPicker.js +4 -4
- package/dist/Editor/Elements/Color Picker/Styles.js +1 -1
- package/dist/Editor/Elements/DataView/DataView.js +4 -3
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/NumberType.js +5 -1
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/TextType.js +5 -1
- package/dist/Editor/Elements/DataView/Layouts/FilterView.js +23 -19
- package/dist/Editor/Elements/DataView/Providers/DataViewProvider.js +1 -1
- package/dist/Editor/Elements/Embed/Image.js +2 -2
- package/dist/Editor/Elements/Form/Form.js +1 -0
- package/dist/Editor/Elements/FreeGrid/FreeGrid.js +0 -14
- package/dist/Editor/Elements/FreeGrid/styles.js +4 -0
- package/dist/Editor/Elements/Grid/GridItem.js +2 -3
- package/dist/Editor/Elements/Link/Link.js +70 -43
- package/dist/Editor/Elements/List/CheckList.js +2 -1
- package/dist/Editor/Elements/Search/SearchAttachment.js +1 -0
- package/dist/Editor/Elements/Search/SearchList.js +8 -1
- package/dist/Editor/Elements/SimpleText/index.js +8 -1
- package/dist/Editor/Elements/SimpleText/style.js +5 -1
- package/dist/Editor/Elements/Table/Table.js +3 -3
- package/dist/Editor/Elements/Table/TableCell.js +14 -9
- package/dist/Editor/Elements/Title/title.js +13 -1
- package/dist/Editor/Elements/Variables/Style.js +28 -2
- package/dist/Editor/Elements/Variables/VariableButton.js +17 -4
- package/dist/Editor/MiniEditor.js +4 -2
- package/dist/Editor/Toolbar/FormatTools/Dropdown.js +27 -3
- package/dist/Editor/Toolbar/FormatTools/FontFamilyAutocomplete.js +4 -3
- package/dist/Editor/Toolbar/FormatTools/MarkButton.js +2 -2
- package/dist/Editor/Toolbar/FormatTools/TextSize.js +7 -15
- package/dist/Editor/Toolbar/PopupTool/AddTemplates.js +46 -36
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectAlignment.js +3 -1
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectFontSize.js +6 -13
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectList.js +3 -1
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectTypography.js +211 -91
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +11 -4
- package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +16 -12
- package/dist/Editor/Toolbar/PopupTool/TemplateCard.js +1 -1
- package/dist/Editor/Toolbar/PopupTool/TextFormat.js +99 -7
- package/dist/Editor/Toolbar/PopupTool/ThemeTextFormat.js +438 -0
- package/dist/Editor/Toolbar/PopupTool/index.js +2 -0
- package/dist/Editor/Toolbar/toolbarGroups.js +48 -6
- package/dist/Editor/assets/svg/ThemeIcons.js +291 -0
- package/dist/Editor/common/ColorPickerButton.js +35 -9
- package/dist/Editor/common/CustomColorPicker/index.js +106 -0
- package/dist/Editor/common/CustomColorPicker/style.js +53 -0
- package/dist/Editor/common/CustomDialog/index.js +94 -0
- package/dist/Editor/common/CustomDialog/style.js +67 -0
- package/dist/Editor/common/CustomSelect.js +33 -0
- package/dist/Editor/common/DnD/DragHandleButton.js +1 -1
- package/dist/Editor/common/DnD/Draggable.js +0 -1
- package/dist/Editor/common/FontLoader/FontList.js +1 -9
- package/dist/Editor/common/FontLoader/FontLoader.js +6 -4
- package/dist/Editor/common/Icon.js +28 -0
- package/dist/Editor/common/ImageSelector/Styles.js +3 -9
- package/dist/Editor/common/MentionsPopup/Styles.js +3 -9
- package/dist/Editor/common/MentionsPopup/index.js +0 -1
- package/dist/Editor/common/RnD/ElementSettings/OtherSettings/Settings.js +2 -1
- package/dist/Editor/common/RnD/ElementSettings/Settings/AppHeaderSettings.js +3 -2
- package/dist/Editor/common/RnD/ElementSettings/Settings/BoxSettings.js +3 -2
- package/dist/Editor/common/RnD/ElementSettings/Settings/ButtonSettings.js +3 -2
- package/dist/Editor/common/RnD/ElementSettings/Settings/CodeSettings.js +3 -2
- package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +4 -2
- package/dist/Editor/common/RnD/ElementSettings/Settings/ImageSettings.js +3 -2
- package/dist/Editor/common/RnD/ElementSettings/Settings/TableSettings.js +3 -2
- package/dist/Editor/common/RnD/ElementSettings/Settings/VideoSettings.js +3 -2
- package/dist/Editor/common/RnD/SwitchViewport/SwitchViewport.js +14 -2
- package/dist/Editor/common/RnD/Theme/MainThemeProvider.js +17 -0
- package/dist/Editor/common/RnD/Theme/ViewportStimulator.js +6 -3
- package/dist/Editor/common/RnD/Utils/gridDropItem.js +5 -4
- package/dist/Editor/common/RnD/Utils/index.js +40 -0
- package/dist/Editor/common/RnD/index.js +23 -3
- package/dist/Editor/common/Shorthands/elements.js +54 -0
- package/dist/Editor/common/StyleBuilder/buttonStyle.js +4 -2
- package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +5 -0
- package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +12 -2
- package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +15 -7
- package/dist/Editor/common/StyleBuilder/fieldTypes/card.js +10 -2
- package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +35 -11
- package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +13 -4
- package/dist/Editor/common/StyleBuilder/fieldTypes/index.js +3 -1
- package/dist/Editor/common/StyleBuilder/fieldTypes/lineSpacing.js +79 -0
- package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +15 -7
- package/dist/Editor/common/StyleBuilder/pageSettingsStyle.js +4 -0
- package/dist/Editor/common/Uploader.js +8 -0
- package/dist/Editor/commonStyle.js +58 -63
- package/dist/Editor/helper/ensureWrappedVariables.js +28 -0
- package/dist/Editor/helper/index.js +2 -2
- package/dist/Editor/helper/theme.js +224 -3
- package/dist/Editor/hooks/useEditorTheme.js +153 -0
- package/dist/Editor/hooks/useMouseMove.js +13 -5
- package/dist/Editor/plugins/withEmbeds.js +1 -1
- package/dist/Editor/plugins/withHTML.js +4 -2
- package/dist/Editor/plugins/withLayout.js +1 -1
- package/dist/Editor/plugins/withTable.js +1 -1
- package/dist/Editor/theme/ThemeList.js +50 -173
- package/dist/Editor/theme/index.js +144 -0
- package/dist/Editor/themeSettings/ActiveTheme.js +72 -0
- package/dist/Editor/themeSettings/buttons/index.js +283 -0
- package/dist/Editor/themeSettings/buttons/style.js +21 -0
- package/dist/Editor/themeSettings/colorTheme/index.js +292 -0
- package/dist/Editor/themeSettings/colorTheme/style.js +77 -0
- package/dist/Editor/themeSettings/fonts/PreviewElement.js +121 -0
- package/dist/Editor/themeSettings/fonts/index.js +220 -0
- package/dist/Editor/themeSettings/fonts/style.js +44 -0
- package/dist/Editor/themeSettings/icons.js +60 -0
- package/dist/Editor/themeSettings/index.js +320 -0
- package/dist/Editor/themeSettings/style.js +152 -0
- package/dist/Editor/themeSettingsAI/icons.js +96 -0
- package/dist/Editor/themeSettingsAI/index.js +356 -0
- package/dist/Editor/themeSettingsAI/saveTheme.js +197 -0
- package/dist/Editor/themeSettingsAI/style.js +250 -0
- package/dist/Editor/utils/SlateUtilityFunctions.js +161 -42
- package/dist/Editor/utils/button.js +0 -14
- package/dist/Editor/utils/customHooks/useTableResize.js +2 -1
- package/dist/Editor/utils/draftToSlate.js +3 -2
- package/dist/Editor/utils/font.js +40 -37
- package/dist/Editor/utils/helper.js +88 -19
- package/dist/Editor/utils/link.js +1 -1
- package/dist/Editor/utils/pageSettings.js +14 -2
- package/dist/Editor/utils/table.js +21 -0
- package/package.json +5 -2
@@ -49,37 +49,32 @@ const useCommonStyle = theme => ({
|
|
49
49
|
fontWeight: "500",
|
50
50
|
fontFamily: "Inter, sans-serif"
|
51
51
|
},
|
52
|
+
"& .MuiPaper-root": {
|
53
|
+
border: `unset !important`,
|
54
|
+
borderRadius: "0px",
|
55
|
+
height: "fit-content",
|
56
|
+
padding: "2px"
|
57
|
+
},
|
52
58
|
"& p": {
|
53
59
|
marginBottom: "7px",
|
54
60
|
marginTop: "4px"
|
55
61
|
},
|
56
|
-
"&
|
57
|
-
|
58
|
-
|
59
|
-
height: 'fit-content',
|
60
|
-
padding: '2px'
|
62
|
+
"& p": {
|
63
|
+
marginBottom: "7px",
|
64
|
+
marginTop: "4px"
|
61
65
|
},
|
62
66
|
"& .muiIconsListParent": {
|
63
67
|
"& svg": {
|
64
68
|
color: `${theme?.palette?.editor?.svgTextAlignStrokeColor} !important`
|
65
69
|
},
|
66
|
-
"&::-webkit-scrollbar-thumb": {
|
67
|
-
background: `none !important`
|
68
|
-
},
|
69
|
-
"&::-webkit-scrollbar-track": {
|
70
|
-
visibility: "hidden"
|
71
|
-
},
|
72
70
|
"&::-webkit-scrollbar-thumb": {
|
73
71
|
background: `${theme?.palette?.editor?.brainPopupScroll} !important`
|
74
|
-
},
|
75
|
-
"&::-webkit-scrollbar-track": {
|
76
|
-
visibility: "hidden"
|
77
72
|
}
|
78
73
|
},
|
79
74
|
"& .MuiGrid-root>.MuiGrid-item": {
|
80
75
|
paddingRight: "0px !important",
|
81
76
|
fontFamily: "Inter, sans-serif",
|
82
|
-
height:
|
77
|
+
height: "fit-content"
|
83
78
|
},
|
84
79
|
"& .MuiInputBase-root": {
|
85
80
|
borderRadius: "10px",
|
@@ -140,11 +135,11 @@ const useCommonStyle = theme => ({
|
|
140
135
|
borderRadius: "10px",
|
141
136
|
width: "46px !important",
|
142
137
|
marginLeft: "10px",
|
143
|
-
height:
|
138
|
+
height: "36px !important"
|
144
139
|
}
|
145
140
|
},
|
146
|
-
|
147
|
-
margin:
|
141
|
+
"& .MuiFormHelperText-root": {
|
142
|
+
margin: "4px 0px 0px 0px",
|
148
143
|
color: theme?.palette?.editor?.closeButtonSvgStroke,
|
149
144
|
fontFamily: "Inter, sans-serif"
|
150
145
|
}
|
@@ -400,14 +395,14 @@ const useCommonStyle = theme => ({
|
|
400
395
|
padding: "8px 12px",
|
401
396
|
fontSize: "12px",
|
402
397
|
color: theme?.palette?.editor?.menuOptionTextColor,
|
403
|
-
fontWeight:
|
398
|
+
fontWeight: "500",
|
404
399
|
fontFamily: "Inter, sans-serif",
|
405
|
-
minHeight:
|
400
|
+
minHeight: "36px",
|
406
401
|
"&:hover": {
|
407
402
|
backgroundColor: theme?.palette?.editor?.menuOptionHoverBackground
|
408
403
|
}
|
409
404
|
},
|
410
|
-
|
405
|
+
"& .Mui-selected": {
|
411
406
|
background: `${theme?.palette?.editor?.menuOptionSelectedOption} !important`
|
412
407
|
},
|
413
408
|
"& .MuiListSubheader-root": {
|
@@ -416,16 +411,16 @@ const useCommonStyle = theme => ({
|
|
416
411
|
fontSize: "12px"
|
417
412
|
},
|
418
413
|
"& .MuiPaper-root": {
|
419
|
-
borderRadius:
|
420
|
-
padding:
|
414
|
+
borderRadius: "8px",
|
415
|
+
padding: "0px",
|
421
416
|
background: `${theme?.palette?.editor?.textWeightPopUpBackground} !important`
|
422
417
|
},
|
423
|
-
|
424
|
-
margin:
|
425
|
-
borderRadius:
|
418
|
+
"& .MuiButtonBase-root": {
|
419
|
+
margin: "4px",
|
420
|
+
borderRadius: "6px"
|
426
421
|
},
|
427
|
-
|
428
|
-
padding:
|
422
|
+
"& .MuiList-root": {
|
423
|
+
padding: "0px"
|
429
424
|
}
|
430
425
|
},
|
431
426
|
datePicker: {
|
@@ -470,27 +465,27 @@ const useCommonStyle = theme => ({
|
|
470
465
|
}
|
471
466
|
}
|
472
467
|
},
|
473
|
-
pageSettingPopUpRoot: {
|
474
|
-
padding: "16px 8px 16px 10px!important",
|
475
|
-
height: "100%"
|
476
|
-
},
|
477
468
|
buttonMoreOption: {
|
478
469
|
background: `${theme?.palette?.editor?.aiInputBackground} !important`,
|
479
470
|
border: `1px solid ${theme?.palette?.editor?.buttonBorder1} !important`,
|
480
|
-
padding:
|
481
|
-
|
482
|
-
width:
|
483
|
-
height:
|
484
|
-
|
471
|
+
padding: "4px !important",
|
472
|
+
"& svg": {
|
473
|
+
width: "18px !important",
|
474
|
+
height: "18px !important",
|
475
|
+
"& path": {
|
485
476
|
stroke: `${theme?.palette?.editor?.closeButtonSvgStroke} !important`
|
486
477
|
}
|
487
478
|
}
|
488
479
|
},
|
480
|
+
pageSettingPopUpRoot: {
|
481
|
+
padding: "16px 8px 16px 10px!important",
|
482
|
+
height: "100%"
|
483
|
+
},
|
489
484
|
buttonMoreOption2: {
|
490
485
|
background: `${theme?.palette?.editor?.aiInputBackground} !important`,
|
491
486
|
border: `1px solid ${theme?.palette?.editor?.buttonBorder1} !important`,
|
492
|
-
|
493
|
-
|
487
|
+
"& svg": {
|
488
|
+
"& path": {
|
494
489
|
fill: `${theme?.palette?.editor?.closeButtonSvgStroke} !important`
|
495
490
|
}
|
496
491
|
}
|
@@ -498,11 +493,11 @@ const useCommonStyle = theme => ({
|
|
498
493
|
buttonMoreOption3: {
|
499
494
|
background: `${theme?.palette?.editor?.aiInputBackground} !important`,
|
500
495
|
border: `1px solid ${theme?.palette?.editor?.buttonBorder1} !important`,
|
501
|
-
padding:
|
502
|
-
|
503
|
-
width:
|
504
|
-
height:
|
505
|
-
|
496
|
+
padding: "5px !important",
|
497
|
+
"& svg": {
|
498
|
+
width: "16px !important",
|
499
|
+
height: "16px !important",
|
500
|
+
"& path": {
|
506
501
|
stroke: `${theme?.palette?.editor?.closeButtonSvgStroke} !important`
|
507
502
|
}
|
508
503
|
}
|
@@ -510,37 +505,37 @@ const useCommonStyle = theme => ({
|
|
510
505
|
resizeButton: {
|
511
506
|
background: theme?.palette?.editor?.aiInputBackground,
|
512
507
|
border: `1px solid ${theme?.palette?.editor?.buttonBorder1}`,
|
513
|
-
padding:
|
514
|
-
borderRadius:
|
515
|
-
|
516
|
-
width:
|
517
|
-
height:
|
518
|
-
|
508
|
+
padding: "5px !important",
|
509
|
+
borderRadius: "50% !important",
|
510
|
+
"& svg": {
|
511
|
+
width: "18px",
|
512
|
+
height: "18px",
|
513
|
+
"& path": {
|
519
514
|
fill: `${theme?.palette?.editor?.closeButtonSvgStroke}`
|
520
515
|
}
|
521
516
|
},
|
522
|
-
|
517
|
+
"&:hover": {
|
523
518
|
background: theme?.palette?.editor?.aiInputBackground
|
524
519
|
}
|
525
520
|
},
|
526
521
|
gradientFillBtn: {
|
527
522
|
background: `linear-gradient(112.61deg, #2C63ED 19.3%, #8360FD 88.14%) !important`,
|
528
|
-
textTransform:
|
529
|
-
color:
|
530
|
-
padding:
|
531
|
-
height:
|
532
|
-
borderRadius:
|
533
|
-
fontWeight:
|
534
|
-
fontSize:
|
523
|
+
textTransform: "math-auto !important",
|
524
|
+
color: "#FFFFFF !important",
|
525
|
+
padding: "0px 12px !important",
|
526
|
+
height: "32px",
|
527
|
+
borderRadius: "8px",
|
528
|
+
fontWeight: "500",
|
529
|
+
fontSize: "14px"
|
535
530
|
},
|
536
531
|
emptyThumbBtn: {
|
537
532
|
background: `${theme?.palette?.editor?.sectionSettingIconHover} !important`,
|
538
533
|
color: `${theme?.palette?.editor?.textColor} !important`,
|
539
|
-
fontSize:
|
540
|
-
|
541
|
-
width:
|
542
|
-
height:
|
543
|
-
|
534
|
+
fontSize: "14px !important",
|
535
|
+
"& svg": {
|
536
|
+
width: "20px !important",
|
537
|
+
height: "20px !important",
|
538
|
+
"& path": {
|
544
539
|
stroke: `${theme?.palette?.editor?.closeButtonSvgStroke} !important`
|
545
540
|
}
|
546
541
|
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
export const ensureWrappedVariables = content => {
|
2
|
+
return content.map(node => {
|
3
|
+
if (node.children) {
|
4
|
+
return {
|
5
|
+
...node,
|
6
|
+
children: node.children.reduce((result, child, index, arr) => {
|
7
|
+
if (child.type === "variables") {
|
8
|
+
if (index === 0 || !arr[index - 1].text || arr[index - 1].text.trim() === "") {
|
9
|
+
result.push({
|
10
|
+
text: ""
|
11
|
+
});
|
12
|
+
}
|
13
|
+
result.push(child);
|
14
|
+
if (index === arr.length - 1 || !arr[index + 1]?.text || arr[index + 1]?.text.trim() === "") {
|
15
|
+
result.push({
|
16
|
+
text: ""
|
17
|
+
});
|
18
|
+
}
|
19
|
+
} else {
|
20
|
+
result.push(child);
|
21
|
+
}
|
22
|
+
return result;
|
23
|
+
}, [])
|
24
|
+
};
|
25
|
+
}
|
26
|
+
return node;
|
27
|
+
});
|
28
|
+
};
|
@@ -337,14 +337,14 @@ export const isCarouselSelected = editor => {
|
|
337
337
|
return false;
|
338
338
|
}
|
339
339
|
const [nodeEntry] = Editor.nodes(editor, {
|
340
|
-
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type ===
|
340
|
+
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "carousel"
|
341
341
|
});
|
342
342
|
if (!nodeEntry) {
|
343
343
|
return false;
|
344
344
|
}
|
345
345
|
const [node] = nodeEntry;
|
346
346
|
const carouselDom = ReactEditor.toDOMNode(editor, node);
|
347
|
-
const isEdit = carouselDom.classList.contains(
|
347
|
+
const isEdit = carouselDom.classList.contains("carousel_slider_edit");
|
348
348
|
return !isEdit;
|
349
349
|
} catch (err) {
|
350
350
|
console.log(err);
|
@@ -1,4 +1,6 @@
|
|
1
|
+
import { ReactEditor } from "slate-react";
|
1
2
|
import { sizeMap } from "../utils/font";
|
3
|
+
import { Editor, Node } from "slate";
|
2
4
|
export const breakpoints = {
|
3
5
|
small: 0,
|
4
6
|
mobile: 600,
|
@@ -33,7 +35,7 @@ const overrideValues = (value, ot) => {
|
|
33
35
|
return Object.keys(value).reduce((a, b) => {
|
34
36
|
return {
|
35
37
|
...a,
|
36
|
-
[b]: overrides[ot] ? overrides[ot](value[b]) : value
|
38
|
+
[b]: overrides[ot] ? overrides[ot](value[b], value) : value
|
37
39
|
};
|
38
40
|
}, {});
|
39
41
|
};
|
@@ -50,7 +52,15 @@ const overrides = {
|
|
50
52
|
overrideReSizeH: val => {
|
51
53
|
return val ? `${val?.height}px` : "auto";
|
52
54
|
},
|
53
|
-
overrideBorderRadius: val => {
|
55
|
+
overrideBorderRadius: (val, breakpointValues) => {
|
56
|
+
if (!val?.topLeft) {
|
57
|
+
Object.values(breakpointValues || {}).forEach(v => {
|
58
|
+
if (v) {
|
59
|
+
// Applying the values from breakpoints that exist to those that do not have
|
60
|
+
val = v;
|
61
|
+
}
|
62
|
+
});
|
63
|
+
}
|
54
64
|
return `${val?.topLeft}px ${val?.topRight}px ${val?.bottomLeft}px ${val?.bottomRight}px`;
|
55
65
|
}
|
56
66
|
};
|
@@ -118,6 +128,194 @@ export const getTRBLBreakPoints = (value, breakpoint) => {
|
|
118
128
|
console.log(err);
|
119
129
|
}
|
120
130
|
};
|
131
|
+
export function getElementStyle(editor, element, stylePropertyName) {
|
132
|
+
try {
|
133
|
+
const path = ReactEditor.findPath(editor, element);
|
134
|
+
if (path?.length) {
|
135
|
+
const currentEle = Node.get(editor, path);
|
136
|
+
const dom = ReactEditor.toDOMNode(editor, currentEle);
|
137
|
+
const editorBtn = dom?.querySelector(".button.theme-element");
|
138
|
+
return getElementProperty(editorBtn, stylePropertyName);
|
139
|
+
}
|
140
|
+
} catch (err) {
|
141
|
+
// console.log(err);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
export function getTextSizeVal(editor) {
|
145
|
+
try {
|
146
|
+
const currentNode = Node.get(editor, editor.selection.anchor.path);
|
147
|
+
const currentElement = ReactEditor.toDOMNode(editor, currentNode);
|
148
|
+
if (currentElement) {
|
149
|
+
const element = currentElement.querySelector('span[data-slate-string="true"]');
|
150
|
+
return getElementProperty(element, "font-size");
|
151
|
+
}
|
152
|
+
} catch (err) {
|
153
|
+
// console.log(err);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
export function getVariableValue(val) {
|
157
|
+
const bodyElement = document.body;
|
158
|
+
const computedStyle = getComputedStyle(bodyElement);
|
159
|
+
const [, variableName] = val?.match(/var\((--[^)]+)\)/) || [];
|
160
|
+
const varValue = computedStyle.getPropertyValue(variableName).trim();
|
161
|
+
return varValue;
|
162
|
+
}
|
163
|
+
const MAP_PROPERTY_KEYS = {
|
164
|
+
fontFamily: "font-family",
|
165
|
+
fontSize: "font-size",
|
166
|
+
textSize: "font-size",
|
167
|
+
fontWeight: "font-weight"
|
168
|
+
};
|
169
|
+
export function getElementProperty(element, styleProperty) {
|
170
|
+
if (!element) {
|
171
|
+
return "";
|
172
|
+
}
|
173
|
+
const computedStyle = window.getComputedStyle(element);
|
174
|
+
const property = MAP_PROPERTY_KEYS[styleProperty] || styleProperty;
|
175
|
+
let style = computedStyle.getPropertyValue(property);
|
176
|
+
if (property === "font-family") {
|
177
|
+
style = style.replace(/"/g, ""); // remove double quotes if exists e.g: '"Courier New"'
|
178
|
+
}
|
179
|
+
|
180
|
+
return style || "";
|
181
|
+
}
|
182
|
+
export const textThemeFields = ["fontFamily", "fontSize", "color", "bold", "italic"
|
183
|
+
// "underline",
|
184
|
+
// "strikethrough",
|
185
|
+
];
|
186
|
+
|
187
|
+
const themeElements = ["headingOne", "headingTwo", "headingThree", "headingFour", "headingFive", "headingSix", "paragraphOne", "paragraphTwo", "paragraphThree"];
|
188
|
+
export const isTextCustomized = editor => {
|
189
|
+
try {
|
190
|
+
if (editor.selection) {
|
191
|
+
const currentElement = Node.parent(editor, editor?.selection?.anchor?.path);
|
192
|
+
if (!currentElement) {
|
193
|
+
return false;
|
194
|
+
}
|
195
|
+
const {
|
196
|
+
children,
|
197
|
+
type
|
198
|
+
} = currentElement;
|
199
|
+
if (!themeElements.includes(type)) {
|
200
|
+
return false;
|
201
|
+
}
|
202
|
+
if (children?.length > 1) {
|
203
|
+
return true;
|
204
|
+
}
|
205
|
+
const customized = textThemeFields.some(field => {
|
206
|
+
const element = children[0] || {};
|
207
|
+
const value = element[field];
|
208
|
+
if (field === "fontSize") {
|
209
|
+
return Object.keys(value || {}).length;
|
210
|
+
} else {
|
211
|
+
return value;
|
212
|
+
}
|
213
|
+
});
|
214
|
+
return customized;
|
215
|
+
} else {
|
216
|
+
return null;
|
217
|
+
}
|
218
|
+
} catch (err) {
|
219
|
+
return null;
|
220
|
+
}
|
221
|
+
};
|
222
|
+
const addToTheme = (field, value, element) => {
|
223
|
+
switch (field) {
|
224
|
+
case "fontFamily":
|
225
|
+
return {
|
226
|
+
fontFamily: value
|
227
|
+
};
|
228
|
+
case "fontSize":
|
229
|
+
return {
|
230
|
+
fontSize: value?.lg
|
231
|
+
};
|
232
|
+
case "color":
|
233
|
+
return {
|
234
|
+
color: value
|
235
|
+
};
|
236
|
+
case "bold":
|
237
|
+
return {
|
238
|
+
fontWeight: "bold"
|
239
|
+
};
|
240
|
+
case "italic":
|
241
|
+
return {
|
242
|
+
fontStyle: "italic"
|
243
|
+
};
|
244
|
+
// case "underline":
|
245
|
+
// case "strikethrough":
|
246
|
+
// let textDecoration = "";
|
247
|
+
|
248
|
+
// if (element.underline) {
|
249
|
+
// textDecoration = "underline";
|
250
|
+
// }
|
251
|
+
|
252
|
+
// if (element.strikethrough) {
|
253
|
+
// textDecoration += " strikethrough";
|
254
|
+
// }
|
255
|
+
|
256
|
+
// return { textDecoration };
|
257
|
+
default:
|
258
|
+
return {};
|
259
|
+
}
|
260
|
+
};
|
261
|
+
const MAP_TEXT_THEME_FIELD = {
|
262
|
+
headingOne: "h1",
|
263
|
+
headingTwo: "h2",
|
264
|
+
headingThree: "h3",
|
265
|
+
headingFour: "h4",
|
266
|
+
headingFive: "h5",
|
267
|
+
headingSix: "h6",
|
268
|
+
paragraphOne: "para1",
|
269
|
+
paragraphTwo: "para2",
|
270
|
+
paragraphThree: "para3"
|
271
|
+
};
|
272
|
+
export const saveToTheme = editor => {
|
273
|
+
try {
|
274
|
+
if (editor.selection) {
|
275
|
+
const currentElement = Node.parent(editor, editor?.selection?.anchor?.path);
|
276
|
+
if (!currentElement) {
|
277
|
+
return false;
|
278
|
+
}
|
279
|
+
const {
|
280
|
+
children
|
281
|
+
} = currentElement;
|
282
|
+
if (children?.length > 1) {
|
283
|
+
return true;
|
284
|
+
}
|
285
|
+
let theme = {};
|
286
|
+
textThemeFields.forEach(field => {
|
287
|
+
const element = children[0] || {};
|
288
|
+
const value = element[field];
|
289
|
+
let style = {};
|
290
|
+
let isValueExist = false;
|
291
|
+
if (value) {
|
292
|
+
isValueExist = true;
|
293
|
+
if (field === "fontSize") {
|
294
|
+
isValueExist = !!Object.keys(value).length;
|
295
|
+
}
|
296
|
+
}
|
297
|
+
if (isValueExist) {
|
298
|
+
style = addToTheme(field, value, element);
|
299
|
+
}
|
300
|
+
theme = {
|
301
|
+
...theme,
|
302
|
+
...style
|
303
|
+
};
|
304
|
+
});
|
305
|
+
textThemeFields.forEach(field => {
|
306
|
+
Editor.removeMark(editor, field);
|
307
|
+
});
|
308
|
+
return {
|
309
|
+
field: MAP_TEXT_THEME_FIELD[currentElement?.type],
|
310
|
+
theme
|
311
|
+
};
|
312
|
+
}
|
313
|
+
} catch (err) {
|
314
|
+
return;
|
315
|
+
}
|
316
|
+
};
|
317
|
+
export const HEADING_THEME_FIELDS = ["h1", "h2", "h3", "h4", "h5", "h6"];
|
318
|
+
export const PARAGRAPH_THEME_FIELDS = ["para1", "para2", "para3"];
|
121
319
|
export const getBRValue = (props, rbr = "lg") => {
|
122
320
|
const {
|
123
321
|
value,
|
@@ -161,4 +359,27 @@ export const groupByBreakpoint = (styleProps, theme) => {
|
|
161
359
|
}
|
162
360
|
};
|
163
361
|
};
|
164
|
-
export const getCustomizationValue = value => isNaN(parseInt(value)) ? null : parseInt(value);
|
362
|
+
export const getCustomizationValue = value => isNaN(parseInt(value)) ? null : parseInt(value);
|
363
|
+
export const getBreakpointLineSpacing = (value, breakpoint) => {
|
364
|
+
try {
|
365
|
+
const values = getBreakPointsValue(value, breakpoint);
|
366
|
+
const cssVal = BREAKPOINTS_DEVICES.reduce((a, b) => {
|
367
|
+
if (values[b] || values["lg"]) {
|
368
|
+
const value = values[b] || values["lg"];
|
369
|
+
return {
|
370
|
+
...a,
|
371
|
+
[b]: value
|
372
|
+
};
|
373
|
+
} else {
|
374
|
+
return a;
|
375
|
+
}
|
376
|
+
}, {});
|
377
|
+
if (breakpoint) {
|
378
|
+
return value[breakpoint] || value["lg"] || value;
|
379
|
+
} else {
|
380
|
+
return cssVal["lg"];
|
381
|
+
}
|
382
|
+
} catch (err) {
|
383
|
+
// console.log(err);
|
384
|
+
}
|
385
|
+
};
|
@@ -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
|
+
};
|