@flozy/editor 10.3.1 → 10.3.3
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 +17 -16
- package/dist/Editor/CommonEditor.js +131 -16
- package/dist/Editor/DialogWrapper.js +31 -25
- package/dist/Editor/Editor.css +46 -8
- package/dist/Editor/Elements/AI/PopoverAIInput.js +11 -3
- package/dist/Editor/Elements/Accordion/Accordion.js +30 -7
- package/dist/Editor/Elements/Accordion/AccordionSummary.js +1 -23
- package/dist/Editor/Elements/AppHeader/AppHeader.js +10 -5
- package/dist/Editor/Elements/Button/EditorButton.js +27 -9
- package/dist/Editor/Elements/Carousel/CarouselItem.js +2 -1
- package/dist/Editor/Elements/Color Picker/ColorButtons.js +61 -14
- package/dist/Editor/Elements/Color Picker/ColorPicker.css +25 -1
- package/dist/Editor/Elements/Color Picker/ColorPicker.js +10 -7
- package/dist/Editor/Elements/Color Picker/Styles.js +15 -13
- package/dist/Editor/Elements/DataView/Layouts/ColumnView.js +4 -2
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/MultiSelect.js +30 -28
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/MultiSelectType.js +9 -7
- package/dist/Editor/Elements/DataView/Layouts/Options/AddOptions.js +0 -1
- package/dist/Editor/Elements/DataView/Layouts/ViewData.js +8 -4
- package/dist/Editor/Elements/Embed/Video.js +1 -1
- package/dist/Editor/Elements/Form/Form.js +1 -3
- package/dist/Editor/Elements/Form/FormElements/FormTextArea.js +0 -1
- package/dist/Editor/Elements/Form/FormField.js +3 -2
- package/dist/Editor/Elements/Form/Workflow/Styles.js +24 -22
- package/dist/Editor/Elements/FreeGrid/FreeGrid.js +35 -31
- package/dist/Editor/Elements/FreeGrid/FreeGridBox.js +7 -4
- package/dist/Editor/Elements/FreeGrid/Options/More.js +7 -7
- package/dist/Editor/Elements/FreeGrid/helper.js +113 -0
- package/dist/Editor/Elements/FreeGrid/styles.js +14 -0
- package/dist/Editor/Elements/Grid/Grid.js +14 -2
- package/dist/Editor/Elements/Grid/GridItem.js +1 -1
- package/dist/Editor/Elements/Signature/Signature.css +2 -1
- package/dist/Editor/Elements/Signature/SignatureOptions/DrawSignature.js +18 -5
- package/dist/Editor/Elements/Signature/SignatureOptions/UploadSignature.js +16 -3
- package/dist/Editor/Elements/SimpleText/style.js +2 -2
- package/dist/Editor/Elements/Table/DragButton.js +0 -1
- package/dist/Editor/Elements/Table/Draggable.js +6 -2
- package/dist/Editor/Elements/Table/Styles.js +7 -0
- package/dist/Editor/Elements/Table/Table.js +3 -3
- package/dist/Editor/Elements/Table/TableCell.js +24 -5
- package/dist/Editor/Elements/Title/title.js +6 -6
- package/dist/Editor/Elements/Variables/VariableButton.js +10 -1
- package/dist/Editor/MiniEditor.js +2 -1
- package/dist/Editor/Styles/EditorStyles.js +5 -5
- 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 +10 -13
- package/dist/Editor/Toolbar/Mini/MiniToolbar.js +2 -1
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/MiniColorPicker.js +4 -2
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectFontSize.js +6 -13
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/SelectTypography.js +167 -42
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +7 -4
- package/dist/Editor/Toolbar/PopupTool/PopperHeader.js +2 -1
- package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +72 -12
- package/dist/Editor/Toolbar/PopupTool/TextFormat.js +58 -10
- package/dist/Editor/Toolbar/PopupTool/ThemeTextFormat.js +439 -0
- package/dist/Editor/Toolbar/PopupTool/index.js +1 -1
- package/dist/Editor/Toolbar/toolbarGroups.js +48 -6
- package/dist/Editor/assets/svg/BackIcon.js +18 -0
- package/dist/Editor/assets/svg/ThemeIcons.js +293 -0
- package/dist/Editor/common/Checkbox/index.js +46 -0
- package/dist/Editor/common/Checkbox/styles.js +45 -0
- package/dist/Editor/common/ColorPickerButton.js +41 -16
- package/dist/Editor/common/CustomColorPicker/index.js +130 -0
- package/dist/Editor/common/CustomColorPicker/style.js +53 -0
- package/dist/Editor/common/CustomDialog2/index.js +94 -0
- package/dist/Editor/common/CustomDialog2/style.js +67 -0
- package/dist/Editor/common/CustomSelect.js +43 -0
- package/dist/Editor/common/DnD/DragHandleButton.js +1 -1
- package/dist/Editor/common/FontLoader/FontLoader.js +3 -0
- package/dist/Editor/common/Icon.js +28 -0
- package/dist/Editor/common/ImageSelector/ImageSelector.js +2 -2
- package/dist/Editor/common/ImageSelector/Styles.js +3 -9
- package/dist/Editor/common/LinkSettings/NavComponents.js +45 -65
- package/dist/Editor/common/LinkSettings/index.js +13 -26
- package/dist/Editor/common/LinkSettings/navOptions.js +2 -2
- package/dist/Editor/common/LinkSettings/style.js +164 -244
- package/dist/Editor/common/RadioGroup/index.js +48 -0
- package/dist/Editor/common/RadioGroup/styles.js +29 -0
- package/dist/Editor/common/RnD/ElementOptions/Actions.js +4 -5
- package/dist/Editor/common/RnD/ElementSettings/OtherSettings/Settings.js +2 -1
- package/dist/Editor/common/RnD/ElementSettings/OtherSettings/Signature.js +4 -3
- 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/TextSettings.js +3 -1
- package/dist/Editor/common/RnD/ElementSettings/Settings/VideoSettings.js +3 -2
- package/dist/Editor/common/RnD/ElementSettings/styles.js +0 -1
- package/dist/Editor/common/RnD/OptionsPopup/style.js +0 -1
- package/dist/Editor/common/RnD/SwitchViewport/SwitchViewport.js +11 -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 +28 -19
- package/dist/Editor/common/RnD/Utils/index.js +3 -1
- package/dist/Editor/common/RnD/VirtualElement/VirtualTextElement.js +42 -58
- package/dist/Editor/common/RnD/VirtualElement/helper.js +321 -131
- package/dist/Editor/common/RnD/VirtualElement/styles.js +16 -0
- package/dist/Editor/common/RnD/index.js +25 -11
- package/dist/Editor/common/Select/index.js +44 -7
- package/dist/Editor/common/Select/styles.js +30 -2
- package/dist/Editor/common/Shorthands/elements.js +54 -0
- package/dist/Editor/common/StyleBuilder/accordionTitleBtnStyle.js +2 -2
- package/dist/Editor/common/StyleBuilder/accordionTitleStyle.js +12 -9
- package/dist/Editor/common/StyleBuilder/buttonStyle.js +4 -2
- package/dist/Editor/common/StyleBuilder/embedVideoStyle.js +4 -0
- 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 +16 -8
- package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +36 -10
- package/dist/Editor/common/StyleBuilder/fieldTypes/embedUpload.js +115 -0
- package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +16 -7
- package/dist/Editor/common/StyleBuilder/fieldTypes/index.js +3 -1
- package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +15 -7
- package/dist/Editor/common/SwipeableDrawer/style.js +14 -12
- package/dist/Editor/common/Uploader.js +16 -0
- package/dist/Editor/common/iconListV2.js +76 -0
- package/dist/Editor/common/iconslist.js +21 -0
- package/dist/Editor/commonStyle.js +116 -61
- package/dist/Editor/helper/index.js +4 -0
- package/dist/Editor/helper/textIndeces.js +58 -0
- package/dist/Editor/helper/theme.js +203 -2
- package/dist/Editor/hooks/useEditorTheme.js +153 -0
- package/dist/Editor/hooks/useMouseMove.js +9 -3
- package/dist/Editor/hooks/useTable.js +5 -4
- package/dist/Editor/hooks/useThemeValues.js +63 -0
- package/dist/Editor/plugins/withEmbeds.js +1 -1
- package/dist/Editor/plugins/withHTML.js +3 -1
- package/dist/Editor/plugins/withTable.js +1 -1
- package/dist/Editor/theme/ThemeList.js +50 -173
- package/dist/Editor/theme/index.js +149 -0
- package/dist/Editor/themeSettings/ActiveTheme.js +82 -0
- package/dist/Editor/themeSettings/buttons/index.js +300 -0
- package/dist/Editor/themeSettings/buttons/style.js +23 -0
- package/dist/Editor/themeSettings/colorTheme/index.js +310 -0
- package/dist/Editor/themeSettings/colorTheme/style.js +81 -0
- package/dist/Editor/themeSettings/fonts/PreviewElement.js +121 -0
- package/dist/Editor/themeSettings/fonts/index.js +240 -0
- package/dist/Editor/themeSettings/fonts/style.js +62 -0
- package/dist/Editor/themeSettings/icons.js +60 -0
- package/dist/Editor/themeSettings/index.js +380 -0
- package/dist/Editor/themeSettings/style.js +299 -0
- package/dist/Editor/themeSettingsAI/icons.js +96 -0
- package/dist/Editor/themeSettingsAI/index.js +355 -0
- package/dist/Editor/themeSettingsAI/saveTheme.js +202 -0
- package/dist/Editor/themeSettingsAI/style.js +332 -0
- package/dist/Editor/utils/SlateUtilityFunctions.js +161 -37
- package/dist/Editor/utils/accordion.js +14 -4
- package/dist/Editor/utils/button.js +1 -17
- package/dist/Editor/utils/customHooks/useTableResize.js +49 -9
- package/dist/Editor/utils/draftToSlate.js +3 -2
- package/dist/Editor/utils/events.js +50 -6
- package/dist/Editor/utils/font.js +40 -37
- package/dist/Editor/utils/helper.js +197 -30
- package/dist/Editor/utils/insertAppHeader.js +1 -1
- package/dist/Editor/utils/signature.js +2 -9
- package/dist/Editor/utils/updateFormName.js +22 -0
- package/package.json +4 -4
@@ -2,6 +2,8 @@ import { Editor, Node, Transforms, Element, Path, Range, Text } from "slate";
|
|
2
2
|
import { ReactEditor } from "slate-react";
|
3
3
|
import insertNewLine from "./insertNewLine";
|
4
4
|
import { getDevice } from "../helper/theme";
|
5
|
+
import { activeMark, getSelectedElementStyle } from "./SlateUtilityFunctions";
|
6
|
+
import { getCurrentElementText } from "../plugins/withHTML";
|
5
7
|
export const windowVar = {};
|
6
8
|
let ST_TIMEOUT = null;
|
7
9
|
const BLOCKS = ["grid", "dataView"];
|
@@ -304,15 +306,20 @@ const getScrollElement = () => {
|
|
304
306
|
const scrollFrom = isSlateWrapperScroll ? slateWrapper : window;
|
305
307
|
return scrollFrom;
|
306
308
|
};
|
307
|
-
const handleLinkBtnClick = (e, props, isMobilePreview) => {
|
309
|
+
const handleLinkBtnClick = (e, props, isMobilePreview, metadata) => {
|
308
310
|
if (e) {
|
309
311
|
e.preventDefault();
|
310
312
|
e.stopPropagation();
|
311
313
|
}
|
314
|
+
const mobileAppRedirect = metadata?.buttonLink?.inAppRedirection;
|
312
315
|
if (props.target) {
|
313
316
|
window.open(props.href);
|
314
317
|
} else {
|
315
|
-
|
318
|
+
if (typeof mobileAppRedirect === "function") {
|
319
|
+
mobileAppRedirect(props.href);
|
320
|
+
} else {
|
321
|
+
window.location.href = props.href;
|
322
|
+
}
|
316
323
|
if (isMobilePreview) {
|
317
324
|
// on iframe - mobile preview, window.location.href is not scrolling to the element correctly
|
318
325
|
const [, elementId] = props.href?.split("#");
|
@@ -328,7 +335,8 @@ const handleLinkBtnClick = (e, props, isMobilePreview) => {
|
|
328
335
|
}
|
329
336
|
}
|
330
337
|
};
|
331
|
-
export const handleLinkType = (url, linkType, readOnly, openInNewTab, onClick = () => {}
|
338
|
+
export const handleLinkType = (url, linkType, readOnly, openInNewTab, onClick = () => {}, metadata = {}, isEditMode, isCustomMobile // for drawer in App Header
|
339
|
+
) => {
|
332
340
|
const props = {};
|
333
341
|
if (!readOnly) {
|
334
342
|
return {
|
@@ -360,6 +368,9 @@ export const handleLinkType = (url, linkType, readOnly, openInNewTab, onClick =
|
|
360
368
|
case "page":
|
361
369
|
const [page = "", section] = url?.split("#") || [];
|
362
370
|
const sec = section ? `#${section}` : "";
|
371
|
+
if (isEditMode) {
|
372
|
+
break;
|
373
|
+
}
|
363
374
|
if (page === "_currentPage") {
|
364
375
|
props.component = "button";
|
365
376
|
props.onClick = () => {
|
@@ -380,11 +391,12 @@ export const handleLinkType = (url, linkType, readOnly, openInNewTab, onClick =
|
|
380
391
|
const currentUserPage = getCurrentUserPage();
|
381
392
|
props.href = isCurrentPage(page) ? `./${currentUserPage}${sec}` : `./${url}`;
|
382
393
|
if (openInNewTab) {
|
383
|
-
if (isCurrentPage(page)) {
|
384
|
-
|
385
|
-
} else {
|
386
|
-
|
387
|
-
}
|
394
|
+
// if (isCurrentPage(page)) {
|
395
|
+
// // temp fix, if user is presented in current page, open in new tab option is restricted, we will scroll to the element in current page
|
396
|
+
// } else {
|
397
|
+
// props.target = "_blank";
|
398
|
+
// }
|
399
|
+
props.target = "_blank";
|
388
400
|
}
|
389
401
|
}
|
390
402
|
break;
|
@@ -419,7 +431,7 @@ export const handleLinkType = (url, linkType, readOnly, openInNewTab, onClick =
|
|
419
431
|
|
420
432
|
// for iphone fix
|
421
433
|
if (props.component === "a" && props.href) {
|
422
|
-
const isMobile = getDevice(window.innerWidth) === "xs";
|
434
|
+
const isMobile = isCustomMobile || getDevice(window.innerWidth) === "xs";
|
423
435
|
if (isMobile) {
|
424
436
|
props.component = "button"; // iphone is opening two tabs, on open in new tab because of a tag.
|
425
437
|
}
|
@@ -427,13 +439,13 @@ export const handleLinkType = (url, linkType, readOnly, openInNewTab, onClick =
|
|
427
439
|
let touchEndClicked = false;
|
428
440
|
props.onTouchEnd = e => {
|
429
441
|
touchEndClicked = true;
|
430
|
-
handleLinkBtnClick(e, props);
|
442
|
+
handleLinkBtnClick(e, props, false, metadata);
|
431
443
|
};
|
432
444
|
props.onClick = e => {
|
433
445
|
// This condition is used for mobile preview in the page editor.
|
434
446
|
// 'touchEnd' will not work in the mobile page preview.
|
435
447
|
if (!touchEndClicked && isMobile) {
|
436
|
-
handleLinkBtnClick(e, props, true);
|
448
|
+
handleLinkBtnClick(e, props, true, metadata);
|
437
449
|
}
|
438
450
|
return false;
|
439
451
|
};
|
@@ -480,6 +492,34 @@ export const decodeString = str => {
|
|
480
492
|
console.log(err);
|
481
493
|
}
|
482
494
|
};
|
495
|
+
export const getContrastColor = color => {
|
496
|
+
let r, g, b;
|
497
|
+
|
498
|
+
// Check if the color is in hex format
|
499
|
+
if (color.startsWith("#")) {
|
500
|
+
r = parseInt(color.substring(1, 3), 16);
|
501
|
+
g = parseInt(color.substring(3, 5), 16);
|
502
|
+
b = parseInt(color.substring(5, 7), 16);
|
503
|
+
}
|
504
|
+
// Check if the color is in RGB/RGBA format
|
505
|
+
else if (color.startsWith("rgb")) {
|
506
|
+
const rgbValues = color.replace(/^rgba?\(|\s+|\)$/g, "") // Remove the rgb/rgba and spaces
|
507
|
+
.split(","); // Split the values into an array
|
508
|
+
|
509
|
+
r = parseInt(rgbValues[0]);
|
510
|
+
g = parseInt(rgbValues[1]);
|
511
|
+
b = parseInt(rgbValues[2]);
|
512
|
+
} else {
|
513
|
+
// If the format is not recognized, default to black text
|
514
|
+
return "#000000";
|
515
|
+
}
|
516
|
+
|
517
|
+
// Calculate relative luminance
|
518
|
+
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
519
|
+
|
520
|
+
// Return black for light colors, white for dark colors
|
521
|
+
return luminance > 0.5 ? "#000000" : "#FFFFFF";
|
522
|
+
};
|
483
523
|
export const onDeleteKey = (event, {
|
484
524
|
editor
|
485
525
|
}) => {
|
@@ -697,6 +737,10 @@ export const isRestrictedNode = (event, editor) => {
|
|
697
737
|
return isNodeRestricted;
|
698
738
|
}
|
699
739
|
};
|
740
|
+
export function capitalizeFirstLetter(str) {
|
741
|
+
if (!str) return str;
|
742
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
743
|
+
}
|
700
744
|
export const insertLineBreakAtEndOfPath = (editor, path) => {
|
701
745
|
try {
|
702
746
|
const [node, nodePath] = Editor.node(editor, path); // Get the node at the specified path
|
@@ -715,6 +759,13 @@ export const insertLineBreakAtEndOfPath = (editor, path) => {
|
|
715
759
|
console.log(err);
|
716
760
|
}
|
717
761
|
};
|
762
|
+
export function isHavingSelection(editor) {
|
763
|
+
try {
|
764
|
+
return editor?.selection && !Range.isCollapsed(editor.selection);
|
765
|
+
} catch (err) {
|
766
|
+
console.log(err);
|
767
|
+
}
|
768
|
+
}
|
718
769
|
const omitNodes = ["site-settings", "page-settings"];
|
719
770
|
export function getInitialValue(value = [], readOnly) {
|
720
771
|
if (readOnly === "readonly" && value?.length) {
|
@@ -745,20 +796,17 @@ export function getInitialValue(value = [], readOnly) {
|
|
745
796
|
}
|
746
797
|
return value;
|
747
798
|
}
|
748
|
-
export function capitalizeFirstLetter(str) {
|
749
|
-
if (!str) return str;
|
750
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
751
|
-
}
|
752
|
-
export function isHavingSelection(editor) {
|
753
|
-
try {
|
754
|
-
return editor?.selection && !Range.isCollapsed(editor.selection);
|
755
|
-
} catch (err) {
|
756
|
-
console.log(err);
|
757
|
-
}
|
758
|
-
}
|
759
799
|
export function getSelectedCls(defaultCls = "", selected, selectedClsName = "selected") {
|
760
800
|
return `${defaultCls} ${selected ? selectedClsName : ""}`;
|
761
801
|
}
|
802
|
+
export function handleNegativeInteger(val) {
|
803
|
+
return val < 0 ? 0 : val;
|
804
|
+
}
|
805
|
+
export const containsSurrogatePair = text => {
|
806
|
+
// Match surrogate pairs (high and low surrogate)
|
807
|
+
const surrogatePairRegex = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
|
808
|
+
return surrogatePairRegex.test(text);
|
809
|
+
};
|
762
810
|
export const getNodeWithType = (editor, nodeType = "", otherOptions) => {
|
763
811
|
try {
|
764
812
|
const options = {
|
@@ -772,11 +820,6 @@ export const getNodeWithType = (editor, nodeType = "", otherOptions) => {
|
|
772
820
|
return [];
|
773
821
|
}
|
774
822
|
};
|
775
|
-
export const containsSurrogatePair = text => {
|
776
|
-
// Match surrogate pairs (high and low surrogate)
|
777
|
-
const surrogatePairRegex = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
|
778
|
-
return surrogatePairRegex.test(text);
|
779
|
-
};
|
780
823
|
export const getSlateDom = (editor, range) => {
|
781
824
|
try {
|
782
825
|
const slateDom = ReactEditor.toDOMRange(editor, range);
|
@@ -826,9 +869,24 @@ export const hideSlateSelection = () => {
|
|
826
869
|
const root = document.documentElement;
|
827
870
|
root.style.setProperty("--slate-highlight-bg", "none");
|
828
871
|
};
|
829
|
-
export
|
830
|
-
|
831
|
-
|
872
|
+
export const insertSlashNode = (editor, insertNode) => {
|
873
|
+
try {
|
874
|
+
// Delete the currently selected text
|
875
|
+
editor.deleteFragment();
|
876
|
+
const currentText = getCurrentElementText(editor);
|
877
|
+
const currentPath = editor?.selection?.anchor?.path;
|
878
|
+
let insertAt = currentPath;
|
879
|
+
if (currentText?.trim()) {
|
880
|
+
const parentPath = Path.parent(currentPath);
|
881
|
+
insertAt = Path.next(parentPath);
|
882
|
+
}
|
883
|
+
Transforms.insertNodes(editor, insertNode, {
|
884
|
+
at: insertAt
|
885
|
+
});
|
886
|
+
} catch (err) {
|
887
|
+
console.log(err);
|
888
|
+
}
|
889
|
+
};
|
832
890
|
export const isEverythingSelected = editor => {
|
833
891
|
const {
|
834
892
|
selection
|
@@ -858,4 +916,113 @@ export const getCurrentNodeText = editor => {
|
|
858
916
|
} catch (error) {
|
859
917
|
console.log("Error:", error);
|
860
918
|
}
|
919
|
+
};
|
920
|
+
function convertColorToRgb(color) {
|
921
|
+
if (color?.startsWith("#")) {
|
922
|
+
// HEX to RGB
|
923
|
+
let hex = color.replace("#", "");
|
924
|
+
let r, g, b;
|
925
|
+
if (hex.length === 3) {
|
926
|
+
hex = hex.split("").map(x => x + x).join("");
|
927
|
+
}
|
928
|
+
if (hex.length === 6) {
|
929
|
+
[r, g, b] = [hex.substring(0, 2), hex.substring(2, 4), hex.substring(4, 6)].map(val => parseInt(val, 16));
|
930
|
+
return `rgb(${r}, ${g}, ${b})`;
|
931
|
+
}
|
932
|
+
} else {
|
933
|
+
return color;
|
934
|
+
}
|
935
|
+
}
|
936
|
+
export const getSelectedColor = (selectedColor, theme, hideThemeColors) => {
|
937
|
+
const colorVars = hideThemeColors ? null : theme?.vars?.colors;
|
938
|
+
let selectedValue = selectedColor;
|
939
|
+
if (colorVars) {
|
940
|
+
const convertedColor = convertColorToRgb(selectedColor);
|
941
|
+
Object.entries(theme.colors).forEach(([key, value]) => {
|
942
|
+
const convertedThemeColor = convertColorToRgb(value);
|
943
|
+
if (convertedThemeColor === convertedColor) {
|
944
|
+
selectedValue = colorVars[key];
|
945
|
+
}
|
946
|
+
});
|
947
|
+
}
|
948
|
+
return selectedValue;
|
949
|
+
};
|
950
|
+
const themeTextFormats = ["headingOne", "headingTwo", "headingThree", "headingFour", "headingFive", "headingSix", "paragraphOne", "paragraphTwo", "paragraphThree"];
|
951
|
+
export const getSelectedElementColor = (editor, format, theme) => {
|
952
|
+
const [isThemeText] = Editor.nodes(editor, {
|
953
|
+
at: editor.selection,
|
954
|
+
match: n => themeTextFormats.includes(n?.type)
|
955
|
+
});
|
956
|
+
if (!isThemeText) {
|
957
|
+
return activeMark(editor, "color") || "#000000";
|
958
|
+
}
|
959
|
+
const color = getSelectedElementStyle(format, editor, format);
|
960
|
+
return getSelectedColor(color, theme);
|
961
|
+
};
|
962
|
+
export const isHavingColor = color => {
|
963
|
+
if (!color) {
|
964
|
+
return false;
|
965
|
+
}
|
966
|
+
if (color.includes("rgba")) {
|
967
|
+
const match = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),?\s*(\d*\.?\d+)?\)/);
|
968
|
+
if (!match) return false; // Invalid format
|
969
|
+
|
970
|
+
const alpha = match[4] !== undefined ? parseFloat(match[4]) : 1; // Default alpha = 1
|
971
|
+
return alpha !== 0;
|
972
|
+
}
|
973
|
+
return true;
|
974
|
+
};
|
975
|
+
const getCopiedTextFormat = domRange => {
|
976
|
+
const contents = domRange.cloneContents();
|
977
|
+
const div = document.createElement("div");
|
978
|
+
div.appendChild(contents);
|
979
|
+
|
980
|
+
// Replace <br> with newlines
|
981
|
+
div.querySelectorAll("br").forEach(br => br.replaceWith("\n"));
|
982
|
+
const BLOCK_TAGS = ["DIV", "P", "LI", "H1", "H2", "H3", "H4", "H5", "H6"];
|
983
|
+
div.querySelectorAll(BLOCK_TAGS.join(",")).forEach(el => {
|
984
|
+
el.insertAdjacentText("beforeend", "\n");
|
985
|
+
});
|
986
|
+
let text = div.textContent || "";
|
987
|
+
text = text
|
988
|
+
// Remove spaces or tabs that appear just before a newline
|
989
|
+
// e.g., "text \n" → "text\n"
|
990
|
+
.replace(/[ \t]+\n/g, "\n")
|
991
|
+
|
992
|
+
// Collapse multiple consecutive newlines into a single newline
|
993
|
+
// e.g., "\n\n\n" → "\n"
|
994
|
+
.replace(/\n{2,}/g, "\n")
|
995
|
+
|
996
|
+
// Remove leading and trailing whitespace from the final text
|
997
|
+
.trim();
|
998
|
+
return text;
|
999
|
+
};
|
1000
|
+
const getCopiedHTMLFormat = domRange => {
|
1001
|
+
const htmlContents = domRange.cloneContents();
|
1002
|
+
const container = document.createElement("div");
|
1003
|
+
container.appendChild(htmlContents);
|
1004
|
+
const html = container.innerHTML;
|
1005
|
+
return html;
|
1006
|
+
};
|
1007
|
+
const getCopiedSlateFormat = editor => {
|
1008
|
+
// Get Slate fragment
|
1009
|
+
const fragment = JSON.stringify(Editor.fragment(editor, editor.selection));
|
1010
|
+
const encodedFragment = window.btoa(decodeURIComponent(encodeURIComponent(fragment)));
|
1011
|
+
return encodedFragment;
|
1012
|
+
};
|
1013
|
+
export const handleCopy = (event, editor) => {
|
1014
|
+
const {
|
1015
|
+
selection
|
1016
|
+
} = editor;
|
1017
|
+
if (!selection || Range.isCollapsed(selection)) return;
|
1018
|
+
event.preventDefault();
|
1019
|
+
const domRange = ReactEditor.toDOMRange(editor, selection);
|
1020
|
+
const text = getCopiedTextFormat(domRange);
|
1021
|
+
const html = getCopiedHTMLFormat(domRange);
|
1022
|
+
const encodedFragment = getCopiedSlateFormat(editor);
|
1023
|
+
|
1024
|
+
// Set all formats manually
|
1025
|
+
event.clipboardData?.setData("text/html", html);
|
1026
|
+
event.clipboardData?.setData("text/plain", text);
|
1027
|
+
event.clipboardData?.setData("application/x-slate-fragment", encodedFragment);
|
861
1028
|
};
|
@@ -1,9 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
import insertNewLine from "./insertNewLine";
|
3
|
-
import { getCurrentElementText } from "../plugins/withHTML";
|
1
|
+
import { insertSlashNode } from "./helper";
|
4
2
|
export const insertSignature = editor => {
|
5
|
-
const hasText = getCurrentElementText(editor);
|
6
|
-
const insertPath = hasText ? Path.next(Path.parent(editor?.selection.focus.path)) : editor.selection.anchor.path;
|
7
3
|
const signature = {
|
8
4
|
type: "signature",
|
9
5
|
alignment: "center",
|
@@ -17,8 +13,5 @@ export const insertSignature = editor => {
|
|
17
13
|
text: " "
|
18
14
|
}]
|
19
15
|
};
|
20
|
-
|
21
|
-
at: insertPath
|
22
|
-
});
|
23
|
-
insertNewLine(editor);
|
16
|
+
insertSlashNode(editor, signature);
|
24
17
|
};
|
@@ -0,0 +1,22 @@
|
|
1
|
+
const updateFormName = node => {
|
2
|
+
try {
|
3
|
+
if (!node || typeof node !== "object") return node;
|
4
|
+
let updatedNode = {
|
5
|
+
...node
|
6
|
+
};
|
7
|
+
if (updatedNode.type === "form") {
|
8
|
+
const timeStamp = Date.now();
|
9
|
+
const newFormName = `form_${timeStamp}`;
|
10
|
+
updatedNode.formName = newFormName;
|
11
|
+
updatedNode.uid = newFormName;
|
12
|
+
}
|
13
|
+
if (Array.isArray(updatedNode.children)) {
|
14
|
+
updatedNode.children = updatedNode.children.map(child => updateFormName(child));
|
15
|
+
}
|
16
|
+
return updatedNode;
|
17
|
+
} catch (err) {
|
18
|
+
console.warn("Error inside updateFormName", err);
|
19
|
+
return node;
|
20
|
+
}
|
21
|
+
};
|
22
|
+
export default updateFormName;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@flozy/editor",
|
3
|
-
"version": "10.3.
|
3
|
+
"version": "10.3.3",
|
4
4
|
"description": "An Editor for flozy app brain",
|
5
5
|
"files": [
|
6
6
|
"dist"
|
@@ -38,7 +38,6 @@
|
|
38
38
|
"react-icons": "^4.10.1",
|
39
39
|
"react-katex": "^3.0.1",
|
40
40
|
"react-rnd": "^10.4.11",
|
41
|
-
"react-scripts": "5.0.1",
|
42
41
|
"react-signature-canvas": "^1.0.6",
|
43
42
|
"react-slick": "^0.29.0",
|
44
43
|
"sanitize-html": "^2.13.0",
|
@@ -69,7 +68,7 @@
|
|
69
68
|
"storybook": "storybook dev -p 6006",
|
70
69
|
"build-storybook": "NODE_OPTIONS='--max_old_space_size=4096' storybook build",
|
71
70
|
"publish:npm": "rm -rf dist && mkdir dist && babel src/components -d dist --copy-files",
|
72
|
-
"publish:local": "rm -rf /Users/
|
71
|
+
"publish:local": "rm -rf /Users/agenciflow08/Documents/flozyapp/client/node_modules/@flozy/editor/dist && babel src/components -d /Users/agenciflow08/Documents/flozyapp/client/node_modules/@flozy/editor/dist --copy-files",
|
73
72
|
"publish:flozy": "./publish-flozy.sh",
|
74
73
|
"publish:flozy2": "./publish-flozy2.sh",
|
75
74
|
"publish:permission": "chmod +x publish-flozy.sh && chmod +x publish-flozy2.sh"
|
@@ -122,7 +121,8 @@
|
|
122
121
|
"prop-types": "^15.8.1",
|
123
122
|
"source-map-explorer": "^2.5.3",
|
124
123
|
"storybook": "^7.4.0",
|
125
|
-
"webpack": "^5.88.2"
|
124
|
+
"webpack": "^5.88.2",
|
125
|
+
"react-scripts": "5.0.1"
|
126
126
|
},
|
127
127
|
"overrides": {
|
128
128
|
"react-refresh": "0.11.0"
|