@flozy/editor 1.7.4 → 1.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/Editor/CommonEditor.js +30 -12
  2. package/dist/Editor/DialogWrapper.js +2 -10
  3. package/dist/Editor/Editor.css +105 -0
  4. package/dist/Editor/Elements/Color Picker/ColorButtons.js +14 -4
  5. package/dist/Editor/Elements/Color Picker/ColorPicker.js +9 -6
  6. package/dist/Editor/Elements/Color Picker/LogoIcon.js +15 -49
  7. package/dist/Editor/Elements/Color Picker/Styles.js +25 -4
  8. package/dist/Editor/Elements/Color Picker/defaultColors.js +1 -1
  9. package/dist/Editor/Elements/Embed/Image.js +25 -31
  10. package/dist/Editor/Elements/Embed/Video.js +49 -40
  11. package/dist/Editor/Elements/Form/Workflow/FormWorkflow.js +49 -3
  12. package/dist/Editor/Elements/Form/Workflow/ListWorkflow.js +92 -75
  13. package/dist/Editor/Elements/Form/Workflow/MoreOptions.js +0 -1
  14. package/dist/Editor/Elements/Form/Workflow/Styles.js +19 -5
  15. package/dist/Editor/Elements/Form/Workflow/UserInputs.js +2 -4
  16. package/dist/Editor/Elements/Grid/Grid.js +67 -114
  17. package/dist/Editor/Elements/Grid/GridItem.js +9 -23
  18. package/dist/Editor/Elements/Grid/templates/default_grid.js +0 -23
  19. package/dist/Editor/Elements/Link/Link.js +58 -20
  20. package/dist/Editor/Elements/Link/LinkButton.js +37 -97
  21. package/dist/Editor/Elements/Link/LinkPopup.js +106 -0
  22. package/dist/Editor/Elements/List/CheckList.js +28 -22
  23. package/dist/Editor/Elements/Signature/SignatureOptions/TypeSignature.js +11 -5
  24. package/dist/Editor/Elements/Signature/SignaturePopup.js +15 -4
  25. package/dist/Editor/Elements/SimpleText.js +30 -26
  26. package/dist/Editor/MiniEditor.js +4 -6
  27. package/dist/Editor/Styles/EditorStyles.js +72 -1
  28. package/dist/Editor/Toolbar/FormatTools/TextSize.js +2 -1
  29. package/dist/Editor/Toolbar/Mini/MiniToolbar.js +5 -1
  30. package/dist/Editor/Toolbar/PopupTool/AddTemplates.js +3 -1
  31. package/dist/Editor/Toolbar/PopupTool/PopupToolStyle.js +4 -0
  32. package/dist/Editor/Toolbar/PopupTool/TextFormat.js +96 -19
  33. package/dist/Editor/Toolbar/toolbarGroups.js +1 -1
  34. package/dist/Editor/common/Section/index.js +118 -0
  35. package/dist/Editor/common/Shorthands/elements.js +1 -1
  36. package/dist/Editor/common/StyleBuilder/appHeaderStyle.js +5 -1
  37. package/dist/Editor/common/StyleBuilder/buttonStyle.js +44 -51
  38. package/dist/Editor/common/StyleBuilder/embedImageStyle.js +2 -24
  39. package/dist/Editor/common/StyleBuilder/embedVideoStyle.js +0 -3
  40. package/dist/Editor/common/StyleBuilder/fieldStyle.js +0 -3
  41. package/dist/Editor/common/StyleBuilder/fieldTypes/alignment.js +52 -62
  42. package/dist/Editor/common/StyleBuilder/fieldTypes/backgroundImage.js +2 -1
  43. package/dist/Editor/common/StyleBuilder/fieldTypes/bannerSpacing.js +100 -74
  44. package/dist/Editor/common/StyleBuilder/fieldTypes/borderRadius.js +41 -10
  45. package/dist/Editor/common/StyleBuilder/fieldTypes/buttonLink.js +3 -3
  46. package/dist/Editor/common/StyleBuilder/fieldTypes/color.js +27 -77
  47. package/dist/Editor/common/StyleBuilder/fieldTypes/fontSize.js +7 -5
  48. package/dist/Editor/common/StyleBuilder/fieldTypes/gridSize.js +19 -15
  49. package/dist/Editor/common/StyleBuilder/fieldTypes/icons.js +2 -2
  50. package/dist/Editor/common/StyleBuilder/fieldTypes/menusArray.js +2 -2
  51. package/dist/Editor/common/StyleBuilder/fieldTypes/radiusStyle.js +67 -8
  52. package/dist/Editor/common/StyleBuilder/fieldTypes/saveAsTemplate.js +2 -3
  53. package/dist/Editor/common/StyleBuilder/fieldTypes/text.js +21 -32
  54. package/dist/Editor/common/StyleBuilder/fieldTypes/textAlign.js +37 -41
  55. package/dist/Editor/common/StyleBuilder/fieldTypes/textOptions.js +26 -24
  56. package/dist/Editor/common/StyleBuilder/formStyle.js +0 -6
  57. package/dist/Editor/common/StyleBuilder/gridItemStyle.js +38 -54
  58. package/dist/Editor/common/StyleBuilder/gridStyle.js +20 -26
  59. package/dist/Editor/common/StyleBuilder/index.js +14 -58
  60. package/dist/Editor/common/StyleBuilder/sectionStyle.js +16 -0
  61. package/dist/Editor/common/Uploader.js +0 -4
  62. package/dist/Editor/helper/index.js +63 -1
  63. package/dist/Editor/utils/Decorators/index.js +5 -0
  64. package/dist/Editor/utils/Decorators/link.js +26 -0
  65. package/dist/Editor/utils/SlateUtilityFunctions.js +36 -8
  66. package/dist/Editor/utils/accordion.js +17 -4
  67. package/dist/Editor/utils/button.js +15 -1
  68. package/dist/Editor/utils/customHooks/useElement.js +28 -0
  69. package/dist/Editor/utils/embed.js +1 -7
  70. package/dist/Editor/utils/events.js +92 -43
  71. package/dist/Editor/utils/gridItem.js +1 -1
  72. package/dist/Editor/utils/link.js +10 -9
  73. package/package.json +1 -1
