@blaze-cms/react-page-builder 0.146.0-node18-core-styles-tooltips.5 → 0.146.0-node18-core-styles-tooltips.11

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 (56) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -0
  3. package/lib/components/SearchContent/SearchContent.js +19 -11
  4. package/lib/components/SearchContent/SearchContent.js.map +1 -1
  5. package/lib/components/SearchFilter/SearchFilter/FiltersList.js +3 -1
  6. package/lib/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
  7. package/lib/components/SearchFilter/components/Range.js +11 -4
  8. package/lib/components/SearchFilter/components/Range.js.map +1 -1
  9. package/lib/hooks/helpers/RenderComponent.js +6 -4
  10. package/lib/hooks/helpers/RenderComponent.js.map +1 -1
  11. package/lib/hooks/use-app-sync-event-hook.js +17 -5
  12. package/lib/hooks/use-app-sync-event-hook.js.map +1 -1
  13. package/lib/system-components/EditorMode/BlazeLogo.js +83 -0
  14. package/lib/system-components/EditorMode/BlazeLogo.js.map +1 -0
  15. package/lib/system-components/EditorMode/PbWrapper.js +46 -0
  16. package/lib/system-components/EditorMode/PbWrapper.js.map +1 -0
  17. package/lib/system-components/EditorMode/constants.js +10 -0
  18. package/lib/system-components/EditorMode/constants.js.map +1 -0
  19. package/lib/system-components/EditorMode/helpers/add-editor-mode-event-listeners.js +127 -0
  20. package/lib/system-components/EditorMode/helpers/add-editor-mode-event-listeners.js.map +1 -0
  21. package/lib/system-components/index.js +25 -0
  22. package/lib/system-components/index.js.map +1 -0
  23. package/lib-es/components/SearchContent/SearchContent.js +22 -12
  24. package/lib-es/components/SearchContent/SearchContent.js.map +1 -1
  25. package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js +4 -2
  26. package/lib-es/components/SearchFilter/SearchFilter/FiltersList.js.map +1 -1
  27. package/lib-es/components/SearchFilter/components/Range.js +11 -4
  28. package/lib-es/components/SearchFilter/components/Range.js.map +1 -1
  29. package/lib-es/hooks/helpers/RenderComponent.js +6 -4
  30. package/lib-es/hooks/helpers/RenderComponent.js.map +1 -1
  31. package/lib-es/hooks/use-app-sync-event-hook.js +18 -6
  32. package/lib-es/hooks/use-app-sync-event-hook.js.map +1 -1
  33. package/lib-es/system-components/EditorMode/BlazeLogo.js +64 -0
  34. package/lib-es/system-components/EditorMode/BlazeLogo.js.map +1 -0
  35. package/lib-es/system-components/EditorMode/PbWrapper.js +34 -0
  36. package/lib-es/system-components/EditorMode/PbWrapper.js.map +1 -0
  37. package/lib-es/system-components/EditorMode/constants.js +3 -0
  38. package/lib-es/system-components/EditorMode/constants.js.map +1 -0
  39. package/lib-es/system-components/EditorMode/helpers/add-editor-mode-event-listeners.js +80 -0
  40. package/lib-es/system-components/EditorMode/helpers/add-editor-mode-event-listeners.js.map +1 -0
  41. package/lib-es/system-components/index.js +3 -0
  42. package/lib-es/system-components/index.js.map +1 -0
  43. package/package.json +3 -3
  44. package/src/components/SearchContent/SearchContent.js +21 -12
  45. package/src/components/SearchFilter/SearchFilter/FiltersList.js +75 -72
  46. package/src/components/SearchFilter/components/Range.js +12 -4
  47. package/src/hooks/helpers/RenderComponent.js +3 -2
  48. package/src/hooks/use-app-sync-event-hook.js +20 -6
  49. package/src/system-components/EditorMode/BlazeLogo.js +48 -0
  50. package/src/system-components/EditorMode/PbWrapper.js +30 -0
  51. package/src/system-components/EditorMode/constants.js +2 -0
  52. package/src/system-components/EditorMode/helpers/add-editor-mode-event-listeners.js +83 -0
  53. package/src/system-components/index.js +3 -0
  54. package/tests/unit/src/components/SearchFilter/components/Range.test.js +10 -0
  55. package/tests/unit/src/components/SearchFilter/components/__snapshots__/Range.test.js.snap +50 -0
  56. package/tests/unit/src/hooks/use-app-sync-evet-hook.test.js +35 -15
