@flozy/editor 3.6.2 → 3.6.3

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;
@@ -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
  }
@@ -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 = isCurrentPage(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.6.2",
3
+ "version": "3.6.3",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"