@@ -1,12 +1,11 @@
1
1
  /* eslint-disable no-unused-vars */
2
- import React, { useState, useEffect } from "react";
3
- import { Transforms, Path, Node } from "slate";
4
- import { useSelected, useSlateStatic, ReactEditor } from "slate-react";
2
+ import React, { useState } from "react";
3
+ import { Transforms, Path } from "slate";
4
+ import { useSlateStatic, ReactEditor } from "slate-react";
5
5
  import { IconButton, Tooltip, Grid as GridContainer } from "@mui/material";
6
6
  import ArrowUpwardIcon from "@mui/icons-material/ArrowUpward";
7
7
  import ArrowDownwardIcon from "@mui/icons-material/ArrowDownward";
8
8
  import KeyboardReturnIcon from "@mui/icons-material/KeyboardReturn";
9
- import TuneIcon from "@mui/icons-material/Tune";
10
9
  import { insertGrid } from "../../utils/grid";
11
10
  import { GridAddGridIcon, GridAddSectionIcon, GridSettingsIcon } from "../../common/iconslist";
12
11
  import GridPopup from "./GridPopup";
@@ -43,10 +42,6 @@ const Grid = props => {
43
42
  borderColor,
44
43
  borderStyle,
45
44
  borderRadius,
46
- sectionBgColor,
47
- sectionBackgroundImage,
48
- sectionBannerSpacing,
49
- sectionBorderRadius,
50
45
  gridSize
51
46
  } = element;