@@ -0,0 +1,30 @@
1
+ import { useRef, useEffect, useState } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import { useMainContext } from '@blaze-cms/nextjs-components';
4
+ import addEditorModeEventListeners from './helpers/add-editor-mode-event-listeners';
5
+ import BlazeLogo from './BlazeLogo';
6
+
7
+ const PbWrapper = ({ name, type = 'start' }) => {
8
+ const ref = useRef(null);
9
+ const [logoProps, setLogoProps] = useState(null);
10
+ const { debugOptions: { adminHref } = {} } = useMainContext();
11
+
12
+ useEffect(
13
+ () => {
14
+ const unmount = addEditorModeEventListeners({ ref, name, adminHref, type, setLogoProps });
15
+
16
+ return unmount;
17
+ },
18
+ [adminHref, name, type]
19
+ );
20
+
21
+ const TagName = `pb-wrapper-${type}`;
22
+ return (
23
+ <>
24
+ <TagName ref={ref} pb-component-name={name} />
25
+ {logoProps && createPortal(<BlazeLogo {...logoProps} />, document.body)}
26
+ </>
27
+ );
28
+ };
29
+
30
+ export default PbWrapper;
@@ -0,0 +1,2 @@
1
+ export const EDITOR_MODE_HIGHLIGHT_CLASS = 'blaze-pb-editor-highlight';
2
+ export const EDITOR_MODE_ICON_CLASS = 'blaze-pb-editor-icon';
@@ -0,0 +1,83 @@
1
+ import { getComponentId } from '../../../helpers';
2
+ import { EDITOR_MODE_HIGHLIGHT_CLASS } from '../constants';
3
+
4
+ const addEditorModeEventListeners = ({ ref, name, adminHref, type, setLogoProps }) => {
5
+ const listeners = [];
6
+
7
+ // ignore start tags and if parent not found
8
+ if (type !== 'end' || !ref.current || !ref.current.parentNode) return listeners;
9
+
10
+ const siblings = ref.current.parentNode.children;
11
+
12
+ const foundChildren = [];
13
+ let foundStart = false;
14
+ // eslint-disable-next-line no-restricted-syntax, no-unused-vars
15
+ for (const child of siblings) {
16
+ if (!foundStart) {
17
+ // find start tag
18
+ if (child.getAttribute('pb-component-name') === name) {
19
+ foundStart = true;
20
+ }
21
+ // eslint-disable-next-line no-continue
22
+ continue;
23
+ }
24
+
25
+ if (child === ref.current) {
26
+ // end tag found
27
+ break;
28
+ }
29
+
30
+ foundChildren.push(child); // all nodes between start and end tags - PB component nodes
31
+ }
32
+
33
+ const cleanUpFunctions = Object.values(siblings).map(childNode => {
34
+ const componentId = getComponentId(name);
35
+ const clickItemId = `click-${componentId}`;
36
+ const click = e => {
37
+ e.stopPropagation();
38
+ e.preventDefault();
39
+ window.open(`${adminHref}#${componentId}`, adminHref);
40
+ };
41
+ const mouseenter = e => {
42
+ document.querySelectorAll(`.${EDITOR_MODE_HIGHLIGHT_CLASS}`).forEach(node => {
43
+ node.classList.remove(EDITOR_MODE_HIGHLIGHT_CLASS);
44
+ });
45
+ childNode.classList.add(EDITOR_MODE_HIGHLIGHT_CLASS);
46
+
47
+ setLogoProps({
48
+ id: clickItemId,
49
+ 'aria-label': `Edit ${name}`,
50
+ childNode,
51
+ onclick: click
52
+ });
53
+ };
54
+ const mouseleave = e => {
55
+ childNode.classList.remove(EDITOR_MODE_HIGHLIGHT_CLASS);
56
+ setLogoProps(null);
57
+ };
58
+
59
+ childNode.addEventListener('click', click); // todo: remove listener and trigger on icon click
60
+ childNode.addEventListener('mouseenter', mouseenter);
61
+ childNode.addEventListener('mouseleave', mouseleave);
62
+
63
+ listeners.push([childNode, { click, mouseenter, mouseleave }]);
64
+
65
+ const nodeCleanup = () => {
66
+ listeners.forEach(([, events]) => {
67
+ Object.entries(events).forEach(([event, handler]) => {
68
+ childNode.removeEventListener(event, handler);
69
+ });
70
+ });
71
+ };
72
+
73
+ return nodeCleanup;
74
+ });
75
+
76
+ const unmount = () => {
77
+ cleanUpFunctions.forEach(fn => fn());
78
+ };
79
+
80
+ return unmount;
81
+ };
82
+
83
+ export default addEditorModeEventListeners;
@@ -0,0 +1,3 @@
1
+ import dynamic from 'next/dynamic';
2
+
3
+ export const PbWrapper = dynamic(() => import('./EditorMode/PbWrapper'));
@@ -96,6 +96,16 @@ describe('Range component', () => {
96
96
  expect(component).toMatchSnapshot();
97
97
  });
