@flozy/editor 3.7.0 → 3.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -146,19 +146,21 @@ function AppHeader(props) {
146
146
  src: appLogo
147
147
  }) : appTitle
148
148
  }), /*#__PURE__*/_jsx(Divider, {}), /*#__PURE__*/_jsx(List, {
149
- children: menus.map((item, i) => /*#__PURE__*/_jsx(ListItem, {
150
- disablePadding: true,
151
- children: /*#__PURE__*/_jsx(ListItemButton, {
152
- component: "a",
153
- href: item.url,
154
- sx: {
155
- textAlign: "center"
156
- },
157
- children: /*#__PURE__*/_jsx(ListItemText, {
158
- primary: item.text
149
+ children: menus.map((item, i) => {
150
+ const buttonProps = handleLinkType(item.url, item.linkType, true, item.target === "_blank");
151
+ return /*#__PURE__*/_jsx(ListItem, {
152
+ disablePadding: true,
153
+ children: /*#__PURE__*/_jsx(ListItemButton, {
154
+ ...buttonProps,
155
+ sx: {
156
+ textAlign: "center"
157
+ },
158
+ children: /*#__PURE__*/_jsx(ListItemText, {
159
+ primary: item.text
160
+ })
159
161
  })
160
- })
161
- }, `${item.text}_${i}`))
162
+ }, `${item.text}_${i}`);
163
+ })
162
164
  })]
163
165
  });
164
166
  const container = window !== undefined ? () => window().document.body : undefined;
