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

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 +23 -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 +90 -0
  14. package/lib/system-components/EditorMode/BlazeLogo.js.map +1 -0
  15. package/lib/system-components/EditorMode/PbWrapper.js +55 -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 +45 -0
  50. package/src/system-components/EditorMode/PbWrapper.js +27 -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,45 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { EDITOR_MODE_ICON_CLASS, EDITOR_MODE_HIGHLIGHT_CLASS } from './constants';
3
+
4
+ const BlazeLogo = ({ childNode, ...props }) => {
5
+ const { id } = props;
6
+ const [style, setStyle] = useState({});
7
+
8
+ useEffect(() => {
9
+ if (!childNode) return;
10
+
11
+ const rect = childNode.getBoundingClientRect();
12
+ const left = rect.width / 2 + rect.left + window.scrollX;
13
+ const top = rect.top - 20 + window.scrollY;
14
+ const display = childNode.classList.contains(EDITOR_MODE_HIGHLIGHT_CLASS) ? null : 'none';
15
+ const newStyle = { display, top, left };
16
+ setStyle(newStyle);
17
+
18
+ const observer = new MutationObserver(mutations => {
19
+ mutations.forEach(mutation => {
20
+ if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
21
+ const isHighlighted = childNode.classList.contains(EDITOR_MODE_HIGHLIGHT_CLASS);
22
+ setStyle({ ...newStyle, display: isHighlighted ? null : 'none' });
23
+ }
24
+ });
25
+ });
26
+ observer.observe(childNode, { attributes: true });
27
+ return () => observer.disconnect();
28
+ }, [childNode, id]);
29
+
30
+ // todo: fix icon hover/click activation while using position absolute
31
+ return (
32
+ <button type="button" className={EDITOR_MODE_ICON_CLASS} {...props} style={style}>
33
+ <svg xmlns="http://www.w3.org/2000/svg" width="22" height="33">
34
+ <path
35
+ fill="currentColor"
36
+ transform="translate(1.0415 1.85962)"
37
+ d="M7.0214715 6.2017469C7.0214715 6.2017469 4.6948299 13.380771 5.2965479 15.065234C5.6174636 15.947572 6.3796396 16.18821 7.3022733 15.386085C9.1074257 13.781834 13.078762 6.3621721 9.949831 0.42644304C8.7463951 -1.8596147 18.293648 5.1589837 16.328037 18.755013C16.087351 20.559793 16.809412 19.998306 17.250671 19.236286C19.176168 15.947572 17.972733 11.616095 17.972733 10.894181C17.972733 10.172268 19.657541 12.939602 19.777885 18.353949C19.89823 23.768295 17.050098 29.022219 11.393953 29.98477C10.03006 30.225407 13.199106 27.578392 13.640366 24.610529C13.68048 24.329784 10.39109 28.300306 9.5888004 27.738817C9.2277699 27.49818 15.36529 19.877987 13.199106 13.300558C13.158992 13.140133 11.754984 24.409996 6.3796396 27.097116C3.3309369 28.621155 0.60315031 25.051697 0.12177619 21.963514C-1.0415446 13.862046 6.4999828 8.7284422 7.0214715 6.2017469Z"
38
+ fillRule="evenodd"
39
+ />
40
+ </svg>
41
+ </button>
42
+ );
43
+ };
44
+
45
+ export default BlazeLogo;
@@ -0,0 +1,27 @@
1
+ import React, { 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
+ const unmount = addEditorModeEventListeners({ ref, name, adminHref, type, setLogoProps });
14
+
15
+ return unmount;
16
+ }, [adminHref, name, type]);
17
+
18
+ const TagName = `pb-wrapper-${type}`;
19
+ return (
20
+ <>
21
+ <TagName ref={ref} pb-component-name={name} />
22
+ {logoProps && createPortal(<BlazeLogo {...logoProps} />, document.body)}
23
+ </>
24
+ );
25
+ };
26
+
27
+ 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
  );