52
47
  const {
@@ -55,12 +50,6 @@ const Grid = props => {
55
50
  right,
56
51
  bottom
57
52
  } = bannerSpacing || {};
58
- const {
59
- left: ssleft,
60
- top: sstop,
61
- right: ssright,
62
- bottom: ssbottom
63
- } = sectionBannerSpacing || {};
64
53
  const {
65
54
  vertical,
66
55
  horizantal,
@@ -72,12 +61,6 @@ const Grid = props => {
72
61
  bottomLeft,
73
62
  bottomRight
74
63
  } = borderRadius || {};
75
- const {
76
- topLeft: ssTopLeft,
77
- topRight: ssTopRight,
78
- bottomLeft: ssBottomLeft,
79
- bottomRight: ssBottomRight
80
- } = sectionBorderRadius || {};
81
64
  const editor = useSlateStatic();
82
65
  const path = ReactEditor.findPath(editor, element);
83
66
  const {
@@ -108,9 +91,6 @@ const Grid = props => {
108
91
  });
109
92
  }
110
93
  };
111
- const onSectionSettings = () => {
112
- setOpenSettings("section");
113
- };
114
94
  const onSettings = () => {
115
95
  setOpenSettings("grid");
116
96
  };
@@ -228,13 +208,6 @@ const Grid = props => {
228
208
  className: "grid-container-toolbar",
229
209
  contentEditable: false,
230
210
  children: [/*#__PURE__*/_jsx(Tooltip, {
231
- title: "Section Settings",
232
- arrow: true,
233
- children: /*#__PURE__*/_jsx(IconButton, {
234
- onClick: onSectionSettings,
235
- children: /*#__PURE__*/_jsx(TuneIcon, {})
236
- })
237
- }), /*#__PURE__*/_jsx(Tooltip, {
238
211
  title: "Grid Settings",
239
212
  arrow: true,
240
213
  children: /*#__PURE__*/_jsx(IconButton, {
@@ -280,95 +253,75 @@ const Grid = props => {
280
253
  const bgImage = backgroundImage && backgroundImage !== "none" ? {
281
254
  backgroundImage: `url(${backgroundImage})`
282
255
  } : {};
283
- const sectionBgImage = sectionBackgroundImage && sectionBackgroundImage !== "none" ? {
284
- backgroundImage: `url(${sectionBackgroundImage})`
285
- } : {};
286
- return /*#__PURE__*/_jsx("section", {
287
- className: "section-wrapper-fluid",
256
+ return /*#__PURE__*/_jsxs(GridContainer, {
257
+ container: true,
258
+ className: `grid-container ${grid} has-hover element-root`,
259
+ ...attributes,
260
+ ...sectionId,
288
261
  style: {
289
- display: "flex",
290
- width: "100%",
291
- background: sectionBgColor,
292
- ...sectionBgImage,
293
- backgroundSize: "cover",
294
- justifyContent: "center",
295
- alignItems: "center",
296
- paddingLeft: `${ssleft}px`,
297
- paddingRight: `${ssright}px`,
298
- paddingTop: `${sstop}px`,
299
- paddingBottom: `${ssbottom}px`,
300
- borderRadius: `${ssTopLeft}px ${ssTopRight}px ${ssBottomLeft}px ${ssBottomRight}px`
262
+ background: bgColor,
263
+ alignContent: vertical,
264
+ ...bgImage,
265
+ borderColor: borderColor || "transparent",
266
+ borderWidth: borderWidth || "1px",
267
+ borderRadius: `${topLeft}px ${topRight}px ${bottomLeft}px ${bottomRight}px`,
268
+ borderStyle: borderStyle || "solid"
301
269
  },
302
- "data-path": path.join(","),
303
- children: /*#__PURE__*/_jsxs(GridContainer, {
304
- container: true,
305
- className: `grid-container ${grid} has-hover element-root`,
306
- ...attributes,
307
- ...sectionId,
270
+ "data-path": path.join(",")
271
+ // sx={{
272
+ // width: `${((gridSize || 12) / 12) * 100}%`,
273
+ // }}
274
+ ,
275
+ children: [fgColor && /*#__PURE__*/_jsx("div", {
308
276
  style: {
309
- background: bgColor,
310
- alignContent: vertical,
311
- ...bgImage,
312
- borderColor: borderColor || "transparent",
313
- borderWidth: borderWidth || "1px",
314
- borderRadius: `${topLeft}px ${topRight}px ${bottomLeft}px ${bottomRight}px`,
315
- borderStyle: borderStyle || "solid"
277
+ position: "absolute",
278
+ pointerEvents: "none",
279
+ width: "100%",
280
+ height: "100%",
281
+ background: fgColor,
282
+ backgroundRepeat: "no-repeat",
283
+ backgroundSize: "cover"
284
+ }
285
+ }), !readOnly && /*#__PURE__*/_jsxs("div", {
286
+ className: `element-selector ${selected ? "selected" : ""}`,
287
+ contentEditable: false,
288
+ children: [/*#__PURE__*/_jsx("div", {
289
+ className: "element-selector-dots tl",
290
+ children: " "
291
+ }), /*#__PURE__*/_jsx("div", {
292
+ className: "element-selector-dots tr",
293
+ children: " "
294
+ }), /*#__PURE__*/_jsx("div", {
295
+ className: "element-selector-dots bl",
296
+ children: " "
297
+ }), /*#__PURE__*/_jsx("div", {
298
+ className: "element-selector-dots br",
299
+ children: " "
300
+ }), /*#__PURE__*/_jsx(GridToolBar, {})]
301
+ }), openSetttings ? /*#__PURE__*/_jsx(PoupComp, {
302
+ element: element,
303
+ onSave: onSave,
304
+ onClose: onClose,
305
+ onDelete: onDelete,
306
+ customProps: customProps
307
+ }) : null, /*#__PURE__*/_jsx(GridContainer, {
308
+ item: true,
309
+ xs: 12,
310
+ className: "grid-c-wrpr",
311
+ style: {
312
+ display: "flex",
313
+ paddingLeft: `${left}px`,
314
+ paddingRight: `${right}px`,
315
+ paddingTop: `${top}px`,
316
+ paddingBottom: `${bottom}px`,
317
+ alignItems: vertical || "start",
318
+ justifyContent: horizantal || "start",
319
+ flexDirection: flexDirection || "row",
320
+ width: "100%"
316
321
  },
317
322
  "data-path": path.join(","),
318
- sx: {
319
- width: `${(gridSize || 8) / 12 * 100}%`
320
- },
321
- children: [fgColor && /*#__PURE__*/_jsx("div", {
322
- style: {
323
- position: "absolute",
324
- pointerEvents: "none",
325
- width: "100%",
326
- height: "100%",
327
- background: fgColor,
328
- backgroundRepeat: "no-repeat",
329
- backgroundSize: "cover"
330
- }
331
- }), !readOnly && /*#__PURE__*/_jsxs("div", {
332
- className: `element-selector ${selected ? "selected" : ""}`,
333
- contentEditable: false,
334
- children: [/*#__PURE__*/_jsx("div", {
335
- className: "element-selector-dots tl",
336
- children: " "
337
- }), /*#__PURE__*/_jsx("div", {
338
- className: "element-selector-dots tr",
339
- children: " "
340
- }), /*#__PURE__*/_jsx("div", {
341
- className: "element-selector-dots bl",
342
- children: " "
343
- }), /*#__PURE__*/_jsx("div", {
344
- className: "element-selector-dots br",
345
- children: " "
346
- }), /*#__PURE__*/_jsx(GridToolBar, {})]
347
- }), openSetttings ? /*#__PURE__*/_jsx(PoupComp, {
348
- element: element,
349
- onSave: onSave,
350
- onClose: onClose,
351
- onDelete: onDelete,
352
- customProps: customProps
353
- }) : null, /*#__PURE__*/_jsx(GridContainer, {
354
- item: true,
355
- xs: 12,
356
- className: "grid-c-wrpr",
357
- style: {
358
- display: "flex",
359
- paddingLeft: `${left}px`,
360
- paddingRight: `${right}px`,
361
- paddingTop: `${top}px`,
362
- paddingBottom: `${bottom}px`,
363
- alignItems: vertical || "start",
364
- justifyContent: horizantal || "start",
365
- flexDirection: flexDirection || "row",
366
- width: "100%"
367
- },
368
- "data-path": path.join(","),
369
- children: children
370
- }), /*#__PURE__*/_jsx(NewLineButtons, {})]
371
- })
323
+ children: children
324
+ }), /*#__PURE__*/_jsx(NewLineButtons, {})]
372
325
  });
373
326
  };
374
327
  export default Grid;
@@ -53,8 +53,6 @@ const GridItem = props => {
53
53
  bottomRight
54
54
  } = borderRadius || {};
55
55
  const editor = useSlateStatic();
56
- // const selected = useSelected();
57
- // const [selected, setSelected] = useState(false);
58
56
  const itemWidth = (grid || 6) / 12 * 100;
59
57
  const path = ReactEditor.findPath(editor, element);
60
58
  const {
@@ -104,24 +102,11 @@ const GridItem = props => {
104
102
  });
105
103
  }
106
104
  };
107
-
108
- // const onMouseOver = (e) => {
109
- // if (!readOnly) {
110
- // e.stopPropagation();
111
- // setSelected(true);
112
- // }
113
- // };
114
-
115
- // const onMouseLeave = (e) => {
116
- // if (!readOnly) {
117
- // e.stopPropagation();
118
- // setSelected(false);
119
- // }
120
- // };
121
-
122
- return /*#__PURE__*/_jsxs(Box, {
105
+ return /*#__PURE__*/_jsxs(Item, {
106
+ item: true,
107
+ xs: grid,
123
108
  component: "div",
124
- className: `grid-item xs-${grid} element-root gi-top-wrpr`,
109
+ className: `grid-item xs-${grid} element-root gi-top-wrpr content-editable`,
125
110
  ...attributes,
126
111
  sx: {
127
112
  display: "flex",
@@ -143,10 +128,11 @@ const GridItem = props => {
143
128
  },
144
129
  height: "100%"
145
130
  },
146
- "data-path": path.join(",")
147
- // onMouseOver={onMouseOver}
148
- // onMouseLeave={onMouseLeave}
149
- ,
131
+ "data-path": path.join(","),
132
+ style: {
133
+ textAlign: element.alignment || "left"
134
+ },
135
+ placeholder: "Grid Item",
150
136
  children: [!readOnly && /*#__PURE__*/_jsxs("div", {
151
137
  className: `element-selector ${selected ? "selected" : ""}`,
152
138
  contentEditable: false,
@@ -34,24 +34,6 @@ const default_grid = [{
34
34
  fontFamily: "PoppinsRegular",
35
35
  text: ""
36
36
  }]
37
- }, {
38
- type: "paragraph",
39
- children: [{
40
- type: "image",
41
- url: "https://developers.elementor.com/docs/assets/img/elementor-placeholder-image.png",
42
- images: [],
43
- children: [{
44
- text: " "
45
- }],
46
- size: {
47
- width: 362.59375,
48
- height: 207,
49
- widthInPercent: 56.780034254954735
50
- },
51
- alignment: {
52
- horizantal: "center"
53
- }
54
- }]
55
37
  }, {
56
38
  type: "paragraph",
57
39
  children: [{
@@ -85,11 +67,6 @@ const default_grid = [{
85
67
  children: [{
86
68
  type: "alignLeft",
87
69
  children: [{
88
- type: "paragraph",
89
- children: [{
90
- text: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."
91
- }]
92
- }, {
93
70
  type: "paragraph",
94
71
  children: [{
95
72
  text: ""
@@ -1,11 +1,12 @@
1
- import React from "react";
2
- import { useFocused, useSelected, useSlateStatic } from "slate-react";
1
+ import React, { useState } from "react";
2
+ import { Node, Transforms } from "slate";
3
+ import { ReactEditor, useFocused, useSelected, useSlateStatic } from "slate-react";
3
4
  import { IconButton, Tooltip } from "@mui/material";
4
5
  import OpenInNewIcon from "@mui/icons-material/OpenInNew";
6
+ import EditIcon from "@mui/icons-material/Edit";
5
7
  import LinkOffIcon from "@mui/icons-material/LinkOff";
6
- import { insertDefaultEmbed } from "../../utils/embed";
7
- import { getQueryStrings } from "../../utils/SlateUtilityFunctions";
8
8
  import { removeLink } from "../../utils/link";
9
+ import LinkPopup from "./LinkPopup";
9
10
  import "./styles.css";
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
11
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -17,21 +18,46 @@ const Link = ({
17
18
  const editor = useSlateStatic();
18
19
  const selected = useSelected();
19
20
  const focused = useFocused();
20
- let refUrl = element.href ? element.href : element.url;
21
- refUrl = refUrl ? refUrl.includes("http") ? refUrl : `//${refUrl}` : "Link";
22
- let embedUrl = refUrl;
23
-
24
- // const urlMatch = embedUrl.match(regex);
25
- // embedUrl = urlMatch && urlMatch.length > 0 ? urlMatch[0] : '';
26
- if (embedUrl.includes("youtube")) embedUrl = getQueryStrings(embedUrl); //embedUrl.replace(/\/watch\?v=/g, '/embed/')
27
- if (embedUrl.includes("youtu.be")) embedUrl = getQueryStrings(embedUrl); //embedUrl.replace(/youtu.be\//, 'youtube.com/embed/')
28
- // Others
29
- if (embedUrl.includes("loom")) embedUrl = embedUrl.replace(/\/share\//, "/embed/");
30
- if (embedUrl.includes("vimeo")) embedUrl = embedUrl.replace(/\/vimeo.com\//, "/player.vimeo.com/video/");
31
- if (embedUrl.includes("dailymotion") && embedUrl.includes("video")) embedUrl = embedUrl.replace(/www.dailymotion.com\//, "www.dailymotion.com/embed/");
32
- if (embedUrl.includes("dai.ly")) embedUrl = embedUrl.replace(/dai.ly\//, "www.dailymotion.com/embed/video/");
33
- const embedDoc = () => {
34
- insertDefaultEmbed(editor, "video", element.href);
21
+ const [showInput, setShowInput] = useState(false);
22
+ const [linkData, setLinkData] = useState({
23
+ name: "",
24
+ url: "",
25
+ showInNewTab: true
26
+ });
27
+ const path = ReactEditor.findPath(editor, element);
28
+ const updateLink = () => {
29
+ Transforms.setNodes(editor, {
30
+ href: linkData?.url,
31
+ showInNewTab: linkData?.showInNewTab
32
+ }, {
33
+ at: path
34
+ });
35
+ setLinkData({
36
+ name: "",
37
+ url: "",
38
+ showInNewTab: true
39
+ });
40
+ setShowInput(false);
41
+ };
42
+ const onEditLink = () => {
43
+ setLinkData({
44
+ name: Node.string(element),
45
+ url: element?.href || "",
46
+ showInNewTab: true
47
+ });
48
+ setShowInput(true);
49
+ };
50
+ const handleInputChange = ({
51
+ target
52
+ }) => {
53
+ let val = target.type === "checkbox" ? target.checked : target.value;
54
+ setLinkData({
55
+ ...linkData,
56
+ [target.name]: val
57
+ });
58
+ };
59
+ const handleClose = () => {
60
+ setShowInput(false);
35
61
  };
36
62
  const Toolbar = () => {
37
63
  return selected && focused ? /*#__PURE__*/_jsxs("div", {
@@ -49,6 +75,12 @@ const Link = ({
49
75
  target: element.target,
50
76
  children: /*#__PURE__*/_jsx(OpenInNewIcon, {})
51
77
  })
78
+ }), /*#__PURE__*/_jsx(Tooltip, {
79
+ title: "Edit",
80
+ children: /*#__PURE__*/_jsx(IconButton, {
81
+ onClick: onEditLink,
82
+ children: /*#__PURE__*/_jsx(EditIcon, {})
83
+ })
52
84
  }), /*#__PURE__*/_jsx(Tooltip, {
53
85
  title: "Remove",
54
86
  children: /*#__PURE__*/_jsx(IconButton, {
@@ -66,7 +98,13 @@ const Link = ({
66
98
  ...element.attr,
67
99
  target: element.target,
68
100
  children: children
69
- }), /*#__PURE__*/_jsx(Toolbar, {})]
101
+ }), /*#__PURE__*/_jsx(Toolbar, {}), /*#__PURE__*/_jsx(LinkPopup, {
102
+ open: showInput,
103
+ linkData: linkData,
104
+ handleClose: handleClose,
105
+ handleInputChange: handleInputChange,
106
+ handleInsertLink: updateLink
107
+ })]
70
108
  });
71
109
  };
72
110
  export default Link;
@@ -1,14 +1,10 @@
1
1
  import { useRef, useState } from "react";
2
- import { Transforms } from "slate";
3
- import { Dialog, DialogActions, DialogContent, DialogTitle, FormControl, FormControlLabel, Grid, TextField, Button, IconButton, Typography, Checkbox, Tooltip
4
- // styled,
5
- } from "@mui/material";
6
- // import { styled } from "@mui/material/styles";
7
- import CloseIcon from "@mui/icons-material/Close";
2
+ import { Editor, Transforms } from "slate";
3
+ import { IconButton, Tooltip } from "@mui/material";
8
4
  import { insertLink } from "../../utils/link";
9
5
  import Icon from "../../common/Icon";
10
- import { isBlockActive } from "../../utils/SlateUtilityFunctions";
11
- // import styled from "@emotion/styled";
6
+ import { getBlockActive } from "../../utils/SlateUtilityFunctions";
7
+ import LinkPopup from "./LinkPopup";
12
8
  import { jsx as _jsx } from "react/jsx-runtime";
13
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
14
10
  const LinkButton = props => {
@@ -17,31 +13,45 @@ const LinkButton = props => {
17
13
  } = props;
18
14
  const linkInputRef = useRef(null);
19
15
  const [showInput, setShowInput] = useState(false);
20
- const [url, setUrl] = useState("");
21
- const [showInNewTab, setShowInNewTab] = useState(false);
16
+ const [linkData, setLinkData] = useState({
17
+ name: "",
18
+ url: "",
19
+ showInNewTab: true
20
+ });
22
21
  const [selection, setSelection] = useState();
22
+ const {
23
+ isActive,
24
+ props: blockProps
25
+ } = getBlockActive(editor, "link");
23
26
  const handleInsertLink = () => {
24
27
  Transforms.select(editor, selection);
25
28
  insertLink(editor, {
26
- url,
27
- showInNewTab
29
+ ...linkData
30
+ });
31
+ setLinkData({
32
+ name: "",
33
+ url: "",
34
+ showInNewTab: true
28
35
  });
29
- setUrl("");
30
36
  setShowInput(false);
31
- setShowInNewTab(false);
32
37
  };
33
38
  const toggleLink = () => {
34
39
  setSelection(editor.selection);
40
+ setLinkData({
41
+ name: Editor.string(editor, editor.selection),
42
+ url: blockProps?.href || "",
43
+ showInNewTab: true
44
+ });
35
45
  setShowInput(true);
36
46
  };
37
47
  const handleInputChange = ({
38
48
  target
39
49
  }) => {
40
- if (target.type === "checkbox") {
41
- setShowInNewTab(target.checked);
42
- } else {
43
- setUrl(target.value);
44
- }
50
+ let val = target.type === "checkbox" ? target.checked : target.value;
51
+ setLinkData({
52
+ ...linkData,
53
+ [target.name]: val
54
+ });
45
55
  };
46
56
  const handleClose = () => {
47
57
  setShowInput(false);
@@ -53,90 +63,20 @@ const LinkButton = props => {
53
63
  title: "Link",
54
64
  arrow: true,
55
65
  children: /*#__PURE__*/_jsx(IconButton, {
56
- className: showInput ? "clicked" : "",
57
- active: isBlockActive(editor, "link") ? "active" : "",
66
+ className: `${showInput ? "clicked" : ""} ${isActive ? "btnActive" : ""}`,
58
67
  format: "link",
59
68
  onClick: toggleLink,
60
69
  children: /*#__PURE__*/_jsx(Icon, {
61
70
  icon: "link"
62
71
  })
63
72
  })
64
- }), showInput && /*#__PURE__*/_jsxs(Dialog, {
65
- fullWidth: true,
66
- open: true,
67
- className: `dialogComp`,
68
- children: [/*#__PURE__*/_jsx(DialogTitle, {
69
- children: /*#__PURE__*/_jsxs("div", {
70
- style: {
71
- display: "flex",
72
- justifyContent: "space-between"
73
- },
74
- children: [/*#__PURE__*/_jsx(Typography, {
75
- variant: "h6",
76
- className: "popupTitle",
77
- color: "primary",
78
- children: "LINK"
79
- }), /*#__PURE__*/_jsx("div", {
80
- style: {
81
- display: "flex"
82
- },
83
- children: /*#__PURE__*/_jsx(IconButton, {
84
- onClick: handleClose,
85
- className: "close-popupbtn",
86
- children: /*#__PURE__*/_jsx(CloseIcon, {})
87
- })
88
- })]
89
- })
90
- }), /*#__PURE__*/_jsxs(DialogContent, {
91
- children: [/*#__PURE__*/_jsx(Grid, {
92
- item: true,
93
- xs: 12,
94
- style: {
95
- paddingTop: "12px"
96
- },
97
- children: /*#__PURE__*/_jsx(TextField, {
98
- size: "small",
99
- fullWidth: true,
100
- value: url,
101
- placeholder: "https://google.com",
102
- onChange: handleInputChange
103
- })
104
- }), /*#__PURE__*/_jsx(Grid, {
105
- item: true,
106
- xs: 12,
107
- sx: {
108
- ml: 1
109
- },
110
- children: /*#__PURE__*/_jsx(FormControl, {
111
- children: /*#__PURE__*/_jsx(FormControlLabel, {
112
- control: /*#__PURE__*/_jsx(Checkbox, {
113
- checked: showInNewTab,
114
- onChange: handleInputChange
115
- }),
116
- label: /*#__PURE__*/_jsx(Typography, {
117
- variant: "body1",
118
- color: "primary",
119
- sx: {
120
- pl: 1
121
- },
122
- children: "Open in new tab"
123
- })
124
- })
125
- })
126
- })]
127
- }), /*#__PURE__*/_jsxs(DialogActions, {
128
- children: [/*#__PURE__*/_jsx(Button, {
129
- onClick: handleClose,
130
- className: "secondaryBtn",
131
- children: "Cancel"
132
- }), /*#__PURE__*/_jsx(Button, {
133
- onClick: handleInsertLink,
134
- className: "primaryBtn",
135
- children: "Add"
136
- })]
137
- })]
73
+ }), /*#__PURE__*/_jsx(LinkPopup, {
74
+ open: showInput,
75
+ linkData: linkData,
76
+ handleClose: handleClose,
77
+ handleInputChange: handleInputChange,
78
+ handleInsertLink: handleInsertLink
138
79
  })]
139
80
  });
140
81
  };
141
- export default LinkButton;
142
- // export default styled(commonStyle)(LinkButton);
82
+ export default LinkButton;