@@ -71,11 +71,11 @@ const FormWorkflow = props => {
71
71
  children: [/*#__PURE__*/_jsx(Grid, {
72
72
  item: true,
73
73
  sx: classes.radioBtn,
74
- children: /*#__PURE__*/_jsxs(RadioGroup, {
74
+ children: /*#__PURE__*/_jsx(RadioGroup, {
75
75
  name: "set timing",
76
76
  value: schedule,
77
77
  defaultValue: 1,
78
- children: [/*#__PURE__*/_jsx(FormControlLabel, {
78
+ children: /*#__PURE__*/_jsx(FormControlLabel, {
79
79
  value: "immediately",
80
80
  label: "Immediately",
81
81
  onChange: () => {
@@ -84,16 +84,7 @@ const FormWorkflow = props => {
84
84
  control: /*#__PURE__*/_jsx(Radio, {
85
85
  size: "small"
86
86
  })
87
- }), /*#__PURE__*/_jsx(FormControlLabel, {
88
- value: "after",
89
- label: "After",
90
- onChange: () => {
91
- setSchedule("after");
92
- },
93
- control: /*#__PURE__*/_jsx(Radio, {
94
- size: "small"
95
- })
96
- })]
87
+ })
97
88
  })
98
89
  }), schedule === "after" && /*#__PURE__*/_jsx(Grid, {
99
90
  item: true,
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState } from "react";
2
- import { Popper, Fade, Paper, ClickAwayListener } from "@mui/material";
2
+ import { Popper, Fade, Paper } from "@mui/material";
3
3
  import { Editor, Range } from "slate";
4
4
  import { useSlate, useFocused } from "slate-react";
5
5
  import useDrag from "../../hooks/useDrag";
@@ -9,6 +9,7 @@ import MiniTextFormat from "./MiniTextFormat";
9
9
  import { useEditorContext } from "../../hooks/useMouseMove";
10
10
  import usePopupStyles from "../PopupTool/PopupToolStyle";
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { Fragment as _Fragment } from "react/jsx-runtime";
12
13
  const PopupTool = props => {
13
14
  const {
14
15
  theme,
@@ -78,14 +79,7 @@ const PopupTool = props => {
78
79
  setOpen(false);
79
80
  setPopupType("");
80
81
  };
81
- return open && !openAI ? /*#__PURE__*/_jsx(ClickAwayListener, {
82
- onClickAway: e => {
83
- // close the mini toolbar, if user clicks outside the editor (in Flozy app.)
84
- if (e.target !== document.body) {
85
- // e.target returns body, if the user clicks material ui select popup inside the tool bar, on that time, we don't need to close
86
- handleClose();
87
- }
88
- },
82
+ return open && !openAI ? /*#__PURE__*/_jsx(_Fragment, {
89
83
  children: size.device === "xs" ? /*#__PURE__*/_jsx("div", {
90
84
  className: "mobileMiniTextWrapper",
91
85
  children: /*#__PURE__*/_jsx(MiniTextFormat, {
@@ -1,8 +1,24 @@
1
1
  import { Autocomplete, Checkbox, FormControlLabel, MenuItem, Select, TextField, Typography, createFilterOptions } from "@mui/material";
2
2
  import { useEffect, useMemo, useState } from "react";
3
+ import { useSlate } from "slate-react";
3
4
  import { jsx as _jsx } from "react/jsx-runtime";
4
5
  import { Fragment as _Fragment } from "react/jsx-runtime";
5
6
  import { jsxs as _jsxs } from "react/jsx-runtime";
7
+ const sectionTypes = ["grid"];
8
+ const loopChildren = (children = [], sections) => {
9
+ if (!children?.length) {
10
+ return sections;
11
+ }
12
+ for (let child of children) {
13
+ if (sectionTypes.includes(child?.type)) {
14
+ if (child.id) {
15
+ sections.push(child.id);
16
+ }
17
+ }
18
+ sections = loopChildren(child.children, sections);
19
+ }
20
+ return sections;
21
+ };
6
22
  const OpenInNewTab = props => {
7
23
  const {
8
24
  nav,
@@ -42,21 +58,35 @@ export const SelectPage = props => {
42
58
  services
43
59
  } = props;
44
60
  const [pages, setPages] = useState([]);
61
+ const editor = useSlate();
45
62
  const getPages = async () => {
46
63
  const result = await services("getPages", {});
47
- const refactor = result?.data?.map(r => {
48
- const {
49
- title,
50
- url_name,
51
- ...rest
52
- } = r;
53
- return {
54
- label: url_name,
55
- value: url_name,
56
- ...rest
64
+ if (result?.data?.length) {
65
+ const refactor = result?.data?.map(r => {
66
+ const {
67
+ title,
68
+ url_name,
69
+ ...rest
70
+ } = r;
71
+ return {
72
+ label: url_name,
73
+ value: url_name,
74
+ ...rest
75
+ };
76
+ });
77
+ setPages(refactor);
78
+ } else {
79
+ const currentPage = {
80
+ label: "Current Page",
81
+ value: "_currentPage",
82
+ is_current_page: 1,
83
+ sections: loopChildren(editor.children, [])
57
84
  };
58
- });
59
- setPages(refactor);
85
+ setPages([currentPage]);
86
+ if (!value) {
87
+ onChange(currentPage.value);
88
+ }
89
+ }
60
90
  };
61
91
  useEffect(() => {
62
92
  getPages();
@@ -76,12 +106,14 @@ export const SelectPage = props => {
76
106
  }
77
107
  return [];
78
108
  }, [value, pages]);
109
+ const isCurrentPage = page?.value === "_currentPage";
79
110
  return /*#__PURE__*/_jsxs("div", {
80
111
  children: [/*#__PURE__*/_jsx(FreeSoloCreateOption, {
81
112
  label: page?.label,
82
- setValue: val => onChange(val?.value),
113
+ setValue: val => onChange(val?.value || ""),
83
114
  placeholder: "Select Page",
84
- options: pages
115
+ options: pages,
116
+ disabled: isCurrentPage
85
117
  }), /*#__PURE__*/_jsx(FreeSoloCreateOption, {
86
118
  label: section?.label,
87
119
  setValue: val => {
@@ -96,7 +128,7 @@ export const SelectPage = props => {
96
128
  label: p,
97
129
  value: p
98
130
  }))
99
- }), /*#__PURE__*/_jsx(OpenInNewTab, {
131
+ }), isCurrentPage ? null : /*#__PURE__*/_jsx(OpenInNewTab, {
100
132
  ...props
101
133
  })]
102
134
  });
@@ -149,7 +181,8 @@ export function FreeSoloCreateOption({
149
181
  label,
150
182
  setValue,
151
183
  options = [],
152
- placeholder = ""
184
+ placeholder = "",
185
+ disabled = false
153
186
  }) {
154
187
  return /*#__PURE__*/_jsx(Autocomplete, {
155
188
  freeSolo: true,
@@ -164,7 +197,7 @@ export function FreeSoloCreateOption({
164
197
  children: option.label
165
198
  }),
166
199
  onChange: (event, newValue) => {
167
- if (typeof newValue === 'string') {
200
+ if (typeof newValue === "string") {
168
201
  setValue({
169
202
  value: newValue
170
203
  });
@@ -189,7 +222,7 @@ export function FreeSoloCreateOption({
189
222
  } = params;
190
223
  // Suggest the creation of a new value
191
224
  const isExisting = options.some(option => inputValue === option.label);
192
- if (inputValue !== '' && !isExisting) {
225
+ if (inputValue !== "" && !isExisting) {
193
226
  filtered.push({
194
227
  inputValue,
195
228
  label: `Add "${inputValue}"`
@@ -202,7 +235,7 @@ export function FreeSoloCreateOption({
202
235
  handleHomeEndKeys: true,
203
236
  getOptionLabel: option => {
204
237
  // Value selected with enter, right from the input
205
- if (typeof option === 'string') {
238
+ if (typeof option === "string") {
206
239
  return option;
207
240
  }
208
241
  // Add "xxx" option created dynamically
@@ -214,6 +247,7 @@ export function FreeSoloCreateOption({
214
247
  },
215
248
  sx: {
216
249
  marginTop: "10px"
217
- }
250
+ },
251
+ disabled: disabled
218
252
  });
219
253
  }
@@ -129,31 +129,32 @@ const formStyle = [{
129
129
  key: "backgroundImage",
130
130
  type: "backgroundImage"
131
131
  }]
132
- }, {
133
- tab: "Add to Boards",
134
- value: "metadatamapping",
135
- fields: [{
136
- label: "Add response to contacts board",
137
- key: "metadatamapping",
138
- type: "metadatamapping",
139
- compType: "card",
140
- content: "By default, form responses are added as separate cards on the default contact board.",
141
- value: "mappingToContactBoard",
142
- infoIcon: /*#__PURE__*/_jsx(Icon, {
143
- icon: "info"
144
- })
145
- }, {
146
- label: "Create a separate board",
147
- key: "metadatamapping",
148
- type: "metadatamapping",
149
- compType: "card",
150
- content: "By default, form responses are added as separate cards on a new board (Contact Us).",
151
- value: "mappingToSeparateBoard",
152
- infoIcon: /*#__PURE__*/_jsx(Icon, {
153
- icon: "info"
154
- })
155
- }]
156
- }, {
132
+ },
133
+ // {
134
+ // tab: "Add to Boards",
135
+ // value: "metadatamapping",
136
+ // fields: [
137
+ // {
138
+ // label: "Add response to contacts board",
139
+ // key: "metadatamapping",
140
+ // type: "metadatamapping",
141
+ // compType: "card",
142
+ // content: "By default, form responses are added as separate cards on the default contact board.",
143
+ // value: "mappingToContactBoard",
144
+ // infoIcon: <Icon icon="info" />
145
+ // },
146
+ // {
147
+ // label: "Create a separate board",
148
+ // key: "metadatamapping",
149
+ // type: "metadatamapping",
150
+ // compType: "card",
151
+ // content: "By default, form responses are added as separate cards on a new board (Contact Us).",
152
+ // value: "mappingToSeparateBoard",
153
+ // infoIcon: <Icon icon="info" />
154
+ // },
155
+ // ],
156
+ // },
157
+ {
157
158
  tab: "Save As Template",
158
159
  value: "saveAsTemplate",
159
160
  needActions: false,
@@ -21,8 +21,8 @@ export const insertForm = (editor, item) => {
21
21
  workflow: [],
22
22
  children: [{
23
23
  ...formField()
24
- }],
25
- metadatamapping: "mappingToContactBoard"
24
+ }]
25
+ // metadatamapping: "mappingToContactBoard",
26
26
  } : item;
27
27
  Transforms.insertNodes(editor, grid);
28
28
  insertNewLine(editor);
@@ -208,7 +208,13 @@ export const hasVerticalScrollbar = (element = {}) => {
208
208
  return element.scrollHeight > element.clientHeight;
209
209
  };
210
210
  const isHomePage = page => {
211
- return page === "home" || page === "iframe.html" || !page;
211
+ return page === "home" || page === "iframe.html" || page === "_currentPage" || !page;
212
+ };
213
+ const getScrollElement = () => {
214
+ const slateWrapper = document.getElementById("slate-wrapper-scroll-container");
215
+ const isSlateWrapperScroll = hasVerticalScrollbar(slateWrapper);
216
+ const scrollFrom = isSlateWrapperScroll ? slateWrapper : window;
217
+ return scrollFrom;
212
218
  };
213
219
  export const handleLinkType = (url, linkType, readOnly, openInNewTab, onClick = () => {}) => {
214
220
  const props = {};
@@ -239,16 +245,33 @@ export const handleLinkType = (url, linkType, readOnly, openInNewTab, onClick =
239
245
  }
240
246
  break;
241
247
  case "page":
242
- props.component = "a";
243
- const [page, section] = url?.split("#") || [];
248
+ const [page = "", section] = url?.split("#") || [];
244
249
  const sec = section ? `#${section}` : "";
245
- const currentUserPage = getCurrentUserPage();
246
- props.href = isHomePage(page) ? `./${currentUserPage}${sec}` : `./${url}`;
247
- if (openInNewTab) {
248
- if (isCurrentPage(page)) {
249
- // temp fix, if user is presented in current page, open in new tab option is restricted, we will scroll to the element in current page
250
- } else {
251
- props.target = "_blank";
250
+ if (page === "_currentPage") {
251
+ props.component = "button";
252
+ props.onClick = () => {
253
+ const scrollFrom = getScrollElement();
254
+ if (sec) {
255
+ const element = document.getElementById(section);
256
+ if (element) {
257
+ const topPosition = element.getBoundingClientRect().top + scrollFrom.scrollTop;
258
+ scrollFrom.scrollTo({
259
+ top: topPosition,
260
+ behavior: "smooth"
261
+ });
262
+ }
263
+ }
264
+ };
265
+ } else {
266
+ props.component = "a";
267
+ const currentUserPage = getCurrentUserPage();
268
+ props.href = isCurrentPage(page) ? `./${currentUserPage}${sec}` : `./${url}`;
269
+ if (openInNewTab) {
270
+ if (isCurrentPage(page)) {
271
+ // temp fix, if user is presented in current page, open in new tab option is restricted, we will scroll to the element in current page
272
+ } else {
273
+ props.target = "_blank";
274
+ }
252
275
  }
253
276
  }
254
277
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "3.7.0",
3
+ "version": "3.7.1",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"