98
98
 
99
+ it('should match snapshot with unit prop', async () => {
100
+ const mockedProps = getMockedProps({
101
+ unit: 'm'
102
+ });
103
+ const component = await getMockedProvider(Range, {
104
+ props: { ...mockedProps }
105
+ });
106
+ expect(component.toJSON()).toMatchSnapshot();
107
+ });
108
+
99
109
  it('should match snapshot with adjusted min & max values based on interval', async () => {
100
110
  const mockedProps = getMockedProps({
101
111
  dataAggregations: {
@@ -234,3 +234,53 @@ exports[`Range component should match snapshot with interval and rounded min & m
234
234
  </div>
235
235
  </div>
236
236
  `;
237
+
238
+ exports[`Range component should match snapshot with unit prop 1`] = `
239
+ Array [
240
+ "",
241
+ <div
242
+ className="form-field form-field--range "
243
+ >
244
+ <label
245
+ className=""
246
+ >
247
+ GLabel (m)
248
+ </label>
249
+ <div
250
+ className="values"
251
+ >
252
+ <span>
253
+ 0
254
+ </span>
255
+ <span>
256
+ 6600
257
+ </span>
258
+ </div>
259
+ <div
260
+ className="range__filter name"
261
+ id="nameRange"
262
+ max={6600}
263
+ max-value={6600}
264
+ min={0}
265
+ min-value={0}
266
+ step={100}
267
+ >
268
+ <div
269
+ className="range__filter--left"
270
+ >
271
+ <span />
272
+ </div>
273
+ <div
274
+ className="range__filter--right"
275
+ >
276
+ <span />
277
+ </div>
278
+ <div
279
+ className="range__filter--line"
280
+ >
281
+ <span />
282
+ </div>
283
+ </div>
284
+ </div>,
285
+ ]
286
+ `;
@@ -4,17 +4,21 @@ import { AppContext } from '@blaze-cms/nextjs-components';
4
4
  import { useAppSyncEventHook } from '../../../../src/hooks';
5
5
 
6
6
  describe('useAppSyncEventHook', () => {
7
- test('should emit event with correct event name and data', () => {
8
- const blazeAppMock = {
9
- events: {
10
- emit: jest.fn()
11
- }
12
- };
7
+ const eventName = 'testEvent';
8
+ const data = { key: 'value' };
9
+ const props = { someProp: 'value' };
10
+
11
+ const blazeAppMock = {
12
+ events: {
13
+ emit: jest.fn()
14
+ }
15
+ };
13
16
 
14
- const eventName = 'testEvent';
15
- const data = { key: 'value' };
16
- const props = { someProp: 'value' };
17
+ beforeEach(() => {
18
+ jest.clearAllMocks();
19
+ });
17
20
 
21
+ test('should emit event with correct event name and data', () => {
18
22
  const wrapper = ({ children }) => (
19
23
  <AppContext.Provider value={{ blazeApp: blazeAppMock }}>{children}</AppContext.Provider>
20
24
  );
@@ -31,15 +35,31 @@ describe('useAppSyncEventHook', () => {
31
35
  expect(result.current.data).toEqual(data);
32
36
  });
33
37
 
34
- test('should return correct data', () => {
35
- const blazeAppMock = {
36
- events: {
37
- emit: jest.fn()
38
+ test('should not emit event on render when using returnFunction', () => {
39
+ const wrapper = ({ children }) => (
40
+ <AppContext.Provider value={{ blazeApp: blazeAppMock }}>{children}</AppContext.Provider>
41
+ );
42
+
43
+ const { result } = renderHook(
44
+ () => useAppSyncEventHook({ eventName, data, props, returnFunction: true }),
45
+ {
46
+ wrapper
38
47
  }
39
- };
48
+ );
40
49
 
41
- const data = { key: 'value' };
50
+ expect(blazeAppMock.events.emit).not.toHaveBeenCalled();
42
51
 
52
+ result.current.runHook();
53
+
54
+ expect(blazeAppMock.events.emit).toHaveBeenCalledWith(`plugin:page-builder:${eventName}:sync`, {
55
+ data,
56
+ props
57
+ });
58
+
59
+ expect(result.current.data).toEqual(data);
60
+ });
61
+
62
+ test('should return correct data', () => {
43
63
  const wrapper = ({ children }) => (
44
64
  <AppContext.Provider value={{ blazeApp: blazeAppMock }}>{children}</AppContext.Provider>
45
65
  );