@flozy/editor 5.3.6 → 5.3.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 +34 -25
- package/dist/Editor/CommonEditor.js +8 -16
- package/dist/Editor/Editor.css +11 -57
- package/dist/Editor/Elements/AI/AIInput.js +1 -0
- package/dist/Editor/Elements/AI/CustomSelect.js +11 -19
- package/dist/Editor/Elements/AI/PopoverAIInput.js +4 -9
- package/dist/Editor/Elements/AI/Styles.js +5 -17
- package/dist/Editor/Elements/Carousel/CarouselItem.js +3 -11
- package/dist/Editor/Elements/Color Picker/ColorButtons.js +3 -3
- package/dist/Editor/Elements/Color Picker/Styles.js +3 -7
- package/dist/Editor/Elements/Color Picker/defaultColors.js +2 -2
- package/dist/Editor/Elements/Divider/Divider.js +15 -16
- package/dist/Editor/Elements/Embed/Image.js +7 -23
- package/dist/Editor/Elements/Embed/Video.js +1 -13
- package/dist/Editor/Elements/Form/Form.js +2 -38
- package/dist/Editor/Elements/Form/FormElements/FormCheckbox.js +1 -7
- package/dist/Editor/Elements/Form/FormElements/FormDate.js +1 -7
- package/dist/Editor/Elements/Form/FormElements/FormEmail.js +1 -7
- package/dist/Editor/Elements/Form/FormElements/FormNumbers.js +1 -7
- package/dist/Editor/Elements/Form/FormElements/FormRadioButton.js +1 -7
- package/dist/Editor/Elements/Form/FormElements/FormText.js +1 -7
- package/dist/Editor/Elements/Form/FormElements/FormTextArea.js +1 -6
- package/dist/Editor/Elements/Form/FormPopup.js +9 -12
- package/dist/Editor/Elements/FreeGrid/FreeGrid.js +1 -1
- package/dist/Editor/Elements/FreeGrid/FreeGridItem.js +1 -20
- package/dist/Editor/Elements/Grid/GridButton.js +2 -2
- package/dist/Editor/Elements/Grid/GridItem.js +36 -45
- package/dist/Editor/Elements/Grid/Styles.js +0 -6
- package/dist/Editor/Elements/Link/LinkButton.js +1 -1
- package/dist/Editor/Elements/Search/SearchButton.js +0 -1
- 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 +48 -13
- package/dist/Editor/Elements/SimpleText/style.js +0 -10
- package/dist/Editor/Elements/Table/Styles.js +79 -82
- package/dist/Editor/Elements/Table/Table.js +140 -260
- package/dist/Editor/Elements/Table/TableCell.js +103 -362
- package/dist/Editor/Elements/Table/TablePopup.js +3 -9
- package/dist/Editor/Elements/Table/TableRow.js +2 -10
- package/dist/Editor/Styles/EditorStyles.js +1 -8
- package/dist/Editor/Toolbar/FormatTools/BlockButton.js +0 -10
- package/dist/Editor/Toolbar/FormatTools/Dropdown.js +12 -7
- package/dist/Editor/Toolbar/FormatTools/FontFamilyAutocomplete.js +4 -10
- package/dist/Editor/Toolbar/FormatTools/MarkButton.js +0 -3
- package/dist/Editor/Toolbar/FormatTools/TextSize.js +2 -0
- package/dist/Editor/Toolbar/Mini/MiniToolbar.js +6 -3
- package/dist/Editor/Toolbar/Mini/Styles.js +1 -4
- package/dist/Editor/Toolbar/PopupTool/MiniTextFormat/index.js +3 -3
- package/dist/Editor/Toolbar/PopupTool/PopperHeader.js +15 -19
- package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +49 -409
- package/dist/Editor/Toolbar/PopupTool/TextFormat.js +8 -17
- package/dist/Editor/Toolbar/PopupTool/index.js +5 -3
- package/dist/Editor/assets/svg/BrainIcon.js +2 -2
- package/dist/Editor/common/ColorPickerButton.js +44 -82
- package/dist/Editor/common/Icon.js +20 -17
- package/dist/Editor/common/LinkSettings/NavComponents.js +1 -2
- package/dist/Editor/common/LinkSettings/index.js +1 -2
- package/dist/Editor/common/MentionsPopup/Styles.js +8 -156
- package/dist/Editor/common/MentionsPopup/index.js +1 -1
- package/dist/Editor/common/RnD/ElementSettings/Settings/FormSettings.js +12 -107
- package/dist/Editor/common/RnD/VirtualElement/index.js +1 -5
- package/dist/Editor/common/RnD/index.js +1 -1
- package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +4 -8
- package/dist/Editor/common/StyleBuilder/fieldTypes/radiusStyle.js +7 -7
- package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +2 -5
- package/dist/Editor/common/StyleBuilder/formStyle.js +149 -268
- package/dist/Editor/common/StyleBuilder/index.js +11 -84
- package/dist/Editor/common/StyleBuilder/tableStyle.js +25 -69
- package/dist/Editor/common/SwipeableDrawer/style.js +4 -15
- package/dist/Editor/common/iconListV2.js +40 -378
- package/dist/Editor/common/iconslist.js +14 -17
- package/dist/Editor/commonStyle.js +10 -130
- package/dist/Editor/helper/deserialize/index.js +20 -27
- package/dist/Editor/helper/index.js +1 -1
- package/dist/Editor/plugins/withCustomDeleteBackward.js +2 -3
- package/dist/Editor/plugins/withHTML.js +10 -61
- package/dist/Editor/plugins/withLayout.js +0 -1
- package/dist/Editor/utils/SlateUtilityFunctions.js +0 -2
- package/dist/Editor/utils/brains.js +1 -1
- package/dist/Editor/utils/chatEditor/SlateUtilityFunctions.js +1 -26
- package/dist/Editor/utils/customHooks/useResize.js +4 -7
- package/dist/Editor/utils/customHooks/useTableResize.js +2 -6
- package/dist/Editor/utils/embed.js +1 -2
- package/dist/Editor/utils/events.js +1 -0
- package/dist/Editor/utils/font.js +4 -11
- package/dist/Editor/utils/formfield.js +4 -8
- package/dist/Editor/utils/helper.js +2 -55
- package/dist/Editor/utils/insertNewLine.js +1 -19
- package/dist/Editor/utils/serializeToText.js +0 -2
- package/dist/Editor/utils/table.js +24 -228
- package/package.json +1 -1
- package/dist/Editor/Elements/Table/AddRowCol.js +0 -77
- package/dist/Editor/Elements/Table/DragButton.js +0 -142
- package/dist/Editor/Elements/Table/DragStyles.js +0 -70
- package/dist/Editor/Elements/Table/Draggable.js +0 -25
- package/dist/Editor/Elements/Table/Droppable.js +0 -53
- package/dist/Editor/Elements/Table/TableTool.js +0 -101
- package/dist/Editor/Elements/Table/tableHelper.js +0 -71
- package/dist/Editor/assets/svg/TableIcons.js +0 -220
- package/dist/Editor/common/Select/index.js +0 -20
- package/dist/Editor/common/Select/styles.js +0 -17
- package/dist/Editor/hooks/useTable.js +0 -207
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Transforms } from "slate";
|
2
|
-
import insertNewLine
|
2
|
+
import insertNewLine from "./insertNewLine";
|
3
3
|
export const insertDefaultEmbed = (editor, type, defaultURL = "", extProps = {}) => {
|
4
4
|
try {
|
5
5
|
const url = defaultURL ? defaultURL : type === "image" ? "" : "";
|
@@ -56,7 +56,6 @@ export const insertEmbed = (editor, embedData, format) => {
|
|
56
56
|
at: editor.selection.anchor.path
|
57
57
|
});
|
58
58
|
insertNewLine(editor);
|
59
|
-
insertNewLineAfterCurrentPath(editor);
|
60
59
|
} catch (err) {
|
61
60
|
console.log(err);
|
62
61
|
}
|
@@ -5,6 +5,7 @@ import { insertAccordion } from "./accordion";
|
|
5
5
|
import { isListItem } from "./helper";
|
6
6
|
import RnDCtrlCmds from "./RnD/RnDCtrlCmds";
|
7
7
|
import EDITORCMDS from "../common/EditorCmds";
|
8
|
+
import { ReactEditor } from "slate-react";
|
8
9
|
const HOTKEYS = {
|
9
10
|
b: "bold",
|
10
11
|
i: "italic",
|
@@ -60,14 +60,7 @@ export const signedTextFonts = Object.keys(fontFamilyMap).slice(-12).map(m => {
|
|
60
60
|
};
|
61
61
|
});
|
62
62
|
export const headingMap = {
|
63
|
-
headingOne: "32px",
|
64
|
-
headingTwo: "24px",
|
65
|
-
headingThree: "19px"
|
66
|
-
};
|
67
|
-
export const fontWeightOptions = [{
|
68
|
-
text: "Bold",
|
69
|
-
value: "500"
|
70
|
-
}, {
|
71
|
-
text: "Bolder",
|
72
|
-
value: "600"
|
73
|
-
}];
|
63
|
+
"headingOne": "32px",
|
64
|
+
"headingTwo": "24px",
|
65
|
+
"headingThree": "19px"
|
66
|
+
};
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Transforms } from "slate";
|
2
|
-
export const formField =
|
2
|
+
export const formField = () => {
|
3
3
|
return {
|
4
4
|
type: "form-field",
|
5
5
|
grid: 6,
|
@@ -12,18 +12,14 @@ export const formField = data => {
|
|
12
12
|
text: ""
|
13
13
|
}],
|
14
14
|
field_type: "text",
|
15
|
-
bgColor:
|
16
|
-
borderColor:
|
15
|
+
bgColor: "rgba(255, 255, 255, 1)",
|
16
|
+
borderColor: "#ccc",
|
17
17
|
bannerSpacing: {
|
18
18
|
left: 16,
|
19
19
|
right: 16,
|
20
20
|
top: 16,
|
21
21
|
bottom: 16
|
22
|
-
}
|
23
|
-
fontFamily: data?.fontFamily ? data?.fontFamily : "",
|
24
|
-
textSize: data?.textSize ? data?.textSize : "",
|
25
|
-
textColor: data?.textColor ? data?.textColor : "",
|
26
|
-
fontWeight: data?.fontWeight ? data?.fontWeight : "500"
|
22
|
+
}
|
27
23
|
};
|
28
24
|
};
|
29
25
|
export const insertGridItem = editor => {
|
@@ -212,7 +212,7 @@ export const isListItem = editor => {
|
|
212
212
|
});
|
213
213
|
return node;
|
214
214
|
};
|
215
|
-
|
215
|
+
const getNode = (editor, path) => {
|
216
216
|
try {
|
217
217
|
return Node.get(editor, path);
|
218
218
|
} catch (err) {
|
@@ -264,17 +264,6 @@ export const decodeAndParseBase64 = encodedString => {
|
|
264
264
|
const jsonData = JSON.parse(decodedURLString);
|
265
265
|
return jsonData;
|
266
266
|
};
|
267
|
-
export const encodeToBase64 = data => {
|
268
|
-
// Convert the data to a JSON string
|
269
|
-
const jsonString = JSON.stringify(data);
|
270
|
-
|
271
|
-
// URL-encode the JSON string
|
272
|
-
const encodedURLString = encodeURIComponent(jsonString);
|
273
|
-
|
274
|
-
// Base64-encode the URL-encoded string
|
275
|
-
const base64EncodedString = btoa(encodedURLString);
|
276
|
-
return base64EncodedString;
|
277
|
-
};
|
278
267
|
export const hasVerticalScrollbar = (element = {}) => {
|
279
268
|
return element.scrollHeight > element.clientHeight;
|
280
269
|
};
|
@@ -622,46 +611,4 @@ export const isPageSettings = (event, editor) => {
|
|
622
611
|
isPageSettingsNode = true;
|
623
612
|
return isPageSettingsNode;
|
624
613
|
}
|
625
|
-
};
|
626
|
-
const omitNodes = ["site-settings", "page-settings"];
|
627
|
-
export function getInitialValue(value = [], readOnly) {
|
628
|
-
if (readOnly === "readonly" && value?.length) {
|
629
|
-
// remove last empty nodes on readonly mode, to remove empty spaces
|
630
|
-
|
631
|
-
let lastNonEmptyElementIndex;
|
632
|
-
for (let i = value?.length; i > 0; i--) {
|
633
|
-
const elementIndex = i - 1;
|
634
|
-
const node = value[elementIndex];
|
635
|
-
if (lastNonEmptyElementIndex) {
|
636
|
-
break;
|
637
|
-
}
|
638
|
-
if (node?.type === "paragraph") {
|
639
|
-
// Ensure all children of the paragraph node are text nodes
|
640
|
-
const hasOnlyTextChildren = node.children.every(child => Text.isText(child));
|
641
|
-
const text = node.children[node.children.length - 1]?.text;
|
642
|
-
lastNonEmptyElementIndex = hasOnlyTextChildren ? text ? elementIndex : null : elementIndex;
|
643
|
-
} else if (omitNodes.includes(node?.type)) {
|
644
|
-
continue;
|
645
|
-
} else {
|
646
|
-
lastNonEmptyElementIndex = elementIndex;
|
647
|
-
}
|
648
|
-
}
|
649
|
-
const newValue = [...value].slice(0, lastNonEmptyElementIndex + 1);
|
650
|
-
return newValue;
|
651
|
-
}
|
652
|
-
return value;
|
653
|
-
}
|
654
|
-
export function capitalizeFirstLetter(str) {
|
655
|
-
if (!str) return str;
|
656
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
657
|
-
}
|
658
|
-
export function isHavingSelection(editor) {
|
659
|
-
try {
|
660
|
-
return editor?.selection && !Range.isCollapsed(editor.selection);
|
661
|
-
} catch (err) {
|
662
|
-
console.log(err);
|
663
|
-
}
|
664
|
-
}
|
665
|
-
export function getSelectedCls(defaultCls = "", selected, selectedClsName = "selected") {
|
666
|
-
return `${defaultCls} ${selected ? selectedClsName : ""}`;
|
667
|
-
}
|
614
|
+
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { Transforms } from "slate";
|
2
2
|
const insertNewLine = editor => {
|
3
3
|
Transforms.insertNodes(editor, {
|
4
4
|
type: "paragraph",
|
@@ -9,22 +9,4 @@ const insertNewLine = editor => {
|
|
9
9
|
at: [editor.children.length]
|
10
10
|
});
|
11
11
|
};
|
12
|
-
export const insertNewLineAfterCurrentPath = editor => {
|
13
|
-
const currentPath = editor?.selection?.anchor?.path;
|
14
|
-
const [tableNode] = Editor.nodes(editor, {
|
15
|
-
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
16
|
-
});
|
17
|
-
if (currentPath && tableNode) {
|
18
|
-
const currentParentPath = Path.parent(currentPath);
|
19
|
-
const nextPath = Path.next(currentParentPath);
|
20
|
-
Transforms.insertNodes(editor, {
|
21
|
-
type: "paragraph",
|
22
|
-
children: [{
|
23
|
-
text: ""
|
24
|
-
}]
|
25
|
-
}, {
|
26
|
-
at: nextPath
|
27
|
-
});
|
28
|
-
}
|
29
|
-
};
|
30
12
|
export default insertNewLine;
|
@@ -2,8 +2,6 @@ export const serializeToText = node => {
|
|
2
2
|
try {
|
3
3
|
if (!node?.type && node?.text) {
|
4
4
|
return node?.text;
|
5
|
-
} else if (node?.type === 'mention') {
|
6
|
-
return '@' + node?.character?.name || '';
|
7
5
|
}
|
8
6
|
let n = Array.isArray(node) ? node : node?.children;
|
9
7
|
n = n && Array.isArray(n) ? n : n ? [n] : [];
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Transforms, Editor, Range, Element, Path, Node } from "slate";
|
2
2
|
import { ReactEditor } from "slate-react";
|
3
|
-
import { customInsertNode
|
3
|
+
import { customInsertNode } from "./helper";
|
4
4
|
export const DEFAULT_TABLE_NODE = () => ({
|
5
5
|
type: "table",
|
6
6
|
children: [{
|
@@ -13,10 +13,7 @@ export const DEFAULT_TABLE_NODE = () => ({
|
|
13
13
|
text: ""
|
14
14
|
}],
|
15
15
|
cellBgColor: "#FFFFFF"
|
16
|
-
}]
|
17
|
-
size: {
|
18
|
-
width: 120
|
19
|
-
}
|
16
|
+
}]
|
20
17
|
}, {
|
21
18
|
type: "table-cell",
|
22
19
|
children: [{
|
@@ -25,10 +22,7 @@ export const DEFAULT_TABLE_NODE = () => ({
|
|
25
22
|
text: ""
|
26
23
|
}],
|
27
24
|
cellBgColor: "#FFFFFF"
|
28
|
-
}]
|
29
|
-
size: {
|
30
|
-
width: 120
|
31
|
-
}
|
25
|
+
}]
|
32
26
|
}, {
|
33
27
|
type: "table-cell",
|
34
28
|
children: [{
|
@@ -37,10 +31,7 @@ export const DEFAULT_TABLE_NODE = () => ({
|
|
37
31
|
text: ""
|
38
32
|
}],
|
39
33
|
cellBgColor: "#FFFFFF"
|
40
|
-
}]
|
41
|
-
size: {
|
42
|
-
width: 120
|
43
|
-
}
|
34
|
+
}]
|
44
35
|
}]
|
45
36
|
}, {
|
46
37
|
type: "table-row",
|
@@ -52,10 +43,7 @@ export const DEFAULT_TABLE_NODE = () => ({
|
|
52
43
|
text: ""
|
53
44
|
}],
|
54
45
|
cellBgColor: "#FFFFFF"
|
55
|
-
}]
|
56
|
-
size: {
|
57
|
-
width: 120
|
58
|
-
}
|
46
|
+
}]
|
59
47
|
}, {
|
60
48
|
type: "table-cell",
|
61
49
|
children: [{
|
@@ -64,10 +52,7 @@ export const DEFAULT_TABLE_NODE = () => ({
|
|
64
52
|
text: ""
|
65
53
|
}],
|
66
54
|
cellBgColor: "#FFFFFF"
|
67
|
-
}]
|
68
|
-
size: {
|
69
|
-
width: 120
|
70
|
-
}
|
55
|
+
}]
|
71
56
|
}, {
|
72
57
|
type: "table-cell",
|
73
58
|
children: [{
|
@@ -78,7 +63,9 @@ export const DEFAULT_TABLE_NODE = () => ({
|
|
78
63
|
cellBgColor: "#FFFFFF"
|
79
64
|
}],
|
80
65
|
size: {
|
81
|
-
|
66
|
+
widthInPercent: 100,
|
67
|
+
height: 100,
|
68
|
+
width: 365.3307291666667
|
82
69
|
}
|
83
70
|
}]
|
84
71
|
}, {
|
@@ -91,10 +78,7 @@ export const DEFAULT_TABLE_NODE = () => ({
|
|
91
78
|
text: ""
|
92
79
|
}],
|
93
80
|
cellBgColor: "#FFFFFF"
|
94
|
-
}]
|
95
|
-
size: {
|
96
|
-
width: 120
|
97
|
-
}
|
81
|
+
}]
|
98
82
|
}, {
|
99
83
|
type: "table-cell",
|
100
84
|
children: [{
|
@@ -103,10 +87,7 @@ export const DEFAULT_TABLE_NODE = () => ({
|
|
103
87
|
text: ""
|
104
88
|
}],
|
105
89
|
cellBgColor: "#FFFFFF"
|
106
|
-
}]
|
107
|
-
size: {
|
108
|
-
width: 120
|
109
|
-
}
|
90
|
+
}]
|
110
91
|
}, {
|
111
92
|
type: "table-cell",
|
112
93
|
children: [{
|
@@ -117,14 +98,14 @@ export const DEFAULT_TABLE_NODE = () => ({
|
|
117
98
|
cellBgColor: "#FFFFFF"
|
118
99
|
}],
|
119
100
|
size: {
|
120
|
-
|
101
|
+
height: 300,
|
102
|
+
widthInPercent: 100
|
121
103
|
}
|
122
104
|
}]
|
123
105
|
}],
|
124
106
|
rows: 3,
|
125
107
|
columns: 3
|
126
108
|
});
|
127
|
-
const isFreeGridTable = n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "freegridItem" && n.childType === "table";
|
128
109
|
const prefixKey = (obj, pk = "") => {
|
129
110
|
return Object.keys(obj).reduce((a, b) => {
|
130
111
|
a[`${pk}${b}`] = obj[b];
|
@@ -163,49 +144,12 @@ export class TableUtil {
|
|
163
144
|
customInsertNode(this.editor, newTable);
|
164
145
|
};
|
165
146
|
removeTable = () => {
|
166
|
-
|
167
|
-
match:
|
147
|
+
Transforms.removeNodes(this.editor, {
|
148
|
+
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
149
|
+
// mode:'highest'
|
168
150
|
});
|
169
|
-
if (freeGridItem) {
|
170
|
-
Transforms.removeNodes(this.editor, {
|
171
|
-
match: isFreeGridTable
|
172
|
-
});
|
173
|
-
} else {
|
174
|
-
Transforms.removeNodes(this.editor, {
|
175
|
-
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
176
|
-
});
|
177
|
-
}
|
178
|
-
};
|
179
|
-
duplicateTable = () => {
|
180
|
-
const {
|
181
|
-
selection
|
182
|
-
} = this.editor;
|
183
|
-
if (!!selection && Range.isCollapsed(selection)) {
|
184
|
-
const [freeGridItem] = Editor.nodes(this.editor, {
|
185
|
-
match: isFreeGridTable
|
186
|
-
});
|
187
|
-
let clone;
|
188
|
-
let path;
|
189
|
-
if (freeGridItem) {
|
190
|
-
const [freeGridNode, freeGridPath] = freeGridItem;
|
191
|
-
clone = freeGridNode;
|
192
|
-
path = freeGridPath;
|
193
|
-
} else {
|
194
|
-
const [[tableNode, tablePath]] = Editor.nodes(this.editor, {
|
195
|
-
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
196
|
-
});
|
197
|
-
clone = tableNode;
|
198
|
-
path = tablePath;
|
199
|
-
}
|
200
|
-
const nextPath = Path.next(path);
|
201
|
-
if (clone) {
|
202
|
-
const clonedNode = JSON.parse(JSON.stringify(clone));
|
203
|
-
Transforms.insertNodes(this.editor, clonedNode, {
|
204
|
-
at: nextPath
|
205
|
-
});
|
206
|
-
}
|
207
|
-
}
|
208
151
|
};
|
152
|
+
|
209
153
|
getDOMNode = path => {
|
210
154
|
try {
|
211
155
|
const [tableNode] = Editor.nodes(this.editor, {
|
@@ -242,12 +186,9 @@ export class TableUtil {
|
|
242
186
|
const [[table, tablePath]] = Editor.nodes(this.editor, {
|
243
187
|
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
244
188
|
});
|
245
|
-
const [
|
246
|
-
const
|
247
|
-
|
248
|
-
const path = isInsertNext ? Path.next(currentRow) : currentRow;
|
249
|
-
const insertData = isDuplicate ? JSON.parse(JSON.stringify(currentRowData)) : createRowOnInsertAbove(currentRowData, currentRow, this.editor);
|
250
|
-
Transforms.insertNodes(this.editor, insertData, {
|
189
|
+
const [, currentRow] = tableNode;
|
190
|
+
const path = action === "after" ? Path.next(currentRow) : currentRow;
|
191
|
+
Transforms.insertNodes(this.editor, createRow(Array(table.columns).fill("")), {
|
251
192
|
at: path
|
252
193
|
});
|
253
194
|
Transforms.setNodes(this.editor, {
|
@@ -258,23 +199,6 @@ export class TableUtil {
|
|
258
199
|
}
|
259
200
|
}
|
260
201
|
};
|
261
|
-
clearRow = () => {
|
262
|
-
const {
|
263
|
-
selection
|
264
|
-
} = this.editor;
|
265
|
-
if (!!selection && Range.isCollapsed(selection)) {
|
266
|
-
const [tableRow] = Editor.nodes(this.editor, {
|
267
|
-
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-row"
|
268
|
-
});
|
269
|
-
if (tableRow) {
|
270
|
-
const [tableRowNode, tableRowPath] = tableRow;
|
271
|
-
tableRowNode?.children?.forEach((cell, index) => {
|
272
|
-
const currentCellPath = [...tableRowPath, index];
|
273
|
-
clearCellText(this.editor, currentCellPath);
|
274
|
-
});
|
275
|
-
}
|
276
|
-
}
|
277
|
-
};
|
278
202
|
deleteRow = () => {
|
279
203
|
try {
|
280
204
|
const {
|
@@ -335,58 +259,6 @@ export class TableUtil {
|
|
335
259
|
}
|
336
260
|
}
|
337
261
|
};
|
338
|
-
duplicateColumn = () => {
|
339
|
-
const {
|
340
|
-
selection
|
341
|
-
} = this.editor;
|
342
|
-
if (!!selection && Range.isCollapsed(selection)) {
|
343
|
-
const [tableNode] = Editor.nodes(this.editor, {
|
344
|
-
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell"
|
345
|
-
});
|
346
|
-
if (tableNode) {
|
347
|
-
const [[table, tablePath]] = Editor.nodes(this.editor, {
|
348
|
-
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
349
|
-
});
|
350
|
-
const [, currentCell] = tableNode;
|
351
|
-
const currentCellPath = currentCell;
|
352
|
-
const insertNextCellPath = Path.next(currentCell);
|
353
|
-
for (let row = 0; row < table.rows; row++) {
|
354
|
-
currentCellPath[currentCellPath.length - 2] = row;
|
355
|
-
insertNextCellPath[insertNextCellPath?.length - 2] = row;
|
356
|
-
const cellNode = getNode(this.editor, currentCellPath);
|
357
|
-
Transforms.insertNodes(this.editor, JSON.parse(JSON.stringify(cellNode)), {
|
358
|
-
at: insertNextCellPath
|
359
|
-
});
|
360
|
-
}
|
361
|
-
Transforms.setNodes(this.editor, {
|
362
|
-
columns: table.columns + 1
|
363
|
-
}, {
|
364
|
-
at: tablePath
|
365
|
-
});
|
366
|
-
}
|
367
|
-
}
|
368
|
-
};
|
369
|
-
clearColumn = () => {
|
370
|
-
const {
|
371
|
-
selection
|
372
|
-
} = this.editor;
|
373
|
-
if (!!selection && Range.isCollapsed(selection)) {
|
374
|
-
const [tableNode] = Editor.nodes(this.editor, {
|
375
|
-
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table-cell"
|
376
|
-
});
|
377
|
-
if (tableNode) {
|
378
|
-
const [[table]] = Editor.nodes(this.editor, {
|
379
|
-
match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "table"
|
380
|
-
});
|
381
|
-
const [, currentCell] = tableNode;
|
382
|
-
const currentCellPath = currentCell;
|
383
|
-
for (let row = 0; row < table.rows; row++) {
|
384
|
-
currentCellPath[currentCellPath.length - 2] = row;
|
385
|
-
clearCellText(this.editor, currentCellPath);
|
386
|
-
}
|
387
|
-
}
|
388
|
-
}
|
389
|
-
};
|
390
262
|
deleteColumn = () => {
|
391
263
|
try {
|
392
264
|
const {
|
@@ -454,7 +326,6 @@ export class TableUtil {
|
|
454
326
|
}, {
|
455
327
|
at: currentCellPath
|
456
328
|
});
|
457
|
-
applyColumnStyle(this.editor, currentCellPath, currentTablePath, cellProps, tableProps?.rows);
|
458
329
|
|
459
330
|
// cell bg entire
|
460
331
|
if (cellProps?.entireBgColor || tableProps?.borderColor || rowProps?.borderColor) {
|
@@ -492,14 +363,6 @@ export class TableUtil {
|
|
492
363
|
console.log(err);
|
493
364
|
}
|
494
365
|
};
|
495
|
-
resizeTableCell = (styleProps, path) => {
|
496
|
-
const cellProps = parseByPrefixKey(styleProps, "col.");
|
497
|
-
Transforms.setNodes(this.editor, {
|
498
|
-
...cellProps
|
499
|
-
}, {
|
500
|
-
at: path
|
501
|
-
});
|
502
|
-
};
|
503
366
|
getTableProps = () => {
|
504
367
|
const {
|
505
368
|
selection
|
@@ -622,14 +485,14 @@ export class TableUtil {
|
|
622
485
|
}
|
623
486
|
};
|
624
487
|
}
|
625
|
-
const createRow =
|
626
|
-
const newRow = Array.from(cellText, value => createTableCell(value
|
488
|
+
const createRow = cellText => {
|
489
|
+
const newRow = Array.from(cellText, value => createTableCell(value));
|
627
490
|
return {
|
628
491
|
type: "table-row",
|
629
492
|
children: newRow
|
630
493
|
};
|
631
494
|
};
|
632
|
-
export const createTableCell =
|
495
|
+
export const createTableCell = text => {
|
633
496
|
return {
|
634
497
|
type: "table-cell",
|
635
498
|
children: [{
|
@@ -637,35 +500,7 @@ export const createTableCell = (text, other = {}) => {
|
|
637
500
|
children: [{
|
638
501
|
text
|
639
502
|
}]
|
640
|
-
}]
|
641
|
-
size: {
|
642
|
-
width: 120
|
643
|
-
},
|
644
|
-
...other
|
645
|
-
};
|
646
|
-
};
|
647
|
-
const createRowOnInsertAbove = (currentRow, currRowPath, editor) => {
|
648
|
-
const isFirstRow = currRowPath[currRowPath?.length - 1] === 0;
|
649
|
-
const rowChild = currentRow?.children?.map((cell, i) => {
|
650
|
-
let other = {};
|
651
|
-
|
652
|
-
// remove the current row's size and add it on the currently inserting cell
|
653
|
-
if (isFirstRow) {
|
654
|
-
const cellPath = [...currRowPath, i];
|
655
|
-
Transforms.setNodes(editor, {
|
656
|
-
size: null
|
657
|
-
}, {
|
658
|
-
at: cellPath
|
659
|
-
});
|
660
|
-
other = {
|
661
|
-
size: cell?.size
|
662
|
-
};
|
663
|
-
}
|
664
|
-
return createTableCell("", other);
|
665
|
-
});
|
666
|
-
return {
|
667
|
-
type: "table-row",
|
668
|
-
children: rowChild
|
503
|
+
}]
|
669
504
|
};
|
670
505
|
};
|
671
506
|
|
@@ -714,43 +549,4 @@ const createTableNode = (cellText, rows, columns) => {
|
|
714
549
|
columns
|
715
550
|
};
|
716
551
|
return tableNode;
|
717
|
-
};
|
718
|
-
const columnStyleKeys = ["entireBgColor", "entireBorderColor", "entireTextColor", "entireFontFamily", "entireFontWeight", "entireTextSize"];
|
719
|
-
const applyColumnStyle = (editor, currentCellPath, currentTablePath, cellProps, rows) => {
|
720
|
-
const colStyle = columnStyleKeys.reduce((acc, key) => {
|
721
|
-
const style = cellProps[key];
|
722
|
-
if (style) {
|
723
|
-
acc[key] = style;
|
724
|
-
}
|
725
|
-
return acc;
|
726
|
-
}, {});
|
727
|
-
for (let r = 0; r < rows; r++) {
|
728
|
-
const cellPosition = currentCellPath[currentCellPath?.length - 1]; // cell position on each row as per selected column cell
|
729
|
-
|
730
|
-
Transforms.setNodes(editor, colStyle, {
|
731
|
-
at: [...currentTablePath, r, cellPosition]
|
732
|
-
});
|
733
|
-
}
|
734
|
-
};
|
735
|
-
export const clearCellText = (editor, currentCellPath) => {
|
736
|
-
try {
|
737
|
-
const existingCellNode = getNode(editor, currentCellPath);
|
738
|
-
Transforms.removeNodes(editor, {
|
739
|
-
at: currentCellPath
|
740
|
-
});
|
741
|
-
Transforms.insertNodes(editor, {
|
742
|
-
...(existingCellNode || {}),
|
743
|
-
children: [{
|
744
|
-
type: "paragraph",
|
745
|
-
children: [{
|
746
|
-
text: ""
|
747
|
-
}],
|
748
|
-
cellBgColor: "#FFFFFF"
|
749
|
-
}]
|
750
|
-
}, {
|
751
|
-
at: currentCellPath
|
752
|
-
});
|
753
|
-
} catch (err) {
|
754
|
-
console.log(err);
|
755
|
-
}
|
756
552
|
};
|
package/package.json
CHANGED
@@ -1,77 +0,0 @@
|
|
1
|
-
import { Button } from "@mui/material";
|
2
|
-
import { useMemo, useState } from "react";
|
3
|
-
import useTable from "../../hooks/useTable";
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
5
|
-
const showAddButton = (addType, tableNode, hoverPath) => {
|
6
|
-
const [row, col] = hoverPath && hoverPath?.length ? hoverPath.slice(-2) : [];
|
7
|
-
if (addType === "row") {
|
8
|
-
return tableNode?.rows - 1 === row;
|
9
|
-
} else {
|
10
|
-
return tableNode?.columns - 1 === col;
|
11
|
-
}
|
12
|
-
};
|
13
|
-
const ADD_COL_BTN_WIDTH = 20;
|
14
|
-
function AddRowCol(props) {
|
15
|
-
const {
|
16
|
-
tableRef,
|
17
|
-
containerRef,
|
18
|
-
addType,
|
19
|
-
tableNode,
|
20
|
-
onAdd,
|
21
|
-
readOnly
|
22
|
-
} = props;
|
23
|
-
const {
|
24
|
-
hoverPath
|
25
|
-
} = useTable();
|
26
|
-
const [hoveringAddBtn, setHoveringAddBtn] = useState(false);
|
27
|
-
const {
|
28
|
-
tableResizing
|
29
|
-
} = useTable();
|
30
|
-
const {
|
31
|
-
clientHeight,
|
32
|
-
scrollWidth
|
33
|
-
} = tableRef?.current || {};
|
34
|
-
const {
|
35
|
-
clientWidth: containerWidth
|
36
|
-
} = containerRef?.current || {};
|
37
|
-
const buttonStyle = useMemo(() => {
|
38
|
-
if (addType === "row") {
|
39
|
-
const isScrollEnabled = scrollWidth > containerWidth;
|
40
|
-
const width = isScrollEnabled ? containerWidth - ADD_COL_BTN_WIDTH : scrollWidth;
|
41
|
-
return {
|
42
|
-
width
|
43
|
-
};
|
44
|
-
} else {
|
45
|
-
return {
|
46
|
-
height: "100%",
|
47
|
-
marginLeft: "3px"
|
48
|
-
};
|
49
|
-
}
|
50
|
-
}, [scrollWidth, clientHeight, containerWidth, tableResizing]);
|
51
|
-
const showAdd = showAddButton(addType, tableNode, hoverPath);
|
52
|
-
const onMouseEnter = () => setHoveringAddBtn(true);
|
53
|
-
const onMouseLeave = () => setHoveringAddBtn(false);
|
54
|
-
const showBtn = (showAdd || hoveringAddBtn) && !tableResizing && !readOnly;
|
55
|
-
return /*#__PURE__*/_jsx("div", {
|
56
|
-
onMouseEnter: onMouseEnter,
|
57
|
-
onMouseLeave: onMouseLeave,
|
58
|
-
contentEditable: false,
|
59
|
-
children: /*#__PURE__*/_jsx(Button, {
|
60
|
-
sx: {
|
61
|
-
fontSize: "14px",
|
62
|
-
border: "1px dashed #8DA8E3",
|
63
|
-
color: "#2563EB !important",
|
64
|
-
padding: "0px 4px",
|
65
|
-
minWidth: "unset",
|
66
|
-
lineHeight: "18px",
|
67
|
-
fontWeight: "normal !important",
|
68
|
-
...buttonStyle,
|
69
|
-
opacity: showBtn ? 1 : 0
|
70
|
-
},
|
71
|
-
disabled: !showBtn,
|
72
|
-
onClick: onAdd,
|
73
|
-
children: "+"
|
74
|
-
})
|
75
|
-
});
|
76
|
-
}
|
77
|
-
export default AddRowCol;
|