@flozy/editor 5.5.8 → 5.6.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/Editor/ChatEditor.js +25 -34
- package/dist/Editor/CommonEditor.js +26 -13
- package/dist/Editor/Editor.css +106 -20
- package/dist/Editor/Elements/AI/AIInput.js +0 -1
- package/dist/Editor/Elements/AI/CustomSelect.js +17 -10
- package/dist/Editor/Elements/AI/PopoverAIInput.js +59 -53
- package/dist/Editor/Elements/AI/Styles.js +24 -6
- package/dist/Editor/Elements/Accordion/Accordion.js +8 -1
- package/dist/Editor/Elements/AppHeader/AppHeader.js +6 -6
- package/dist/Editor/Elements/Button/EditorButton.js +6 -1
- package/dist/Editor/Elements/Carousel/CarouselItem.js +11 -3
- package/dist/Editor/Elements/Color Picker/ColorButtons.js +7 -5
- package/dist/Editor/Elements/Color Picker/Styles.js +8 -3
- package/dist/Editor/Elements/Color Picker/defaultColors.js +2 -2
- package/dist/Editor/Elements/DataView/DataView.js +124 -0
- package/dist/Editor/Elements/DataView/DataViewButton.js +23 -0
- package/dist/Editor/Elements/DataView/Layouts/ColumnView.js +83 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/CheckType.js +33 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/Select.js +180 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/SimpleSelect.js +62 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/Components/styles.js +68 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/DateType.js +35 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/MultiSelectType.js +39 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/NumberType.js +30 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/PersonType.js +30 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/SelectType.js +35 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/TextType.js +36 -0
- package/dist/Editor/Elements/DataView/Layouts/DataTypes/index.js +17 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/ChooseField.js +29 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/ChooseSort.js +38 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterSort/SortOptions/index.js +86 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterSort/index.js +71 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterSort/styles.js +138 -0
- package/dist/Editor/Elements/DataView/Layouts/FilterView.js +213 -0
- package/dist/Editor/Elements/DataView/Layouts/Formula.js +29 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/AddOptions.js +113 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/AddProperty.js +44 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/AllProperties.js +146 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/ChangeProperty.js +79 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/ColumnsList.js +57 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/Constants.js +101 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/EditOption.js +174 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/EditProperty.js +241 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/FilterProperty.js +45 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/PropertyList.js +32 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/index.js +110 -0
- package/dist/Editor/Elements/DataView/Layouts/Options/styles.js +217 -0
- package/dist/Editor/Elements/DataView/Layouts/TableStyles.js +131 -0
- package/dist/Editor/Elements/DataView/Layouts/TableView.js +253 -0
- package/dist/Editor/Elements/DataView/Layouts/ViewData.js +85 -0
- package/dist/Editor/Elements/DataView/Layouts/colStyles.js +10 -0
- package/dist/Editor/Elements/DataView/Layouts/index.js +25 -0
- package/dist/Editor/Elements/DataView/Providers/DataViewProvider.js +277 -0
- package/dist/Editor/Elements/DataView/Utils/globalSearch.js +15 -0
- package/dist/Editor/Elements/DataView/Utils/multiSortRows.js +88 -0
- package/dist/Editor/Elements/DataView/styles.js +169 -0
- package/dist/Editor/Elements/Divider/Divider.js +36 -20
- package/dist/Editor/Elements/Embed/Image.js +51 -16
- package/dist/Editor/Elements/Embed/Video.js +26 -3
- package/dist/Editor/Elements/Form/Form.js +38 -2
- package/dist/Editor/Elements/Form/FormElements/FormCheckbox.js +7 -1
- package/dist/Editor/Elements/Form/FormElements/FormDate.js +7 -1
- package/dist/Editor/Elements/Form/FormElements/FormEmail.js +7 -1
- package/dist/Editor/Elements/Form/FormElements/FormNumbers.js +7 -1
- package/dist/Editor/Elements/Form/FormElements/FormRadioButton.js +7 -1
- package/dist/Editor/Elements/Form/FormElements/FormText.js +7 -1
- package/dist/Editor/Elements/Form/FormElements/FormTextArea.js +6 -1
- package/dist/Editor/Elements/Form/FormPopup.js +12 -9
- package/dist/Editor/Elements/Form/Workflow/Styles.js +2 -0
- package/dist/Editor/Elements/FreeGrid/FreeGrid.js +1 -1
- package/dist/Editor/Elements/FreeGrid/FreeGridBox.js +4 -2
- package/dist/Editor/Elements/FreeGrid/FreeGridItem.js +20 -1
- package/dist/Editor/Elements/FreeGrid/breakpointConstants.js +4 -4
- package/dist/Editor/Elements/FreeGrid/styles.js +1 -1
- package/dist/Editor/Elements/Grid/GridButton.js +2 -2
- package/dist/Editor/Elements/Grid/GridItem.js +47 -36
- package/dist/Editor/Elements/Grid/Styles.js +50 -0
- package/dist/Editor/Elements/Link/LinkButton.js +1 -1
- package/dist/Editor/Elements/Search/SearchButton.js +1 -0
- package/dist/Editor/Elements/Signature/Signature.css +1 -1
- package/dist/Editor/Elements/Signature/SignatureOptions/TypeSignature.js +2 -2
- package/dist/Editor/Elements/Signature/SignaturePopup.js +17 -52
- package/dist/Editor/Elements/SimpleText/index.js +3 -2
- package/dist/Editor/Elements/SimpleText/style.js +15 -0
- package/dist/Editor/Elements/Table/AddRowCol.js +77 -0
- package/dist/Editor/Elements/Table/DragButton.js +142 -0
- package/dist/Editor/Elements/Table/DragStyles.js +70 -0
- package/dist/Editor/Elements/Table/Draggable.js +25 -0
- package/dist/Editor/Elements/Table/Droppable.js +53 -0
- package/dist/Editor/Elements/Table/Styles.js +88 -78
- package/dist/Editor/Elements/Table/Table.js +263 -140
- package/dist/Editor/Elements/Table/TableCell.js +365 -111
- package/dist/Editor/Elements/Table/TablePopup.js +9 -3
- package/dist/Editor/Elements/Table/TableRow.js +10 -2
- package/dist/Editor/Elements/Table/TableTool.js +101 -0
- package/dist/Editor/Elements/Table/tableHelper.js +71 -0
- package/dist/Editor/Elements/TopBanner/TopBanner.js +2 -1
- package/dist/Editor/MiniEditor.js +21 -2
- package/dist/Editor/Styles/EditorStyles.js +13 -4
- package/dist/Editor/Toolbar/FormatTools/BlockButton.js +10 -0
- package/dist/Editor/Toolbar/FormatTools/Dropdown.js +7 -12
- package/dist/Editor/Toolbar/FormatTools/FontFamilyAutocomplete.js +26 -4
- package/dist/Editor/Toolbar/FormatTools/MarkButton.js +3 -0
- package/dist/Editor/Toolbar/FormatTools/TextSize.js +5 -5
- package/dist/Editor/Toolbar/Mini/MiniToolbar.js +8 -8
- package/dist/Editor/Toolbar/Mini/Styles.js +9 -1
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/InfinityAITool.js +7 -3
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +6 -4
- package/dist/Editor/Toolbar/PopupTool/PopperHeader.js +19 -15
- package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +547 -58
- package/dist/Editor/Toolbar/PopupTool/TextFormat.js +28 -16
- package/dist/Editor/Toolbar/PopupTool/index.js +3 -5
- package/dist/Editor/Toolbar/Toolbar.js +6 -0
- package/dist/Editor/Toolbar/toolbarGroups.js +4 -0
- package/dist/Editor/assets/svg/ArrowDownIcon.js +25 -0
- package/dist/Editor/assets/svg/ArrowUpIcon.js +25 -0
- package/dist/Editor/assets/svg/BrainIcon.js +2 -2
- package/dist/Editor/assets/svg/CalenderIconTick.js +64 -0
- package/dist/Editor/assets/svg/ChervDown.js +18 -0
- package/dist/Editor/assets/svg/ChervUp.js +18 -0
- package/dist/Editor/assets/svg/DataTableIcon.js +50 -0
- package/dist/Editor/assets/svg/DuplicateIcon.js +23 -0
- package/dist/Editor/assets/svg/EyeIcon.js +23 -0
- package/dist/Editor/assets/svg/EyeSlash.js +43 -0
- package/dist/Editor/assets/svg/HashtagIcon.js +33 -0
- package/dist/Editor/assets/svg/PlusIcon.js +23 -0
- package/dist/Editor/assets/svg/SelectRoundedIcon.js +24 -0
- package/dist/Editor/assets/svg/SettingsIcon.js +4 -4
- package/dist/Editor/assets/svg/SortByIcon.js +33 -0
- package/dist/Editor/assets/svg/TableIcons.js +220 -0
- package/dist/Editor/assets/svg/TickOutlined.js +23 -0
- package/dist/Editor/assets/svg/TrashCanIcon.js +38 -0
- package/dist/Editor/common/ColorPickerButton.js +85 -45
- package/dist/Editor/common/DnD/Draggable.js +2 -1
- package/dist/Editor/common/FontLoader/FontLoader.js +2 -2
- package/dist/Editor/common/Icon.js +54 -21
- package/dist/Editor/common/ImageSelector/Options/Upload.js +2 -1
- package/dist/Editor/common/ImageSelector/Styles.js +47 -6
- package/dist/Editor/common/ImageSelector/UploadStyles.js +18 -6
- package/dist/Editor/common/LinkSettings/NavComponents.js +2 -1
- package/dist/Editor/common/LinkSettings/index.js +2 -1
- package/dist/Editor/common/MentionsPopup/Styles.js +142 -8
- package/dist/Editor/common/MentionsPopup/index.js +1 -1
- package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +107 -12
- package/dist/Editor/common/RnD/GuideLines/styles.js +3 -3
- package/dist/Editor/common/RnD/ShadowElement.js +1 -1
- package/dist/Editor/common/RnD/VirtualElement/index.js +5 -1
- package/dist/Editor/common/RnD/index.js +4 -3
- package/dist/Editor/common/Section/index.js +3 -3
- package/dist/Editor/common/Section/styles.js +5 -1
- package/dist/Editor/common/Select/index.js +20 -0
- package/dist/Editor/common/Select/styles.js +17 -0
- package/dist/Editor/common/Shorthands/elements.js +13 -1
- package/dist/Editor/common/StyleBuilder/fieldStyle.js +2 -1
- package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +4 -3
- package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +35 -7
- package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +15 -2
- package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +2 -1
- package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +1 -1
- package/dist/Editor/common/StyleBuilder/fieldTypes/icons.js +2 -0
- package/dist/Editor/common/StyleBuilder/fieldTypes/radiusStyle.js +11 -11
- package/dist/Editor/common/StyleBuilder/fieldTypes/saveAsTemplate.js +22 -6
- package/dist/Editor/common/StyleBuilder/fieldTypes/selectBox.js +21 -2
- package/dist/Editor/common/StyleBuilder/fieldTypes/text.js +20 -4
- package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +12 -2
- package/dist/Editor/common/StyleBuilder/formStyle.js +268 -149
- package/dist/Editor/common/StyleBuilder/index.js +101 -20
- package/dist/Editor/common/StyleBuilder/tableStyle.js +69 -25
- package/dist/Editor/common/SwipeableDrawer/style.js +15 -4
- package/dist/Editor/common/ToolbarIcon.js +1 -1
- package/dist/Editor/common/Uploader.js +39 -37
- package/dist/Editor/common/iconListV2.js +598 -74
- package/dist/Editor/common/iconslist.js +25 -19
- package/dist/Editor/commonStyle.js +421 -15
- package/dist/Editor/helper/deserialize/index.js +31 -2
- package/dist/Editor/helper/enforceDateFormat.js +41 -0
- package/dist/Editor/helper/index.js +15 -2
- package/dist/Editor/helper/theme.js +15 -1
- package/dist/Editor/hooks/useBreakpoints.js +1 -1
- package/dist/Editor/hooks/useTable.js +210 -0
- package/dist/Editor/plugins/withCustomDeleteBackward.js +1 -1
- package/dist/Editor/plugins/withEmbeds.js +30 -26
- package/dist/Editor/plugins/withHTML.js +100 -12
- package/dist/Editor/plugins/withLayout.js +1 -0
- package/dist/Editor/utils/SlateUtilityFunctions.js +31 -11
- package/dist/Editor/utils/brains.js +1 -1
- package/dist/Editor/utils/chatEditor/SlateUtilityFunctions.js +75 -6
- package/dist/Editor/utils/customHooks/useResize.js +7 -4
- package/dist/Editor/utils/customHooks/useTableResize.js +6 -2
- package/dist/Editor/utils/dataView.js +43 -0
- package/dist/Editor/utils/embed.js +2 -1
- package/dist/Editor/utils/events.js +0 -1
- package/dist/Editor/utils/font.js +11 -4
- package/dist/Editor/utils/formfield.js +8 -4
- package/dist/Editor/utils/helper.js +100 -2
- package/dist/Editor/utils/insertNewLine.js +19 -1
- package/dist/Editor/utils/serializeToText.js +2 -0
- package/dist/Editor/utils/table.js +228 -24
- package/package.json +2 -2
@@ -1,4 +1,26 @@
|
|
1
1
|
import { jsx } from "slate-hyperscript";
|
2
|
+
const inlineStyles = [{
|
3
|
+
key: "bold",
|
4
|
+
getStyle: styles => styles.fontWeight === "bold" || parseInt(styles.fontWeight, 10) >= 700
|
5
|
+
}, {
|
6
|
+
key: "italic",
|
7
|
+
getStyle: styles => styles.fontStyle === "italic"
|
8
|
+
}, {
|
9
|
+
key: "underline",
|
10
|
+
getStyle: styles => styles.textDecoration.includes("underline")
|
11
|
+
}];
|
12
|
+
function getInlineTextStyles(element) {
|
13
|
+
if (!element || !element.style) return {};
|
14
|
+
const styles = element.style;
|
15
|
+
const elementStyles = inlineStyles.reduce((total, currVal) => {
|
16
|
+
const style = currVal.getStyle(styles);
|
17
|
+
if (style) {
|
18
|
+
total[currVal.key] = style;
|
19
|
+
}
|
20
|
+
return total;
|
21
|
+
}, {});
|
22
|
+
return elementStyles;
|
23
|
+
}
|
2
24
|
const handleTableCell = (el, children) => {
|
3
25
|
const wrapChild = children?.map(c => {
|
4
26
|
if (typeof c === "string") {
|
@@ -14,7 +36,10 @@ const handleTableCell = (el, children) => {
|
|
14
36
|
});
|
15
37
|
return {
|
16
38
|
type: "table-cell",
|
17
|
-
overwriteChild: wrapChild
|
39
|
+
overwriteChild: wrapChild,
|
40
|
+
size: {
|
41
|
+
width: 120
|
42
|
+
}
|
18
43
|
};
|
19
44
|
};
|
20
45
|
const INLINE_TAGS = ["A", "ABBR", "B", "BDO", "CITE", "CODE", "DATA", "DEL", "DFN", "IMG", "INS", "KBD", "LABEL", "MARK", "Q", "SAMP", "SMALL", "SPAN", "SUB", "SUP", "TIME", "VAR"];
|
@@ -135,9 +160,13 @@ const TEXT_TAGS = {
|
|
135
160
|
|
136
161
|
const deserialize = el => {
|
137
162
|
if (el.nodeType === 3) {
|
163
|
+
// if there is any line-breaks
|
138
164
|
const match = /\r|\n/.exec(el.textContent);
|
139
165
|
const text = el.textContent.replace(/\r|\n/g, "").trim();
|
140
|
-
return match && !text ? null :
|
166
|
+
return match && !text ? null : {
|
167
|
+
text,
|
168
|
+
...getInlineTextStyles(el.parentNode)
|
169
|
+
};
|
141
170
|
} else if (el.nodeType !== 1) {
|
142
171
|
return null;
|
143
172
|
} else if (el.nodeName === "BR") {
|
@@ -0,0 +1,41 @@
|
|
1
|
+
function enforceDateFormat(inputElement) {
|
2
|
+
inputElement.addEventListener("input", event => {
|
3
|
+
const input = event.target;
|
4
|
+
let value = input.value;
|
5
|
+
|
6
|
+
// Allow only numbers and forward slashes
|
7
|
+
value = value.replace(/[^\d/]/g, "");
|
8
|
+
|
9
|
+
// Enforce MM/DD/YYYY structure
|
10
|
+
if (value.length > 10) {
|
11
|
+
value = value.slice(0, 10);
|
12
|
+
}
|
13
|
+
const parts = value.split("/");
|
14
|
+
if (parts.length > 1) {
|
15
|
+
parts[0] = parts[0].slice(0, 2); // Limit MM to 2 digits
|
16
|
+
if (parts[0] > 12) parts[0] = "12"; // Max month value
|
17
|
+
}
|
18
|
+
|
19
|
+
if (parts.length > 2) {
|
20
|
+
parts[1] = parts[1].slice(0, 2); // Limit DD to 2 digits
|
21
|
+
if (parts[1] > 31) parts[1] = "31"; // Max day value
|
22
|
+
}
|
23
|
+
|
24
|
+
if (parts.length > 3) {
|
25
|
+
parts[2] = parts[2].slice(0, 4); // Limit YYYY to 4 digits
|
26
|
+
}
|
27
|
+
|
28
|
+
input.value = parts.join("/");
|
29
|
+
|
30
|
+
// Optionally, validate the full date
|
31
|
+
if (input.value.length === 10) {
|
32
|
+
const [month, day, year] = input.value.split("/").map(Number);
|
33
|
+
const isValidDate = !isNaN(Date.parse(`${year}-${month}-${day}`));
|
34
|
+
if (!isValidDate) {
|
35
|
+
input.value = ""; // Clear input if invalid
|
36
|
+
alert("Invalid date format. Please enter a valid MM/DD/YYYY date.");
|
37
|
+
}
|
38
|
+
}
|
39
|
+
});
|
40
|
+
}
|
41
|
+
export default enforceDateFormat;
|
@@ -308,7 +308,13 @@ export const getTextColor = (color = "") => {
|
|
308
308
|
color: "transparent !important",
|
309
309
|
caretColor: "black",
|
310
310
|
"& span": {
|
311
|
-
color: "transparent !important"
|
311
|
+
color: "transparent !important",
|
312
|
+
"& ::selection": {
|
313
|
+
color: "#000 !important"
|
314
|
+
}
|
315
|
+
},
|
316
|
+
"& ::selection": {
|
317
|
+
color: "#000 !important"
|
312
318
|
}
|
313
319
|
} : {
|
314
320
|
color
|
@@ -352,7 +358,7 @@ export const clearBrainText = editor => {
|
|
352
358
|
} = editor;
|
353
359
|
if (selection) {
|
354
360
|
const [currentNode, currentPath] = Editor.node(editor, selection);
|
355
|
-
const cleanedText = Node.string(currentNode).replace(/\/b(?:rain|rai|ra|r)?/g, "").trim();
|
361
|
+
const cleanedText = Node.string(currentNode).replace(/\/(?:b(?:rain|rai|ra|r)?)?/g, "").trim();
|
356
362
|
Transforms.insertText(editor, cleanedText, {
|
357
363
|
at: currentPath
|
358
364
|
});
|
@@ -360,4 +366,11 @@ export const clearBrainText = editor => {
|
|
360
366
|
} catch (err) {
|
361
367
|
console.log(err);
|
362
368
|
}
|
369
|
+
};
|
370
|
+
export const clearSelectionOnly = editor => {
|
371
|
+
try {
|
372
|
+
Transforms.deselect(editor);
|
373
|
+
} catch (err) {
|
374
|
+
console.log(err);
|
375
|
+
}
|
363
376
|
};
|
@@ -54,6 +54,20 @@ const overrides = {
|
|
54
54
|
return `${val?.topLeft}px ${val?.topRight}px ${val?.bottomLeft}px ${val?.bottomRight}px`;
|
55
55
|
}
|
56
56
|
};
|
57
|
+
export const checkXS = (val = {}) => {
|
58
|
+
try {
|
59
|
+
if (typeof val === "object") {
|
60
|
+
if (val?.xs === undefined && val?.lg !== undefined) {
|
61
|
+
val.xs = val.lg;
|
62
|
+
}
|
63
|
+
return val;
|
64
|
+
}
|
65
|
+
return val;
|
66
|
+
} catch (err) {
|
67
|
+
console.log(err);
|
68
|
+
return val;
|
69
|
+
}
|
70
|
+
};
|
57
71
|
export const getBreakPointsValue = (value, breakpoint, ot = null, ov = false) => {
|
58
72
|
try {
|
59
73
|
if (breakpoint) {
|
@@ -67,7 +81,7 @@ export const getBreakPointsValue = (value, breakpoint, ot = null, ov = false) =>
|
|
67
81
|
return value ? value[breakpoint] || value["lg"] : value;
|
68
82
|
}
|
69
83
|
} else if (typeof value === "object") {
|
70
|
-
return !breakpoint && value["lg"] ? !ov ? value : overrideValues(value, ot) : value[breakpoint] || copyAllLg(value, ot);
|
84
|
+
return !breakpoint && value["lg"] ? !ov ? value : checkXS(overrideValues(value, ot)) : value[breakpoint] || copyAllLg(value, ot);
|
71
85
|
} else {
|
72
86
|
// consider without breakpoints
|
73
87
|
return copyAllLg(value, ot);
|
@@ -0,0 +1,210 @@
|
|
1
|
+
import { ClickAwayListener } from "@mui/material";
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
3
|
+
import { clearCellText } from "../utils/table";
|
4
|
+
import { Editor, Element, Transforms } from "slate";
|
5
|
+
import { DndContext, DragOverlay, PointerSensor, useSensor, useSensors } from "@dnd-kit/core";
|
6
|
+
import { encodeToBase64, isHavingSelection } from "../utils/helper";
|
7
|
+
import { serializeToText } from "../utils/serializeToText";
|
8
|
+
import { createCopiedTableStructure, getRectangleBounds, tableNodeToDom } from "../Elements/Table/tableHelper";
|
9
|
+
|
10
|
+
// const selectFirstCell = (tablePath, editor, updateTableSelection) => {
|
11
|
+
// const firstCell = [...tablePath, 0, 0];
|
12
|
+
|
13
|
+
// const end = Editor.end(editor, firstCell);
|
14
|
+
|
15
|
+
// Transforms.select(editor, {
|
16
|
+
// anchor: end,
|
17
|
+
// focus: end,
|
18
|
+
// });
|
19
|
+
|
20
|
+
// updateTableSelection({
|
21
|
+
// startCellPath: firstCell,
|
22
|
+
// endCellPath: [],
|
23
|
+
// isDragging: false,
|
24
|
+
// });
|
25
|
+
// };
|
26
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
27
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
28
|
+
const handleDragEnd = (dragData, editor, resetAll) => {
|
29
|
+
const {
|
30
|
+
active,
|
31
|
+
over
|
32
|
+
} = dragData;
|
33
|
+
if (over) {
|
34
|
+
const {
|
35
|
+
dragType,
|
36
|
+
path: startCellPath
|
37
|
+
} = active?.data?.current || {};
|
38
|
+
const {
|
39
|
+
path: overCellPath
|
40
|
+
} = over?.data?.current || {};
|
41
|
+
if (startCellPath?.length) {
|
42
|
+
if (dragType === "row") {
|
43
|
+
const startRowPath = startCellPath.slice(0, -1);
|
44
|
+
const overRowPath = overCellPath.slice(0, -1);
|
45
|
+
Transforms.moveNodes(editor, {
|
46
|
+
at: startRowPath,
|
47
|
+
to: overRowPath
|
48
|
+
});
|
49
|
+
} else {
|
50
|
+
const [startCol] = startCellPath.slice(-1);
|
51
|
+
const [overCol] = overCellPath.slice(-1);
|
52
|
+
const [tableData] = Editor.nodes(editor, {
|
53
|
+
at: startCellPath,
|
54
|
+
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
55
|
+
});
|
56
|
+
const [tableNode, tablePath] = tableData;
|
57
|
+
const rows = tableNode?.rows || 0;
|
58
|
+
for (let row = 0; row < rows; row++) {
|
59
|
+
const startColPath = [...tablePath, row, startCol];
|
60
|
+
const overColPath = [...tablePath, row, overCol];
|
61
|
+
Transforms.moveNodes(editor, {
|
62
|
+
at: startColPath,
|
63
|
+
to: overColPath
|
64
|
+
});
|
65
|
+
}
|
66
|
+
}
|
67
|
+
resetAll();
|
68
|
+
}
|
69
|
+
}
|
70
|
+
};
|
71
|
+
const TableContext = /*#__PURE__*/createContext();
|
72
|
+
export function getDefaultTableSelection() {
|
73
|
+
return {
|
74
|
+
startCellPath: [],
|
75
|
+
endCellPath: [],
|
76
|
+
isDragging: false
|
77
|
+
};
|
78
|
+
}
|
79
|
+
export const TableProvider = ({
|
80
|
+
editor,
|
81
|
+
children,
|
82
|
+
otherProps = {}
|
83
|
+
}) => {
|
84
|
+
const [hoverPath, setHoverPath] = useState(null);
|
85
|
+
const [tableSelection, setTableSelection] = useState(getDefaultTableSelection());
|
86
|
+
const [tableResizing, setTableResizing] = useState(null);
|
87
|
+
|
88
|
+
// for the button events (like onclick,...etc) inside draggable component to work correctly
|
89
|
+
const sensors = useSensors(useSensor(PointerSensor, {
|
90
|
+
activationConstraint: {
|
91
|
+
delay: 250,
|
92
|
+
distance: 0 // throws exceeded distance error
|
93
|
+
}
|
94
|
+
}));
|
95
|
+
|
96
|
+
const getSelectedCells = () => {
|
97
|
+
return getRectangleBounds(tableSelection);
|
98
|
+
};
|
99
|
+
const updateTableSelection = update => {
|
100
|
+
setTableSelection(prev => ({
|
101
|
+
...prev,
|
102
|
+
...update
|
103
|
+
}));
|
104
|
+
};
|
105
|
+
const resetAll = () => {
|
106
|
+
setTableSelection(getDefaultTableSelection());
|
107
|
+
Transforms.deselect(editor);
|
108
|
+
|
109
|
+
// hide drag icons after drag completion
|
110
|
+
setTimeout(() => setHoverPath(null), 200);
|
111
|
+
};
|
112
|
+
const values = useMemo(() => {
|
113
|
+
return {
|
114
|
+
hoverPath,
|
115
|
+
setHoverPath,
|
116
|
+
editor,
|
117
|
+
getSelectedCells,
|
118
|
+
updateTableSelection,
|
119
|
+
tableSelection,
|
120
|
+
tableResizing,
|
121
|
+
setTableResizing,
|
122
|
+
otherProps,
|
123
|
+
resetAll
|
124
|
+
};
|
125
|
+
}, [hoverPath, editor?.selection, tableSelection, tableResizing]);
|
126
|
+
useEffect(() => {
|
127
|
+
let isTextSelected;
|
128
|
+
const handleKeyDown = event => {
|
129
|
+
const isCutKey = (event.ctrlKey || event.metaKey) && event.key === "x";
|
130
|
+
if (isCutKey) {
|
131
|
+
isTextSelected = isHavingSelection(editor);
|
132
|
+
} else if (event.key === "Backspace") {
|
133
|
+
const selectedCells = getSelectedCells();
|
134
|
+
if (selectedCells?.length > 1) {
|
135
|
+
selectedCells.forEach(currentCellPath => {
|
136
|
+
clearCellText(editor, currentCellPath);
|
137
|
+
});
|
138
|
+
}
|
139
|
+
}
|
140
|
+
};
|
141
|
+
const handleCopy = (event, isCut) => {
|
142
|
+
try {
|
143
|
+
const isTextSelected = isHavingSelection(editor);
|
144
|
+
const {
|
145
|
+
startCellPath
|
146
|
+
} = tableSelection || {};
|
147
|
+
const customCopy = startCellPath?.length;
|
148
|
+
if (customCopy && !isTextSelected) {
|
149
|
+
event.preventDefault(); // Prevent default copy behavior
|
150
|
+
|
151
|
+
const {
|
152
|
+
tablePath
|
153
|
+
} = otherProps;
|
154
|
+
const [node] = Editor.node(editor, tablePath);
|
155
|
+
const copiedTableNode = createCopiedTableStructure(editor, tableSelection, node, tablePath);
|
156
|
+
const tableNode = [copiedTableNode];
|
157
|
+
const encodedTableNode = encodeToBase64(tableNode);
|
158
|
+
event.clipboardData.setData("application/x-slate-fragment", encodedTableNode);
|
159
|
+
const textData = serializeToText(tableNode);
|
160
|
+
event.clipboardData.setData("text/plain", textData);
|
161
|
+
const tableDom = tableNodeToDom(copiedTableNode);
|
162
|
+
event.clipboardData.setData("text/html", tableDom?.outerHTML);
|
163
|
+
if (isCut) {
|
164
|
+
clearCellText(editor, startCellPath);
|
165
|
+
}
|
166
|
+
}
|
167
|
+
} catch (err) {
|
168
|
+
console.log(err);
|
169
|
+
}
|
170
|
+
};
|
171
|
+
const handleCut = e => {
|
172
|
+
// unable to find the text selected or not here, that why handling it on handleKeyDown
|
173
|
+
|
174
|
+
if (!isTextSelected) {
|
175
|
+
e.preventDefault();
|
176
|
+
handleCopy(e, true);
|
177
|
+
}
|
178
|
+
};
|
179
|
+
window.addEventListener("keydown", handleKeyDown);
|
180
|
+
window.addEventListener("copy", handleCopy);
|
181
|
+
window.addEventListener("cut", handleCut);
|
182
|
+
return () => {
|
183
|
+
window.removeEventListener("keydown", handleKeyDown);
|
184
|
+
window.removeEventListener("copy", handleCopy);
|
185
|
+
window.removeEventListener("cut", handleCut);
|
186
|
+
};
|
187
|
+
}, [tableSelection, editor, tableSelection]);
|
188
|
+
|
189
|
+
// useEffect(() => {
|
190
|
+
// selectFirstCell(tablePath, editor, updateTableSelection);
|
191
|
+
// }, []);
|
192
|
+
|
193
|
+
return /*#__PURE__*/_jsx(TableContext.Provider, {
|
194
|
+
value: values,
|
195
|
+
children: /*#__PURE__*/_jsxs(DndContext, {
|
196
|
+
sensors: sensors,
|
197
|
+
onDragEnd: data => handleDragEnd(data, editor, resetAll),
|
198
|
+
children: [/*#__PURE__*/_jsx(ClickAwayListener, {
|
199
|
+
onClickAway: () => setTableSelection(getDefaultTableSelection()),
|
200
|
+
children: /*#__PURE__*/_jsx("div", {
|
201
|
+
children: children
|
202
|
+
})
|
203
|
+
}), /*#__PURE__*/_jsx(DragOverlay, {})]
|
204
|
+
})
|
205
|
+
});
|
206
|
+
};
|
207
|
+
function useTable() {
|
208
|
+
return useContext(TableContext);
|
209
|
+
}
|
210
|
+
export default useTable;
|
@@ -64,7 +64,7 @@ const withCustomDeleteBackward = editor => {
|
|
64
64
|
|
65
65
|
// Check if current node is a list item and is the last one, signature node
|
66
66
|
const [node] = Editor.nodes(editor, {
|
67
|
-
match: n => BACKWARD_BLOCKS
|
67
|
+
match: n => BACKWARD_BLOCKS.includes(n.type) // Adjust based on your list item type
|
68
68
|
});
|
69
69
|
|
70
70
|
if (node) {
|
@@ -40,32 +40,36 @@ const withEmbeds = editor => {
|
|
40
40
|
}
|
41
41
|
};
|
42
42
|
editor.insertBreak = (...args) => {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
43
|
+
try {
|
44
|
+
const parentPath = Path.parent(editor.selection.focus.path);
|
45
|
+
const parentNode = Node.get(editor, parentPath);
|
46
|
+
if (editor.isVoid(parentNode)) {
|
47
|
+
const nextPath = Path.next(parentPath);
|
48
|
+
Transforms.insertNodes(editor, {
|
49
|
+
type: "paragraph",
|
50
|
+
children: [{
|
51
|
+
text: ""
|
52
|
+
}]
|
53
|
+
}, {
|
54
|
+
at: nextPath,
|
55
|
+
select: true // Focus on this node once inserted
|
56
|
+
});
|
57
|
+
} else if (AvoidCopying.indexOf(parentNode?.type) >= 0) {
|
58
|
+
const nextPath = Path.next(parentPath);
|
59
|
+
Transforms.insertNodes(editor, {
|
60
|
+
type: "paragraph",
|
61
|
+
children: [{
|
62
|
+
text: ""
|
63
|
+
}]
|
64
|
+
}, {
|
65
|
+
at: nextPath,
|
66
|
+
select: true // Focus on this node once inserted
|
67
|
+
});
|
68
|
+
} else {
|
69
|
+
insertBreak(...args);
|
70
|
+
}
|
71
|
+
} catch (err) {
|
72
|
+
console.log(err);
|
69
73
|
}
|
70
74
|
};
|
71
75
|
return editor;
|
@@ -2,6 +2,45 @@ import { Transforms, Editor, Element, Node, Path } from "slate";
|
|
2
2
|
import deserialize from "../helper/deserialize";
|
3
3
|
import { decodeAndParseBase64 } from "../utils/helper";
|
4
4
|
const avoidDefaultInsert = ["table", "grid"];
|
5
|
+
const NON_TEXT_TAGS = ["ol", "ul", "img", "table", "video", "a", "button", "GOOGLE-SHEETS-HTML-ORIGIN"];
|
6
|
+
const ALLOWED_TEXT_NODES = ["paragraph", "title", "headingOne", "headingTwo", "headingThree"];
|
7
|
+
const parseCopiedHTML = html => {
|
8
|
+
const parsed = new DOMParser().parseFromString(html, "text/html");
|
9
|
+
|
10
|
+
// if ol, ul are inside li, remove and push ol,ul after that li to maintain format between our slate list and external source list's json
|
11
|
+
parsed.querySelectorAll("li > ul, li > ol").forEach(list => {
|
12
|
+
// Find the parent li
|
13
|
+
const parentLi = list.parentElement;
|
14
|
+
|
15
|
+
// Move the list after the parent li
|
16
|
+
parentLi.after(list);
|
17
|
+
});
|
18
|
+
|
19
|
+
// to handle google docs list
|
20
|
+
parsed.querySelectorAll("li p, li div").forEach(element => {
|
21
|
+
const parent = element.parentNode;
|
22
|
+
// Move all child nodes of <p> or <div> to its parent <li>
|
23
|
+
while (element.firstChild) {
|
24
|
+
parent.insertBefore(element.firstChild, element);
|
25
|
+
}
|
26
|
+
// Remove the <p> or <div> element
|
27
|
+
parent.removeChild(element);
|
28
|
+
});
|
29
|
+
|
30
|
+
// claude.ai, copy list inbetween, some li tags are not wrapped with ul or ol
|
31
|
+
parsed.querySelectorAll("li").forEach(li => {
|
32
|
+
// Check if the parent of <li> is not a <ul> or <ol>
|
33
|
+
if (!li.parentElement || li.parentElement.tagName !== "UL" && li.parentElement.tagName !== "OL") {
|
34
|
+
// Create a <ul> element
|
35
|
+
const ul = document.createElement("ul");
|
36
|
+
// Append the <li> to the <ul>
|
37
|
+
ul.appendChild(li.cloneNode(true)); // Clone the <li>
|
38
|
+
// Replace the original <li> in the DOM with the <ul>
|
39
|
+
li.replaceWith(ul);
|
40
|
+
}
|
41
|
+
});
|
42
|
+
return parsed;
|
43
|
+
};
|
5
44
|
const loopChildren = (children = [], defaultInsert) => {
|
6
45
|
if (!children?.length) {
|
7
46
|
return defaultInsert;
|
@@ -26,7 +65,7 @@ const getCurrentElement = editor => {
|
|
26
65
|
return null;
|
27
66
|
}
|
28
67
|
};
|
29
|
-
const getCurrentElementText = editor => {
|
68
|
+
export const getCurrentElementText = editor => {
|
30
69
|
try {
|
31
70
|
if (editor.selection) {
|
32
71
|
return Editor.string(editor, editor?.selection?.anchor?.path);
|
@@ -61,12 +100,23 @@ const insertAtNextNode = (editor, formattedFragment) => {
|
|
61
100
|
console.log(err);
|
62
101
|
}
|
63
102
|
};
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
103
|
+
|
104
|
+
// const handleInsert = (editor, defaultInsert, fragment = []) => {
|
105
|
+
// if (
|
106
|
+
// getCurrentElementText(editor) &&
|
107
|
+
// fragment.some((f) => f.type === "table")
|
108
|
+
// ) {
|
109
|
+
// insertAtNextNode(editor, fragment);
|
110
|
+
// } else {
|
111
|
+
// defaultInsert();
|
112
|
+
// }
|
113
|
+
// };
|
114
|
+
|
115
|
+
const getTableCellChild = (fragment = []) => {
|
116
|
+
const table = fragment.find(node => node.type === "table");
|
117
|
+
const row = table?.children?.find(node => node.type === "table-row");
|
118
|
+
const cell = row?.children?.find(node => node.type === "table-cell");
|
119
|
+
return cell?.children || [];
|
70
120
|
};
|
71
121
|
const formatFragment = {
|
72
122
|
"list-item": fragment => {
|
@@ -115,8 +165,21 @@ const withHtml = editor => {
|
|
115
165
|
const html = data?.getData("text/html");
|
116
166
|
const currentEl = getCurrentElement(editor);
|
117
167
|
const eltype = currentEl?.type;
|
168
|
+
const firstNode = editor?.children?.[0];
|
169
|
+
const titlePath = firstNode?.type === "topbanner" ? 1 : 0;
|
170
|
+
const isTitlePath = editor.needLayout && editor?.selection?.anchor?.path[0] === titlePath;
|
118
171
|
if (slateHTML && !formatFragment[eltype]) {
|
172
|
+
const [tableCellNode] = Editor.nodes(editor, {
|
173
|
+
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell"
|
174
|
+
});
|
119
175
|
const decoded = decodeAndParseBase64(slateHTML);
|
176
|
+
if (tableCellNode) {
|
177
|
+
const tableCellChild = getTableCellChild(decoded);
|
178
|
+
if (tableCellChild?.length) {
|
179
|
+
Transforms.insertFragment(editor, tableCellChild);
|
180
|
+
return;
|
181
|
+
}
|
182
|
+
}
|
120
183
|
const tableNode = getFocusedNode(editor, "table");
|
121
184
|
const onlyTextNode = getFocusedNode(editor, "freegrid");
|
122
185
|
|
@@ -154,22 +217,38 @@ const withHtml = editor => {
|
|
154
217
|
Transforms.insertText(editor, text);
|
155
218
|
}
|
156
219
|
} else {
|
157
|
-
|
220
|
+
const isTextNode = ALLOWED_TEXT_NODES.includes(decoded?.[0]?.type);
|
221
|
+
if (isTitlePath && !isTextNode) {
|
222
|
+
insertAtNextNode(editor, decoded);
|
223
|
+
return;
|
224
|
+
}
|
225
|
+
const currentText = getCurrentElementText(editor);
|
226
|
+
if (currentText?.trim() && !isTextNode) {
|
227
|
+
insertAtNextNode(editor, decoded);
|
228
|
+
return;
|
229
|
+
}
|
230
|
+
insertData(data);
|
158
231
|
}
|
159
232
|
} else if (html) {
|
160
|
-
const parsed =
|
233
|
+
const parsed = parseCopiedHTML(html);
|
234
|
+
const rootElement = parsed.body;
|
235
|
+
const isNonText = rootElement ? rootElement?.querySelector(NON_TEXT_TAGS.toString()) : false;
|
161
236
|
const isGoogleSheet = parsed.body.querySelector("google-sheets-html-origin");
|
162
237
|
if (isGoogleSheet) {
|
163
238
|
if (editor.isChatEditor) {
|
164
239
|
return;
|
165
240
|
}
|
166
|
-
const table =
|
241
|
+
const table = rootElement.querySelector("table");
|
167
242
|
const colGrp = table.querySelector("colgroup");
|
168
243
|
if (colGrp) {
|
169
244
|
colGrp.remove();
|
170
245
|
}
|
171
246
|
const fragment = deserialize(table);
|
172
|
-
|
247
|
+
if (isTitlePath) {
|
248
|
+
insertAtNextNode(editor, [fragment]);
|
249
|
+
} else {
|
250
|
+
Transforms.insertFragment(editor, [fragment]);
|
251
|
+
}
|
173
252
|
return;
|
174
253
|
}
|
175
254
|
const fragment = deserialize(parsed.body);
|
@@ -183,7 +262,16 @@ const withHtml = editor => {
|
|
183
262
|
if (editor.isChatEditor && is_img_table) {
|
184
263
|
return;
|
185
264
|
}
|
186
|
-
|
265
|
+
if (isTitlePath && isNonText) {
|
266
|
+
insertAtNextNode(editor, formattedFragment);
|
267
|
+
return;
|
268
|
+
}
|
269
|
+
const currentText = getCurrentElementText(editor);
|
270
|
+
if (currentText?.trim() && isNonText) {
|
271
|
+
insertAtNextNode(editor, formattedFragment);
|
272
|
+
return;
|
273
|
+
}
|
274
|
+
Transforms.insertFragment(editor, formattedFragment);
|
187
275
|
return;
|
188
276
|
} else {
|
189
277
|
insertData(data);
|