@griddo/ax 11.11.8-rc.1 → 11.12.0

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 (99) hide show
  1. package/config/jest/componentsMock.js +5 -7
  2. package/package.json +2 -2
  3. package/src/__tests__/components/Browser/Browser.test.tsx +87 -438
  4. package/src/__tests__/components/ConfigPanel/ConfigPanel.test.tsx +3 -1
  5. package/src/__tests__/components/Fields/Button/Button.test.tsx +27 -29
  6. package/src/__tests__/components/ResizePanel/ResizePanel.test.tsx +1 -1
  7. package/src/components/Browser/index.tsx +149 -294
  8. package/src/components/Browser/style.tsx +6 -75
  9. package/src/components/Button/index.tsx +1 -2
  10. package/src/components/ConfigPanel/Form/ConnectedField/PageConnectedField/Field/index.tsx +4 -2
  11. package/src/components/Fields/AsyncSelect/style.tsx +0 -13
  12. package/src/components/Fields/FieldGroup/index.tsx +2 -5
  13. package/src/components/Fields/FieldGroup/style.tsx +7 -32
  14. package/src/components/Fields/HeadingField/index.tsx +2 -2
  15. package/src/components/Fields/HiddenField/style.tsx +1 -1
  16. package/src/components/Fields/NumberField/index.tsx +16 -15
  17. package/src/components/Fields/NumberField/style.tsx +0 -2
  18. package/src/components/Fields/ReferenceField/index.tsx +1 -1
  19. package/src/components/Fields/Select/index.tsx +1 -5
  20. package/src/components/Fields/Select/style.tsx +0 -56
  21. package/src/components/Fields/SummaryButton/index.tsx +9 -18
  22. package/src/components/Fields/SummaryButton/style.tsx +2 -1
  23. package/src/components/Fields/TagsField/index.tsx +9 -8
  24. package/src/components/Fields/UrlField/index.tsx +27 -26
  25. package/src/components/Fields/index.tsx +0 -2
  26. package/src/components/FloatingPanel/index.tsx +2 -5
  27. package/src/components/FloatingPanel/style.tsx +1 -2
  28. package/src/components/IconAction/index.tsx +1 -1
  29. package/src/components/MainWrapper/AppBar/index.tsx +1 -8
  30. package/src/components/MainWrapper/index.tsx +1 -7
  31. package/src/components/Notification/index.tsx +2 -2
  32. package/src/components/PageFinder/index.tsx +1 -1
  33. package/src/components/ResizePanel/index.tsx +3 -4
  34. package/src/components/ResizePanel/style.tsx +1 -1
  35. package/src/components/SearchField/style.tsx +2 -2
  36. package/src/components/SideModal/index.tsx +1 -2
  37. package/src/components/Tabs/index.tsx +4 -13
  38. package/src/components/Tabs/style.tsx +8 -7
  39. package/src/components/Toast/index.tsx +2 -4
  40. package/src/components/Tooltip/index.tsx +3 -4
  41. package/src/components/index.tsx +0 -8
  42. package/src/forms/fields.tsx +68 -70
  43. package/src/hooks/forms.tsx +1 -22
  44. package/src/hooks/index.tsx +3 -13
  45. package/src/hooks/modals.tsx +15 -103
  46. package/src/hooks/users.tsx +8 -25
  47. package/src/modules/Forms/atoms.tsx +2 -2
  48. package/src/modules/FramePreview/index.tsx +16 -55
  49. package/src/modules/FramePreview/style.tsx +2 -34
  50. package/src/modules/GlobalEditor/Editor/index.tsx +3 -37
  51. package/src/modules/GlobalEditor/PageBrowser/index.tsx +2 -19
  52. package/src/modules/GlobalEditor/Preview/index.tsx +2 -0
  53. package/src/modules/GlobalEditor/Preview/style.tsx +1 -1
  54. package/src/modules/GlobalEditor/index.tsx +57 -119
  55. package/src/modules/PageEditor/Editor/index.tsx +2 -33
  56. package/src/modules/PageEditor/PageBrowser/index.tsx +2 -20
  57. package/src/modules/PageEditor/Preview/index.tsx +2 -0
  58. package/src/modules/PageEditor/Preview/style.tsx +1 -1
  59. package/src/modules/PageEditor/atoms.tsx +1 -1
  60. package/src/modules/PageEditor/index.tsx +66 -130
  61. package/src/modules/PublicPreview/index.tsx +2 -5
  62. package/src/schemas/pages/GlobalPage.ts +70 -87
  63. package/src/schemas/pages/Page.ts +70 -87
  64. package/src/types/index.tsx +0 -12
  65. package/src/__tests__/components/Browser/Browser.utils.test.ts +0 -55
  66. package/src/__tests__/components/HeadingsPreviewModal/ErrorsBanner/ErrorItem/ErrorItem.test.tsx +0 -158
  67. package/src/__tests__/components/HeadingsPreviewModal/ErrorsBanner/ErrorsBanner.test.tsx +0 -90
  68. package/src/__tests__/components/HeadingsPreviewModal/HeadingsPreviewModal.test.tsx +0 -178
  69. package/src/__tests__/components/HeadingsPreviewModal/HeadingsPreviewModal.utils.test.tsx +0 -150
  70. package/src/__tests__/components/KeywordsPreviewModal/KeywordItem/KeywordItem.test.tsx +0 -91
  71. package/src/__tests__/components/KeywordsPreviewModal/KeywordsPreviewModal.test.tsx +0 -122
  72. package/src/__tests__/components/KeywordsPreviewModal/KeywordsPreviewModal.utils.test.ts +0 -15
  73. package/src/__tests__/components/KeywordsPreviewModal/atoms.test.tsx +0 -101
  74. package/src/__tests__/modules/FramePreview/FramePreview.test.tsx +0 -318
  75. package/src/__tests__/modules/FramePreview/FramePreview.utils.test.ts +0 -242
  76. package/src/__tests__/modules/FramePreview/HeadingsOverlay/HeadingsOverlay.test.tsx +0 -185
  77. package/src/components/Browser/utils.tsx +0 -13
  78. package/src/components/Fields/SEOPreview/index.tsx +0 -36
  79. package/src/components/Fields/SEOPreview/style.tsx +0 -24
  80. package/src/components/FloatingNote/index.tsx +0 -35
  81. package/src/components/FloatingNote/style.tsx +0 -26
  82. package/src/components/HeadingsPreviewModal/ErrorsBanner/ErrorItem/index.tsx +0 -85
  83. package/src/components/HeadingsPreviewModal/ErrorsBanner/ErrorItem/style.tsx +0 -80
  84. package/src/components/HeadingsPreviewModal/ErrorsBanner/index.tsx +0 -57
  85. package/src/components/HeadingsPreviewModal/ErrorsBanner/style.tsx +0 -82
  86. package/src/components/HeadingsPreviewModal/HeadingItem/index.tsx +0 -71
  87. package/src/components/HeadingsPreviewModal/HeadingItem/style.tsx +0 -77
  88. package/src/components/HeadingsPreviewModal/index.tsx +0 -146
  89. package/src/components/HeadingsPreviewModal/style.tsx +0 -82
  90. package/src/components/HeadingsPreviewModal/utils.tsx +0 -257
  91. package/src/components/KeywordsPreviewModal/KeywordItem/index.tsx +0 -46
  92. package/src/components/KeywordsPreviewModal/KeywordItem/style.tsx +0 -64
  93. package/src/components/KeywordsPreviewModal/atoms.tsx +0 -96
  94. package/src/components/KeywordsPreviewModal/index.tsx +0 -99
  95. package/src/components/KeywordsPreviewModal/style.tsx +0 -87
  96. package/src/components/KeywordsPreviewModal/utils.tsx +0 -22
  97. package/src/modules/FramePreview/HeadingsOverlay/index.tsx +0 -113
  98. package/src/modules/FramePreview/HeadingsOverlay/style.tsx +0 -24
  99. package/src/modules/FramePreview/utils.tsx +0 -140
