@flozy/editor 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -84,7 +84,7 @@ const CommonEditor = props => {
84
84
  const isAstChange = editor.operations.some(op => "set_selection" !== op.type);
85
85
  if (isAstChange && onSave) {
86
86
  // send the value to onSave api
87
- onSave(JSON.stringify(value));
87
+ onSave(JSON.stringify(newValue));
88
88
  }
89
89
  };
90
90
  const customProps = {
@@ -0,0 +1,221 @@
1
+ import React, { useState } from "react";
2
+ import { useSlateStatic, ReactEditor } from "slate-react";
3
+ import { Transforms } from "slate";
4
+ import AppBar from "@mui/material/AppBar";
5
+ import Box from "@mui/material/Box";
6
+ import CssBaseline from "@mui/material/CssBaseline";
7
+ import Divider from "@mui/material/Divider";
8
+ import Drawer from "@mui/material/Drawer";
9
+ import IconButton from "@mui/material/IconButton";
10
+ import List from "@mui/material/List";
11
+ import ListItem from "@mui/material/ListItem";
12
+ import ListItemButton from "@mui/material/ListItemButton";
13
+ import ListItemText from "@mui/material/ListItemText";
14
+ import MenuIcon from "@mui/icons-material/Menu";
15
+ import Toolbar from "@mui/material/Toolbar";
16
+ import Typography from "@mui/material/Typography";
17
+ import Button from "@mui/material/Button";
18
+ import SettingsIcon from "@mui/icons-material/Settings";
19
+ import DeleteIcon from "@mui/icons-material/Delete";
20
+ import AppHeaderPopup from "./AppHeaderPopup";
21
+ import { jsx as _jsx } from "react/jsx-runtime";
22
+ import { jsxs as _jsxs } from "react/jsx-runtime";
23
+ const drawerWidth = 240;
24
+ function AppHeader(props) {
25
+ const [openSetttings, setOpenSettings] = useState(false);
26
+ const {
27
+ attributes,
28
+ element,
29
+ customProps
30
+ } = props;
31
+ const {
32
+ appTitle,
33
+ appLogo,
34
+ menus,
35
+ bgColor,
36
+ menuStyle
37
+ } = element;
38
+ const {
39
+ window
40
+ } = props;
41
+ const [mobileOpen, setMobileOpen] = React.useState(false);
42
+ const editor = useSlateStatic();
43
+ const path = ReactEditor.findPath(editor, element);
44
+ const isDrawer = menuStyle === "drawer";
45
+ const handleDrawerToggle = () => {
46
+ setMobileOpen(prevState => !prevState);
47
+ };
48
+ const onSettings = () => {
49
+ setOpenSettings(true);
50
+ };
51
+ const ToolBar = () => {
52
+ return customProps?.readOnly !== true ? /*#__PURE__*/_jsxs("div", {
53
+ className: "element-toolbar",
54
+ contentEditable: false,
55
+ style: {
56
+ top: "-38px"
57
+ },
58
+ children: [/*#__PURE__*/_jsx(IconButton, {
59
+ size: "small",
60
+ onClick: onSettings,
61
+ children: /*#__PURE__*/_jsx(SettingsIcon, {})
62
+ }), /*#__PURE__*/_jsx(IconButton, {
63
+ size: "small",
64
+ onClick: onDelete,
65
+ children: /*#__PURE__*/_jsx(DeleteIcon, {})
66
+ })]
67
+ }) : null;
68
+ };
69
+ const onSave = data => {
70
+ const updateData = {
71
+ ...data
72
+ };
73
+ delete updateData.children;
74
+ Transforms.setNodes(editor, updateData, {
75
+ at: path
76
+ });
77
+ onClose();
78
+ };
79
+ const onDelete = () => {
80
+ Transforms.removeNodes(editor, {
81
+ at: path
82
+ });
83
+ };
84
+ const onClose = () => {
85
+ setOpenSettings(false);
86
+ };
87
+ const drawer = /*#__PURE__*/_jsxs(Box, {
88
+ onClick: handleDrawerToggle,
89
+ sx: {
90
+ textAlign: "center"
91
+ },
92
+ children: [/*#__PURE__*/_jsx(Typography, {
93
+ variant: "h6",
94
+ sx: {
95
+ my: 2
96
+ },
97
+ children: appLogo && appLogo !== "none" ? /*#__PURE__*/_jsx("img", {
98
+ alt: `${appTitle} Logo`,
99
+ style: {
100
+ height: "40px",
101
+ width: "auto"
102
+ },
103
+ src: appLogo
104
+ }) : appTitle
105
+ }), /*#__PURE__*/_jsx(Divider, {}), /*#__PURE__*/_jsx(List, {
106
+ children: menus.map(item => /*#__PURE__*/_jsx(ListItem, {
107
+ disablePadding: true,
108
+ children: /*#__PURE__*/_jsx(ListItemButton, {
109
+ sx: {
110
+ textAlign: "center"
111
+ },
112
+ children: /*#__PURE__*/_jsx(ListItemText, {
113
+ primary: item.text
114
+ })
115
+ })
116
+ }, item.text))
117
+ })]
118
+ });
119
+ const container = window !== undefined ? () => window().document.body : undefined;
120
+ return /*#__PURE__*/_jsxs(Box, {
121
+ sx: {
122
+ display: "flex",
123
+ position: "relative"
124
+ },
125
+ ...attributes,
126
+ contentEditable: false,
127
+ children: [/*#__PURE__*/_jsx(CssBaseline, {}), /*#__PURE__*/_jsx(AppBar, {
128
+ component: "nav",
129
+ style: {
130
+ position: "relative",
131
+ background: bgColor
132
+ },
133
+ children: /*#__PURE__*/_jsxs(Toolbar, {
134
+ children: [/*#__PURE__*/_jsx(IconButton, {
135
+ color: "inherit",
136
+ "aria-label": "open drawer",
137
+ edge: "start",
138
+ onClick: handleDrawerToggle,
139
+ sx: {
140
+ mr: 2,
141
+ display: {
142
+ sm: "none"
143
+ }
144
+ },
145
+ children: /*#__PURE__*/_jsx(MenuIcon, {})
146
+ }), /*#__PURE__*/_jsxs(Typography, {
147
+ variant: "h6",
148
+ component: "div",
149
+ style: {
150
+ display: "inline-flex",
151
+ alignItems: "center"
152
+ },
153
+ sx: {
154
+ flexGrow: 1,
155
+ display: {
156
+ xs: "none",
157
+ sm: "block"
158
+ }
159
+ },
160
+ children: [appLogo && appLogo !== "none" ? /*#__PURE__*/_jsx("img", {
161
+ alt: `${appTitle} Logo`,
162
+ style: {
163
+ height: "40px",
164
+ width: "auto"
165
+ },
166
+ src: appLogo
167
+ }) : null, "\xA0", appTitle]
168
+ }), /*#__PURE__*/_jsxs(Box, {
169
+ sx: {
170
+ display: {
171
+ xs: "none",
172
+ sm: "block"
173
+ }
174
+ },
175
+ children: [isDrawer ? /*#__PURE__*/_jsx(IconButton, {
176
+ color: "inherit",
177
+ "aria-label": "open drawer",
178
+ edge: "start",
179
+ onClick: handleDrawerToggle,
180
+ children: /*#__PURE__*/_jsx(MenuIcon, {})
181
+ }) : null, !isDrawer ? menus.map(item => /*#__PURE__*/_jsx(Button, {
182
+ component: "a",
183
+ href: item.href,
184
+ sx: {
185
+ color: "#fff"
186
+ },
187
+ children: item.text
188
+ }, item)) : null]
189
+ })]
190
+ })
191
+ }), /*#__PURE__*/_jsx("nav", {
192
+ children: /*#__PURE__*/_jsx(Drawer, {
193
+ container: container,
194
+ variant: "temporary",
195
+ open: mobileOpen,
196
+ onClose: handleDrawerToggle,
197
+ ModalProps: {
198
+ keepMounted: true // Better open performance on mobile.
199
+ },
200
+
201
+ sx: {
202
+ display: {
203
+ xs: "block",
204
+ sm: isDrawer ? "block" : "none"
205
+ },
206
+ "& .MuiDrawer-paper": {
207
+ boxSizing: "border-box",
208
+ width: drawerWidth
209
+ }
210
+ },
211
+ children: drawer
212
+ })
213
+ }), /*#__PURE__*/_jsx(ToolBar, {}), openSetttings ? /*#__PURE__*/_jsx(AppHeaderPopup, {
214
+ element: element,
215
+ onSave: onSave,
216
+ onClose: onClose,
217
+ customProps: customProps
218
+ }) : null]
219
+ });
220
+ }
221
+ export default AppHeader;
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import { IconButton } from "@mui/material";
3
+ import ViewDayIcon from "@mui/icons-material/ViewDay";
4
+ import { insertAppHeader } from "../../utils/insertAppHeader";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ const AppHeaderButton = props => {
7
+ const {
8
+ editor
9
+ } = props;
10
+ const handleClick = () => {
11
+ insertAppHeader(editor, {});
12
+ };
13
+ return /*#__PURE__*/_jsx(IconButton, {
14
+ title: "App Header",
15
+ onClick: handleClick,
16
+ children: /*#__PURE__*/_jsx(ViewDayIcon, {})
17
+ });
18
+ };
19
+ export default AppHeaderButton;
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ import StyleBuilder from "../../common/StyleBuilder";
3
+ import appHeaderStyle from "../../common/StyleBuilder/appHeaderStyle";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ const AppHeaderPopup = props => {
6
+ const {
7
+ element,
8
+ onSave,
9
+ onClose
10
+ } = props;
11
+ return /*#__PURE__*/_jsx(StyleBuilder, {
12
+ title: "App Header",
13
+ type: "gridItemStyle",
14
+ element: element,
15
+ onSave: onSave,
16
+ onClose: onClose,
17
+ renderTabs: appHeaderStyle
18
+ });
19
+ };
20
+ export default AppHeaderPopup;
@@ -26,7 +26,6 @@ const Carousel = props => {
26
26
  const selected = useSelected();
27
27
  const [edit, setEdit] = useState(false);
28
28
  const [reload, setReload] = useState(new Date().getTime());
29
- const path = ReactEditor.findPath(editor, element);
30
29
  const settings = {
31
30
  dots: true,
32
31
  infinite: true,
@@ -58,6 +57,7 @@ const Carousel = props => {
58
57
  }
59
58
  };
60
59
  const onDelete = () => {
60
+ const path = ReactEditor.findPath(editor, element);
61
61
  Transforms.removeNodes(editor, {
62
62
  at: [...path]
63
63
  });
@@ -5,22 +5,23 @@ import ArticleIcon from "@mui/icons-material/Article";
5
5
  import { useSlateStatic, ReactEditor } from "slate-react";
6
6
  import PageSettingsPopup from "./PageSettingsPopup";
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
+ import { Fragment as _Fragment } from "react/jsx-runtime";
8
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
9
10
  const PageSettingsButton = props => {
10
11
  const {
11
12
  customProps
12
13
  } = props;
13
14
  const [openSetttings, setOpenSettings] = useState(false);
14
- const [pageProps, setPageProps] = useState({});
15
15
  const editor = useSlateStatic();
16
16
  const onSettings = () => {
17
17
  const {
18
- element
18
+ element,
19
+ path
19
20
  } = getPageSettingsPath();
20
- if (element) {
21
- setPageProps(element?.pageProps || {});
22
- setOpenSettings(true);
23
- }
21
+ setOpenSettings({
22
+ element: element?.pageProps || {},
23
+ path
24
+ });
24
25
  };
25
26
  const getPageSettingsPath = () => {
26
27
  try {
@@ -30,11 +31,17 @@ const PageSettingsButton = props => {
30
31
  return !Editor.isEditor(n) && Element.isElement(n) && n.type === "page-settings";
31
32
  }
32
33
  });
33
- const path = ReactEditor.findPath(editor, pageSettingsNode[0]);
34
- return {
35
- path,
36
- element: pageSettingsNode[0]
37
- };
34
+ if (pageSettingsNode && pageSettingsNode[0]) {
35
+ const path = ReactEditor.findPath(editor, pageSettingsNode[0]);
36
+ return {
37
+ path,
38
+ element: pageSettingsNode[0]
39
+ };
40
+ } else {
41
+ return {
42
+ path: null
43
+ };
44
+ }
38
45
  } catch (err) {
39
46
  console.log(err);
40
47
  return {
@@ -43,20 +50,17 @@ const PageSettingsButton = props => {
43
50
  }
44
51
  };
45
52
  const onSave = data => {
46
- const {
47
- path
48
- } = getPageSettingsPath();
49
53
  const updateData = {
50
54
  ...data
51
55
  };
52
56
  delete updateData.children;
53
- if (path) {
57
+ if (openSetttings?.path) {
54
58
  Transforms.setNodes(editor, {
55
59
  pageProps: {
56
60
  ...updateData
57
61
  }
58
62
  }, {
59
- at: path
63
+ at: openSetttings?.path
60
64
  });
61
65
  } else {
62
66
  Transforms.insertNodes(editor, [{
@@ -74,11 +78,13 @@ const PageSettingsButton = props => {
74
78
  const onClose = () => {
75
79
  setOpenSettings(false);
76
80
  };
77
- return /*#__PURE__*/_jsxs(IconButton, {
78
- title: "Page Settings",
79
- onClick: onSettings,
80
- children: [/*#__PURE__*/_jsx(ArticleIcon, {}), openSetttings ? /*#__PURE__*/_jsx(PageSettingsPopup, {
81
- element: pageProps,
81
+ return /*#__PURE__*/_jsxs(_Fragment, {
82
+ children: [/*#__PURE__*/_jsx(IconButton, {
83
+ title: "Page Settings",
84
+ onClick: onSettings,
85
+ children: /*#__PURE__*/_jsx(ArticleIcon, {})
86
+ }), openSetttings !== false ? /*#__PURE__*/_jsx(PageSettingsPopup, {
87
+ element: openSetttings?.element || {},
82
88
  onSave: onSave,
83
89
  onClose: onClose,
84
90
  customProps: customProps
@@ -25,6 +25,7 @@ import PageSettingsButton from "../Elements/PageSettings/PageSettingsButton";
25
25
  import CarouselButton from "../Elements/Carousel/CarouselButton";
26
26
  import ChipTextButton from "../Elements/ChipText/ChipTextButton";
27
27
  import DrawerMenuButton from "../Elements/DrawerMenu/DrawerMenuButton";
28
+ import AppHeaderButton from "../Elements/AppHeader/AppHeaderButton";
28
29
  import { jsx as _jsx } from "react/jsx-runtime";
29
30
  import { jsxs as _jsxs } from "react/jsx-runtime";
30
31
  const Toolbar = props => {
@@ -198,6 +199,11 @@ const Toolbar = props => {
198
199
  editor: editor,
199
200
  customProps: customProps
200
201
  }, element.id);
202
+ case "app-header":
203
+ return /*#__PURE__*/_jsx(AppHeaderButton, {
204
+ editor: editor,
205
+ customProps: customProps
206
+ }, element.id);
201
207
  default:
202
208
  return null;
203
209
  }
@@ -131,5 +131,8 @@ const toolbarGroups = [[{
131
131
  }, {
132
132
  id: 36,
133
133
  type: "drawer"
134
+ }, {
135
+ id: 37,
136
+ type: "app-header"
134
137
  }]];
135
138
  export default toolbarGroups;
@@ -0,0 +1,63 @@
1
+ const appHeaderStyle = [{
2
+ tab: "Logo",
3
+ value: "appLogo",
4
+ fields: [{
5
+ label: "App Logo URL",
6
+ key: "appLogo",
7
+ type: "text"
8
+ }, {
9
+ label: "App Logo",
10
+ key: "appLogo",
11
+ type: "backgroundImage"
12
+ }]
13
+ }, {
14
+ tab: "Title",
15
+ value: "appTitle",
16
+ fields: [{
17
+ label: "App Title",
18
+ key: "appTitle",
19
+ type: "text"
20
+ }]
21
+ }, {
22
+ tab: "Menus",
23
+ value: "menus",
24
+ fields: [{
25
+ label: "Menus",
26
+ key: "menus",
27
+ type: "menusArray"
28
+ }]
29
+ }, {
30
+ tab: "Banner Spacing",
31
+ value: "bannerSpacing",
32
+ fields: [{
33
+ label: "Banner Spacing",
34
+ key: "bannerSpacing",
35
+ type: "bannerSpacing"
36
+ }]
37
+ }, {
38
+ tab: "Border Radius",
39
+ value: "borderRadius",
40
+ fields: [{
41
+ label: "Border Radius",
42
+ key: "borderRadius",
43
+ type: "borderRadius"
44
+ }]
45
+ }, {
46
+ tab: "Colors",
47
+ value: "colors",
48
+ fields: [{
49
+ label: "Text",
50
+ key: "textColor",
51
+ type: "color",
52
+ needPreview: true
53
+ }, {
54
+ label: "Background",
55
+ key: "bgColor",
56
+ type: "color"
57
+ }, {
58
+ label: "Border",
59
+ key: "borderColor",
60
+ type: "color"
61
+ }]
62
+ }];
63
+ export default appHeaderStyle;
@@ -7,6 +7,7 @@ import BackgroundImage from "./backgroundImage";
7
7
  import GridSize from "./gridSize";
8
8
  import ElementSize from "./elementSize";
9
9
  import ImageTexts from "./imageTexts";
10
+ import MenusArray from "./menusArray";
10
11
  const FieldMap = {
11
12
  text: Text,
12
13
  bannerSpacing: BannerSpacing,
@@ -16,6 +17,7 @@ const FieldMap = {
16
17
  backgroundImage: BackgroundImage,
17
18
  gridSize: GridSize,
18
19
  elementSize: ElementSize,
19
- imageTexts: ImageTexts
20
+ imageTexts: ImageTexts,
21
+ menusArray: MenusArray
20
22
  };
21
23
  export default FieldMap;
@@ -0,0 +1,114 @@
1
+ import React from "react";
2
+ import { Button, Grid, Radio, RadioGroup, TextField, FormControl, FormLabel, FormControlLabel } from "@mui/material";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ import { jsxs as _jsxs } from "react/jsx-runtime";
5
+ const MenusArray = props => {
6
+ const {
7
+ value,
8
+ data,
9
+ elementProps,
10
+ onChange
11
+ } = props;
12
+ const {
13
+ key
14
+ } = data;
15
+ const {
16
+ menuStyle
17
+ } = elementProps || {
18
+ menuStyle: "stacked"
19
+ };
20
+ const handleChange = index => e => {
21
+ const upValue = [...(value || [])];
22
+ upValue[index] = {
23
+ ...(upValue[index] || {}),
24
+ [e.target.name]: e.target.value
25
+ };
26
+ onChange({
27
+ [key]: upValue
28
+ });
29
+ };
30
+ const onAddMenu = () => {
31
+ onChange({
32
+ [key]: [...value, {
33
+ ...value[0]
34
+ }]
35
+ });
36
+ };
37
+ const onDelete = index => () => {
38
+ const upValue = [...(value || [])];
39
+ upValue.splice(index, 1);
40
+ onChange({
41
+ [key]: upValue
42
+ });
43
+ };
44
+ const handleVariant = e => {
45
+ onChange({
46
+ [e.target.name]: e.target.value
47
+ });
48
+ };
49
+ return /*#__PURE__*/_jsxs(Grid, {
50
+ container: true,
51
+ padding: 1,
52
+ spacing: 2,
53
+ children: [/*#__PURE__*/_jsx(Grid, {
54
+ item: true,
55
+ xs: 12,
56
+ children: /*#__PURE__*/_jsxs(FormControl, {
57
+ children: [/*#__PURE__*/_jsx(FormLabel, {
58
+ id: "demo-radio-buttons-group-label",
59
+ children: "Menu Variant"
60
+ }), /*#__PURE__*/_jsxs(RadioGroup, {
61
+ row: true,
62
+ "aria-labelledby": "demo-radio-buttons-group-label",
63
+ defaultValue: menuStyle,
64
+ value: menuStyle,
65
+ name: "menuStyle",
66
+ onChange: handleVariant,
67
+ children: [/*#__PURE__*/_jsx(FormControlLabel, {
68
+ value: "stacked",
69
+ checked: menuStyle === "stacked",
70
+ control: /*#__PURE__*/_jsx(Radio, {}),
71
+ label: "Stacked"
72
+ }), /*#__PURE__*/_jsx(FormControlLabel, {
73
+ value: "drawer",
74
+ checked: menuStyle === "drawer",
75
+ control: /*#__PURE__*/_jsx(Radio, {}),
76
+ label: "Drawer"
77
+ })]
78
+ })]
79
+ })
80
+ }), (value || []).map((m, i) => {
81
+ return /*#__PURE__*/_jsxs(Grid, {
82
+ item: true,
83
+ xs: 12,
84
+ children: [/*#__PURE__*/_jsx(TextField, {
85
+ name: "text",
86
+ type: "text",
87
+ value: m.text,
88
+ onChange: handleChange(i),
89
+ size: "small",
90
+ fullWidth: true
91
+ }), /*#__PURE__*/_jsx(TextField, {
92
+ name: "url",
93
+ type: "text",
94
+ value: m.url,
95
+ onChange: handleChange(i),
96
+ size: "small",
97
+ fullWidth: true
98
+ }), /*#__PURE__*/_jsx(Button, {
99
+ onClick: onDelete(i),
100
+ color: "error",
101
+ children: "Delete"
102
+ })]
103
+ }, `add-m-${i}`);
104
+ }), /*#__PURE__*/_jsx(Grid, {
105
+ item: true,
106
+ xs: 12,
107
+ children: /*#__PURE__*/_jsx(Button, {
108
+ onClick: onAddMenu,
109
+ children: "+ Add"
110
+ })
111
+ })]
112
+ });
113
+ };
114
+ export default MenusArray;
@@ -5,6 +5,14 @@ const pageSettingsStyle = [{
5
5
  label: "Text",
6
6
  key: "color",
7
7
  type: "color"
8
+ }, {
9
+ label: "Background URL",
10
+ key: "pageColor",
11
+ type: "text"
12
+ }, {
13
+ label: "Background Image",
14
+ key: "pageColor",
15
+ type: "backgroundImage"
8
16
  }, {
9
17
  label: "Background",
10
18
  key: "pageColor",
@@ -23,6 +23,7 @@ import ImageTextWrapper from "../Elements/ImageText/ImageTextWrapper";
23
23
  import ImageText from "../Elements/ImageText/ImageText";
24
24
  import ChipText from "../Elements/ChipText/ChipText";
25
25
  import DrawerMenu from "../Elements/DrawerMenu/DrawerMenu";
26
+ import AppHeader from "../Elements/AppHeader/AppHeader";
26
27
  import { jsx as _jsx } from "react/jsx-runtime";
27
28
  const alignment = ["alignLeft", "alignRight", "alignCenter"];
28
29
  const list_types = ["orderedList", "unorderedList"];
@@ -353,6 +354,10 @@ export const getBlock = props => {
353
354
  return /*#__PURE__*/_jsx(DrawerMenu, {
354
355
  ...props
355
356
  });
357
+ case "app-header":
358
+ return /*#__PURE__*/_jsx(AppHeader, {
359
+ ...props
360
+ });
356
361
  default:
357
362
  return /*#__PURE__*/_jsx("div", {
358
363
  ...element.attr,
@@ -0,0 +1,55 @@
1
+ import { Editor, Transforms, Path, Range, Element } from "slate";
2
+ export const createAppHeaderNode = ({
3
+ menus
4
+ }) => ({
5
+ type: "app-header",
6
+ appTitle: "Title",
7
+ appLogo: "https://upload.wikimedia.org/wikipedia/commons/thumb/0/08/Netflix_2015_logo.svg/1200px-Netflix_2015_logo.svg.png",
8
+ menus: !menus ? [{
9
+ type: "menu",
10
+ url: "https://www.google.com",
11
+ target: "_blank",
12
+ text: "Google"
13
+ }] : menus,
14
+ menuStyle: "drawer",
15
+ children: [{
16
+ text: ""
17
+ }]
18
+ });
19
+ export const insertAppHeader = (editor, props) => {
20
+ const {
21
+ selection
22
+ } = editor;
23
+ const appHeader = createAppHeaderNode(props || {});
24
+ if (!!selection) {
25
+ const [parent, parentPath] = Editor.parent(editor, selection.focus.path);
26
+ if (editor.isVoid(parent)) {
27
+ Transforms.insertNodes(editor, {
28
+ type: "paragraph",
29
+ children: [appHeader]
30
+ }, {
31
+ at: Path.next(parentPath),
32
+ select: true
33
+ });
34
+ } else if (Range.isCollapsed(selection)) {
35
+ Transforms.insertNodes(editor, appHeader, {
36
+ select: true
37
+ });
38
+ } else {
39
+ Transforms.wrapNodes(editor, appHeader, {
40
+ split: true
41
+ });
42
+ }
43
+ } else {
44
+ Transforms.insertNodes(editor, {
45
+ type: "paragraph",
46
+ children: [appHeader]
47
+ });
48
+ }
49
+ };
50
+ export const removeAppHeader = (editor, path) => {
51
+ Transforms.unwrapNodes(editor, {
52
+ at: path,
53
+ match: n => !Editor.isEditor(n) && Element.isElement(n) && n.type === "app-header"
54
+ });
55
+ };
@@ -1,28 +1,38 @@
1
- import { Text } from 'slate';
2
- import { getBlock, getMarked } from './SlateUtilityFunctions.js';
3
- import ReactDOMServer from 'react-dom/server';
1
+ import { Text } from "slate";
2
+ import { getBlock, getMarked } from "./SlateUtilityFunctions.js";
3
+ import ReactDOMServer from "react-dom/server";
4
4
  const {
5
- renderToStaticMarkup
5
+ renderToString
6
6
  } = ReactDOMServer;
7
7
  export const serialize = node => {
8
- if (Text.isText(node)) {
9
- let string = getMarked(node, node.text);
10
- string = renderToStaticMarkup(string);
11
- return string;
8
+ try {
9
+ if (Text.isText(node)) {
10
+ let string = getMarked(node, node.text);
11
+ string = renderToString(string);
12
+ return string;
13
+ }
14
+ const children = node.children.map(n => serialize(n)).join("");
15
+ let block = getBlock({
16
+ children,
17
+ element: node
18
+ });
19
+ block = renderToString(block);
20
+ return block;
21
+ } catch (err) {
22
+ console.log(err);
23
+ return null;
12
24
  }
13
- const children = node.children.map(n => serialize(n)).join('');
14
- let block = getBlock({
15
- children,
16
- element: node
17
- });
18
- block = renderToStaticMarkup(block);
19
- return block;
20
25
  };
21
26
  export const serializer = editorValue => {
22
27
  if (editorValue.length > 0) {
23
- return editorValue.map(n => serialize(n)).join('');
28
+ return editorValue.map(n => serialize(n)).join("");
24
29
  }
25
30
  };
26
31
  export const deserializer = body => {
27
32
  console.log(body);
33
+ };
34
+ export const convertToHTML = editorWrapper => {
35
+ if (editorWrapper && editorWrapper?.current) {
36
+ return editorWrapper?.current;
37
+ }
28
38
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"