@@ -1,5 +1,6 @@
1
- import { FieldContainer, FieldGroup, FieldsBehavior } from "@ax/components";
2
- import type { IErrorItem, IPage, ISite } from "@ax/types";
1
+ import React from "react";
2
+ import { FieldContainer, FieldsBehavior } from "@ax/components";
3
+ import { IErrorItem, IPage, ISite } from "@ax/types";
3
4
 
4
5
  const getInnerFields = (
5
6
  innerFields: any[],
@@ -15,54 +16,48 @@ const getInnerFields = (
15
16
  ) => {
16
17
  let fieldArr: any[] = [];
17
18
 
18
- return innerFields?.map((singleFieldProps: any) => {
19
- const { key } = singleFieldProps;
20
- const error = errors?.find((err: any) => err.editorID === selectedContent.editorID && err.key === key);
19
+ return (
20
+ innerFields &&
21
+ innerFields.map((singleFieldProps: any) => {
22
+ const { key } = singleFieldProps;
23
+ const error = errors && errors.find((err: any) => err.editorID === selectedContent.editorID && err.key === key);
21
24
 
22
- const isGroup = singleFieldProps.type === "FieldGroup";
23
- const isCollapsed = isGroup && singleFieldProps.collapsed;
24
- const isConditional = singleFieldProps.type === "ConditionalField";
25
- const isArrayGroup = singleFieldProps.type === "ArrayFieldGroup";
25
+ if (singleFieldProps.type === "ConditionalField" || singleFieldProps.type === "ArrayFieldGroup") {
26
+ fieldArr = getInnerFields(
27
+ singleFieldProps.fields,
28
+ innerActions,
29
+ selectedContent,
30
+ isTemplateActivated,
31
+ theme,
32
+ moduleCopy,
33
+ parentDisabled,
34
+ site,
35
+ errors,
36
+ deleteError,
37
+ );
38
+ }
26
39
 
27
- if (isGroup || isConditional || isArrayGroup) {
28
- fieldArr = getInnerFields(
29
- singleFieldProps.fields,
30
- innerActions,
31
- selectedContent,
32
- isTemplateActivated,
33
- theme,
34
- moduleCopy,
35
- parentDisabled,
36
- site,
37
- errors,
38
- deleteError,
40
+ return (
41
+ <FieldContainer
42
+ key={key}
43
+ objKey={key}
44
+ innerFields={fieldArr}
45
+ field={singleFieldProps}
46
+ actions={innerActions}
47
+ selectedContent={selectedContent}
48
+ updateValue={innerActions.updateValue}
49
+ goTo={innerActions.goTo}
50
+ site={site}
51
+ {...singleFieldProps}
52
+ disabled={!isTemplateActivated || singleFieldProps.disabled || parentDisabled}
53
+ error={error}
54
+ deleteError={deleteError}
55
+ theme={theme}
56
+ moduleCopy={moduleCopy}
57
+ />
39
58
  );
40
- }
41
-
42
- return isGroup ? (
43
- <FieldGroup key={key} title={singleFieldProps.title} collapsed={isCollapsed} solid={singleFieldProps.solid}>
44
- {fieldArr}
45
- </FieldGroup>
46
- ) : (
47
- <FieldContainer
48
- key={key}
49
- objKey={key}
50
- innerFields={fieldArr}
51
- field={singleFieldProps}
52
- actions={innerActions}
53
- selectedContent={selectedContent}
54
- updateValue={innerActions.updateValue}
55
- goTo={innerActions.goTo}
56
- site={site}
57
- {...singleFieldProps}
58
- disabled={!isTemplateActivated || singleFieldProps.disabled || parentDisabled}
59
- error={error}
60
- deleteError={deleteError}
61
- theme={theme}
62
- moduleCopy={moduleCopy}
63
- />
64
- );
65
- });
59
+ })
60
+ );
66
61
  };
67
62
 
68
63
  const getStructuredDataInnerFields = (
@@ -74,35 +69,38 @@ const getStructuredDataInnerFields = (
74
69
  ) => {
75
70
  let fieldArr: any[] = [];
76
71
 
77
- return innerFields?.map((singleFieldProps: any) => {
78
- const { key, type, fields } = singleFieldProps;
72
+ return (
73
+ innerFields &&
74
+ innerFields.map((singleFieldProps: any) => {
75
+ const { key, type, fields } = singleFieldProps;
79
76
 
80
- const handleChange = (newValue: any) => {
81
- updateValue({ [key]: newValue });
82
- };
77
+ const handleChange = (newValue: any) => {
78
+ updateValue({ [key]: newValue });
79
+ };
83
80
 
84
- const value = content?.[key];
81
+ const value = content && content[key];
85
82
 
86
- if (type === "ConditionalField" || type === "ArrayFieldGroup") {
87
- fieldArr = getStructuredDataInnerFields(fields, content, updateValue, theme, errors);
88
- }
83
+ if (type === "ConditionalField" || type === "ArrayFieldGroup") {
84
+ fieldArr = getStructuredDataInnerFields(fields, content, updateValue, theme, errors);
85
+ }
89
86
 
90
- const error = errors.find((err: any) => err.key === key);
87
+ const error = errors.find((err: any) => err.key === key);
91
88
 
92
- const fieldProps = {
93
- value,
94
- objKey: key,
95
- fieldType: type,
96
- innerFields: fieldArr,
97
- field: singleFieldProps,
98
- onChange: handleChange,
99
- ...singleFieldProps,
100
- theme,
101
- error,
102
- };
89
+ const fieldProps = {
90
+ value,
91
+ objKey: key,
92
+ fieldType: type,
93
+ innerFields: fieldArr,
94
+ field: singleFieldProps,
95
+ onChange: handleChange,
96
+ ...singleFieldProps,
97
+ theme,
98
+ error,
99
+ };
103
100
 
104
- return <FieldsBehavior key={key} {...fieldProps} />;
105
- });
101
+ return <FieldsBehavior key={key} {...fieldProps} />;
102
+ })
103
+ );
106
104
  };
107
105
 
108
106
  export { getInnerFields, getStructuredDataInnerFields };
@@ -26,27 +26,6 @@ const useDebounce = (value: any) => {
26
26
  return debouncedValue;
27
27
  };
28
28
 
29
- const useDebouncedCallback = <T extends unknown[]>(callback: (...args: T) => void, delay: number) => {
30
- const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
31
- const callbackRef = useRef(callback);
32
-
33
- useEffect(() => {
34
- callbackRef.current = callback;
35
- }, [callback]);
36
-
37
- return useCallback(
38
- (...args: T) => {
39
- if (delay === 0) {
40
- callbackRef.current(...args);
41
- return;
42
- }
43
- clearTimeout(timeoutRef.current);
44
- timeoutRef.current = setTimeout(() => callbackRef.current(...args), delay);
45
- },
46
- [delay],
47
- );
48
- };
49
-
50
29
  const useEqualStructured = (component: any) => {
51
30
  return memo(component, (prevProps: any, newProps: any) => {
52
31
  const { fieldKey } = prevProps;
@@ -255,4 +234,4 @@ const useShouldBeSaved = (form: Record<string, unknown> | IUser | FormContent, d
255
234
  return { isDirty, setIsDirty };
256
235
  };
257
236
 
258
- export { useDebounce, useDebouncedCallback, useEqualStructured, usePrevious, useIsDirty, useShouldBeSaved };
237
+ export { useDebounce, useEqualStructured, useIsDirty, usePrevious, useShouldBeSaved };
@@ -1,19 +1,12 @@
1
1
  import { type IBulkSelectedItems, useBulkSelection } from "./bulk";
2
2
  import { useAdaptiveText, useCategoryColors, useEmptyState } from "./content";
3
- import {
4
- useDebounce,
5
- useDebouncedCallback,
6
- useEqualStructured,
7
- useIsDirty,
8
- usePrevious,
9
- useShouldBeSaved,
10
- } from "./forms";
3
+ import { useDebounce, useEqualStructured, useIsDirty, usePrevious, useShouldBeSaved } from "./forms";
11
4
  import { useOnMessageReceivedFromIframe, useOnMessageReceivedFromOutside } from "./iframe";
12
5
  import { useURLSearchParam } from "./location";
13
- import { useHandleClickOutside, useModal, useModals, useToast } from "./modals";
6
+ import { useHandleClickOutside, useModal, useToast } from "./modals";
14
7
  import { useNetworkStatus } from "./network";
15
8
  import { useResizable } from "./resize";
16
- import { useGlobalPermission, usePermission, usePermissions } from "./users";
9
+ import { useGlobalPermission, usePermission } from "./users";
17
10
  import { useWindowSize } from "./window";
18
11
 
19
12
  export {
@@ -21,19 +14,16 @@ export {
21
14
  useBulkSelection,
22
15
  useCategoryColors,
23
16
  useDebounce,
24
- useDebouncedCallback,
25
17
  useEmptyState,
26
18
  useEqualStructured,
27
19
  useGlobalPermission,
28
20
  useHandleClickOutside,
29
21
  useIsDirty,
30
22
  useModal,
31
- useModals,
32
23
  useNetworkStatus,
33
24
  useOnMessageReceivedFromIframe,
34
25
  useOnMessageReceivedFromOutside,
35
26
  usePermission,
36
- usePermissions,
37
27
  usePrevious,
38
28
  useResizable,
39
29
  useShouldBeSaved,
@@ -1,4 +1,4 @@
1
- import { useState, useEffect, useRef, useCallback } from "react";
1
+ import { useState, useEffect } from "react";
2
2
 
3
3
  const useModal = (initialState?: boolean, bodyBlock = true) => {
4
4
  const [isOpen, setIsOpen] = useState(initialState || false);
@@ -6,26 +6,11 @@ const useModal = (initialState?: boolean, bodyBlock = true) => {
6
6
  setIsOpen(!isOpen);
7
7
  };
8
8
 
9
- useEffect(() => {
10
- if (isOpen && bodyBlock) {
11
- if (!document.body.classList.contains("modal-open")) {
12
- document.body.classList.add("modal-open");
13
- }
14
- return () => {
15
- // Solo eliminar si no hay otros modales abiertos
16
- const modals = document.querySelectorAll('[data-testid="modal-wrapper"]');
17
- if (modals.length <= 1) {
18
- document.body.classList.remove("modal-open");
19
- }
20
- };
21
- } else if (!bodyBlock || !isOpen) {
22
- // Solo eliminar si no hay modales abiertos
23
- const modals = document.querySelectorAll('[data-testid="modal-wrapper"]');
24
- if (modals.length === 0) {
25
- document.body.classList.remove("modal-open");
26
- }
27
- }
28
- }, [isOpen, bodyBlock]);
9
+ if (isOpen && bodyBlock) {
10
+ document.body.classList.add("modal-open");
11
+ } else {
12
+ document.body.classList.remove("modal-open");
13
+ }
29
14
 
30
15
  return {
31
16
  isOpen,
@@ -33,66 +18,6 @@ const useModal = (initialState?: boolean, bodyBlock = true) => {
33
18
  };
34
19
  };
35
20
 
36
- const useModals = <T extends string>(modalKeys: readonly T[], bodyBlock = true) => {
37
- const [openModals, setOpenModals] = useState<Record<T, boolean>>(() =>
38
- modalKeys.reduce(
39
- (acc, key) => {
40
- acc[key] = false;
41
- return acc;
42
- },
43
- {} as Record<T, boolean>,
44
- ),
45
- );
46
-
47
- const toggleModal = useCallback((modalKey: T) => {
48
- setOpenModals((prev) => ({ ...prev, [modalKey]: !prev[modalKey] }));
49
- }, []);
50
-
51
- const openModal = useCallback((modalKey: T) => {
52
- setOpenModals((prev) => ({ ...prev, [modalKey]: true }));
53
- }, []);
54
-
55
- const closeModal = useCallback((modalKey: T) => {
56
- setOpenModals((prev) => ({ ...prev, [modalKey]: false }));
57
- }, []);
58
-
59
- const isOpen = useCallback(
60
- (modalKey: T) => {
61
- return openModals[modalKey] || false;
62
- },
63
- [openModals],
64
- );
65
-
66
- useEffect(() => {
67
- const hasOpenModals = Object.values(openModals).some(Boolean);
68
-
69
- if (hasOpenModals && bodyBlock) {
70
- if (!document.body.classList.contains("modal-open")) {
71
- document.body.classList.add("modal-open");
72
- }
73
- return () => {
74
- // Solo eliminar si no hay otros modales abiertos
75
- const modals = document.querySelectorAll('[data-testid="modal-wrapper"]');
76
- if (modals.length <= 1) {
77
- document.body.classList.remove("modal-open");
78
- }
79
- };
80
- }
81
- // Solo eliminar si no hay modales abiertos
82
- const modals = document.querySelectorAll('[data-testid="modal-wrapper"]');
83
- if (modals.length === 0) {
84
- document.body.classList.remove("modal-open");
85
- }
86
- }, [openModals, bodyBlock]);
87
-
88
- return {
89
- toggleModal,
90
- openModal,
91
- closeModal,
92
- isOpen,
93
- };
94
- };
95
-
96
21
  const useHandleClickOutside = (isOpen: boolean, handleClickOutside: (e: MouseEvent) => void) => {
97
22
  useEffect(() => {
98
23
  if (isOpen) {
@@ -110,32 +35,19 @@ const useHandleClickOutside = (isOpen: boolean, handleClickOutside: (e: MouseEve
110
35
  const useToast = () => {
111
36
  const [isVisible, setIsVisible] = useState(false);
112
37
  const [state, setState] = useState<any>(null);
113
- const timeoutRef = useRef<NodeJS.Timeout | null>(null);
114
38
 
115
- const toggleToast = useCallback((newState?: any) => {
116
- if (timeoutRef.current) {
117
- clearTimeout(timeoutRef.current);
118
- }
39
+ let temp: any;
40
+ const setTemp = () => (temp = setTimeout(() => setIsVisible(false), 6000));
41
+ const stopTemp = () => clearTimeout(temp);
119
42
 
120
- if (newState) {
121
- setState(newState);
122
- }
43
+ const toggleToast = (state?: unknown) => {
123
44
  setIsVisible(true);
124
-
125
- timeoutRef.current = setTimeout(() => {
126
- setIsVisible(false);
127
- }, 6000);
128
- }, []);
129
-
130
- useEffect(() => {
131
- return () => {
132
- if (timeoutRef.current) {
133
- clearTimeout(timeoutRef.current);
134
- }
135
- };
136
- }, []);
45
+ setTemp();
46
+ stopTemp();
47
+ state && setState(state);
48
+ };
137
49
 
138
50
  return { isVisible, setIsVisible, toggleToast, state };
139
51
  };
140
52
 
141
- export { useModal, useModals, useHandleClickOutside, useToast };
53
+ export { useModal, useHandleClickOutside, useToast };
@@ -1,11 +1,11 @@
1
- import { useMemo } from "react";
2
1
  import { useSelector } from "react-redux";
3
-
4
- import type { IRootState } from "@ax/types";
2
+ import { IRootState } from "@ax/types";
5
3
 
6
4
  const usePermission = (permission: string | string[] | undefined): boolean => {
7
5
  const userPermissions = useSelector((state: IRootState) => state.users.currentPermissions);
8
- const isSuperAdmin = useSelector((state: IRootState) => state.users.currentUser?.isSuperAdmin);
6
+ const isSuperAdmin = useSelector(
7
+ (state: IRootState) => state.users.currentUser && state.users.currentUser.isSuperAdmin,
8
+ );
9
9
 
10
10
  const isAllowedTo = (permissions: string[]) =>
11
11
  userPermissions && permissions.some((permission: string) => userPermissions.includes(permission));
@@ -19,28 +19,11 @@ const usePermission = (permission: string | string[] | undefined): boolean => {
19
19
  return isAllowedTo(arrayPermission);
20
20
  };
21
21
 
22
- const usePermissions = <T extends Record<string, string | string[]>>(permissions: T): Record<keyof T, boolean> => {
23
- const userPermissions = useSelector((state: IRootState) => state.users.currentPermissions);
24
- const isSuperAdmin = useSelector((state: IRootState) => state.users.currentUser?.isSuperAdmin);
25
-
26
- return useMemo(() => {
27
- const isAllowedTo = (permission: string | string[]) => {
28
- if (isSuperAdmin) return true;
29
- const arrayPermission = Array.isArray(permission) ? permission : [permission];
30
- return userPermissions && arrayPermission.some((perm: string) => userPermissions.includes(perm));
31
- };
32
-
33
- const result: Record<string, boolean> = {};
34
- for (const key of Object.keys(permissions)) {
35
- result[key] = isAllowedTo(permissions[key]);
36
- }
37
- return result as Record<keyof T, boolean>;
38
- }, [permissions, userPermissions, isSuperAdmin]);
39
- };
40
-
41
22
  const useGlobalPermission = (permission: string | string[] | undefined): boolean => {
42
23
  const userPermissions = useSelector((state: IRootState) => state.users.globalPermissions);
43
- const isSuperAdmin = useSelector((state: IRootState) => state.users.currentUser?.isSuperAdmin);
24
+ const isSuperAdmin = useSelector(
25
+ (state: IRootState) => state.users.currentUser && state.users.currentUser.isSuperAdmin,
26
+ );
44
27
 
45
28
  const isAllowedTo = (permissions: string[]) =>
46
29
  userPermissions && permissions.some((permission: string) => userPermissions.includes(permission));
@@ -54,4 +37,4 @@ const useGlobalPermission = (permission: string | string[] | undefined): boolean
54
37
  return isAllowedTo(arrayPermission);
55
38
  };
56
39
 
57
- export { usePermission, usePermissions, useGlobalPermission };
40
+ export { usePermission, useGlobalPermission };
@@ -1,6 +1,6 @@
1
- import type { Dispatch, SetStateAction } from "react";
1
+ import React, { Dispatch, SetStateAction } from "react";
2
2
 
3
- import type { IModal } from "@ax/types";
3
+ import { IModal } from "@ax/types";
4
4
  import { Modal, FieldsBehavior, AsyncSelect } from "@ax/components";
5
5
 
6
6
  import * as S from "./style";
@@ -1,4 +1,3 @@
1
- import { useEffect } from "react";
2
1
  import { connect } from "react-redux";
3
2
 
4
3
  import { BrowserContent, Loading, Toast } from "@ax/components";
@@ -9,9 +8,6 @@ import { getDefaultTheme } from "@ax/helpers";
9
8
  import { useOnMessageReceivedFromOutside, useToast, useURLSearchParam } from "@ax/hooks";
10
9
  import type { FormContent, ILanguage, IRootState, ISite, ISocialState } from "@ax/types";
11
10
 
12
- import HeadingsOverlay from "./HeadingsOverlay";
13
- import { observeAndAddIdsToHeadings, observeAndHighlightKeywords } from "./utils";
14
-
15
11
  import * as S from "./style";
16
12
 
17
13
  const FramePreview = (props: IProps) => {
@@ -33,19 +29,11 @@ const FramePreview = (props: IProps) => {
33
29
  copyModule,
34
30
  } = props;
35
31
 
36
- const previewParam = useURLSearchParam("preview");
37
- const disabledParam = useURLSearchParam("disabled");
32
+ const isPreview = useURLSearchParam("preview");
33
+ const isDisabled = useURLSearchParam("disabled");
38
34
  const type = useURLSearchParam("type");
39
- const headingFilter = useURLSearchParam("headingFilter");
40
- const keywordFilter = useURLSearchParam("keywordFilter");
41
-
42
- const isPreviewMode = previewParam === "true";
43
- const isDisabled = disabledParam === "true";
35
+ document.body.classList.add("preview");
44
36
  const isForm = type === "form";
45
- const isHeadingsEditor = type === "headings";
46
- const isKeywordsEditor = type === "keywords";
47
- const keywords: string[] = pageContent?.metaKeywords || [];
48
- const filteredKeywords = keywordFilter ? [keywordFilter] : keywords;
49
37
  const setSelectedContent = isForm ? setSelectedFormContent : setSelectedPageContent;
50
38
  const setContent = isForm ? setFormContent : setEditorContent;
51
39
  const content = isForm ? formContent : pageContent;
@@ -54,40 +42,15 @@ const FramePreview = (props: IProps) => {
54
42
  const { isVisible, toggleToast, setIsVisible, state: toastState } = useToast();
55
43
  useOnMessageReceivedFromOutside(setContent, setSelectedContent);
56
44
 
57
- useEffect(() => {
58
- document.body.classList.add("preview");
59
-
60
- const handleMouseMove = (e: MouseEvent) => {
61
- window.parent.postMessage(
62
- {
63
- type: "iframe-mousemove",
64
- clientX: e.clientX,
65
- },
66
- "*",
67
- );
68
- };
69
-
70
- window.addEventListener("mousemove", handleMouseMove);
71
- return () => window.removeEventListener("mousemove", handleMouseMove);
72
- }, []);
73
-
74
- useEffect(() => {
75
- if (isDisabled) {
76
- localStorage.setItem("selectedID", "0");
77
- }
78
- }, [isDisabled]);
79
-
80
- useEffect(() => {
81
- if (isHeadingsEditor) {
82
- return observeAndAddIdsToHeadings(document.body, headingFilter);
83
- }
84
- }, [isHeadingsEditor, headingFilter]);
85
-
86
- useEffect(() => {
87
- if (isKeywordsEditor) {
88
- return observeAndHighlightKeywords(document.body, filteredKeywords);
89
- }
90
- }, [isKeywordsEditor, filteredKeywords]);
45
+ window.addEventListener("mousemove", (e) => {
46
+ window.parent.postMessage(
47
+ {
48
+ type: "iframe-mousemove",
49
+ clientX: e.clientX,
50
+ },
51
+ "*",
52
+ );
53
+ });
91
54
 
92
55
  const selectEditorID = (
93
56
  selectedComponent: { editorID: number; component: any; type: string; parentEditorID: number },
@@ -104,7 +67,7 @@ const FramePreview = (props: IProps) => {
104
67
 
105
68
  const isNavigationModule = ["header", "footer"].includes(selectedComponent.type);
106
69
 
107
- if (!isPreviewMode && (!isDisabled || isNavigationModule)) {
70
+ if (isPreview === "false" && (isDisabled === "false" || isNavigationModule)) {
108
71
  window.parent.postMessage({ type: "module-click", message: editorID }, "*");
109
72
  setSelectedContent?.(editorID);
110
73
  }
@@ -121,7 +84,7 @@ const FramePreview = (props: IProps) => {
121
84
  const theme = currentSiteInfo ? currentSiteInfo.theme : globalTheme;
122
85
  const langs = currentSiteInfo ? siteLangs : globalLangs;
123
86
  const siteID = currentSiteInfo ? currentSiteInfo.id : canonicalSite;
124
- const renderer = isForm ? "forms" : isPreviewMode ? "preview" : "editor";
87
+ const renderer = isForm ? "forms" : isPreview === "true" ? "preview" : "editor";
125
88
 
126
89
  const deleteModuleSelected = (editorID: number) => {
127
90
  window.parent.postMessage({ type: "module-delete", message: editorID }, "*");
@@ -149,8 +112,8 @@ const FramePreview = (props: IProps) => {
149
112
  if (isLoading) return <Loading />;
150
113
 
151
114
  return (
152
- <S.Wrapper>
153
- <S.GlobalScrollStyle />
115
+ // biome-ignore lint/suspicious/noAssignInExpressions: TODO: fix this
116
+ <S.Wrapper ref={(ref: any) => ((window as any).browserRef = ref)}>
154
117
  <BrowserContent
155
118
  cloudinaryName={cloudinaryName}
156
119
  theme={theme}
@@ -168,8 +131,6 @@ const FramePreview = (props: IProps) => {
168
131
  renderer={renderer}
169
132
  selectHoverEditorID={selectHoverEditorID}
170
133
  />
171
- {isHeadingsEditor && <S.Velo />}
172
- {isHeadingsEditor && <HeadingsOverlay headingFilter={headingFilter} />}
173
134
  {isVisible && <Toast message={toastState} setIsVisible={setIsVisible} />}
174
135
  </S.Wrapper>
175
136
  );
@@ -1,20 +1,4 @@
1
- import styled, { createGlobalStyle } from "styled-components";
2
-
3
- const GlobalScrollStyle = createGlobalStyle`
4
- body.preview {
5
- overflow-x: hidden;
6
- }
7
-
8
- body.preview::-webkit-scrollbar {
9
- -webkit-appearance: none;
10
- width: 4px;
11
- }
12
-
13
- body.preview::-webkit-scrollbar-thumb {
14
- border-radius: 4px;
15
- background-color: ${(p: any) => p.theme.colors.iconNonActive};
16
- }
17
- `;
1
+ import styled from "styled-components";
18
2
 
19
3
  const Wrapper = styled.div`
20
4
  scroll-behavior: smooth;
@@ -28,22 +12,6 @@ const Wrapper = styled.div`
28
12
  body.preview:not(&) {
29
13
  min-width: 0 !important;
30
14
  }
31
-
32
- .gdd-keyword {
33
- background-color: #FFEF9A !important;
34
- color: #1C1547 !important;
35
- padding: ${(p) => `0 ${p.theme.spacing.xxs}`};
36
- }
37
- `;
38
-
39
- const Velo = styled.div`
40
- position: fixed;
41
- top: 0;
42
- left: 0;
43
- height: 100%;
44
- right: 0;
45
- background: rgba(255, 255, 255, 0.4);
46
- z-index: 1000;
47
15
  `;
48
16
 
49
- export { Wrapper, Velo, GlobalScrollStyle };
17
+ export { Wrapper };