@pushwoosh/dumb-components 2.9.8 → 2.9.10

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 (23) hide show
  1. package/Calendar/CalendarMonth/styles.js +2 -2
  2. package/Calendar/__tests__/CellBox.test.d.ts +1 -0
  3. package/Calendar/__tests__/CellBox.test.js +34 -0
  4. package/RichMessageEditor/{EditorEmojiPicker.js → EditorEmojiPicker/EditorEmojiPicker.js} +3 -3
  5. package/RichMessageEditor/EditorEmojiPicker/index.d.ts +1 -0
  6. package/RichMessageEditor/EditorEmojiPicker/index.js +1 -0
  7. package/RichMessageEditor/{EditorEmojiPicker.styles.js → EditorEmojiPicker/styles.js} +1 -1
  8. package/RichMessageEditor/RichMessageEditor.js +1 -1
  9. package/RichMessageEditor/slate/SlateEditor.js +1 -1
  10. package/RichMessageEditor/slate/{SlateEditor.styles.js → styles.js} +1 -1
  11. package/RichMessageEditor/{RichMessageEditor.styles.js → styles.js} +4 -4
  12. package/package.json +1 -1
  13. package/shared/dropdownField/__tests__/useDropdownPosition.test.d.ts +1 -0
  14. package/shared/dropdownField/__tests__/useDropdownPosition.test.js +60 -0
  15. package/shared/dropdownField/constants.d.ts +1 -1
  16. package/shared/dropdownField/constants.js +1 -1
  17. package/shared/dropdownField/useDropdownPosition.js +2 -2
  18. /package/RichMessageEditor/{EditorEmojiPicker.d.ts → EditorEmojiPicker/EditorEmojiPicker.d.ts} +0 -0
  19. /package/RichMessageEditor/{EditorEmojiPicker.helpers.d.ts → EditorEmojiPicker/EditorEmojiPicker.helpers.d.ts} +0 -0
  20. /package/RichMessageEditor/{EditorEmojiPicker.helpers.js → EditorEmojiPicker/EditorEmojiPicker.helpers.js} +0 -0
  21. /package/RichMessageEditor/{EditorEmojiPicker.styles.d.ts → EditorEmojiPicker/styles.d.ts} +0 -0
  22. /package/RichMessageEditor/slate/{SlateEditor.styles.d.ts → styles.d.ts} +0 -0
  23. /package/RichMessageEditor/{RichMessageEditor.styles.d.ts → styles.d.ts} +0 -0
@@ -8,8 +8,8 @@ const periodToCss = css(["border-top-left-radius:0;border-bottom-left-radius:0;"
8
8
  const disabledCss = css(["font-weight:", ";color:", ";border:1px solid ", ";background:linear-gradient( to top left,rgba(0,0,0,0) 0%,rgba(0,0,0,0) calc(50% - 0.8px),", " 50%,rgba(0,0,0,0) calc(50% + 0.8px),rgba(0,0,0,0) 100% );pointer-events:none;"], FontWeight.REGULAR, Color.PHANTOM, Color.DIVIDER, Color.DIVIDER);
9
9
  const outdatedCss = css(["opacity:0;pointer-events:none;"]);
10
10
  const highlightedCss = css(["outline:1px solid ", ";"], Color.SOFT_LIGHT);
11
- const periodCss = css(["position:relative;z-index:0;:before{content:'';position:absolute;top:0;left:-1px;right:-1px;bottom:0;background:", ";z-index:-1;}"], Color.SOFT_LIGHT);
12
- const periodOutdatedCss = css(["position:relative;z-index:0;color:transparent;pointer-events:none;:before{content:'';position:absolute;top:0;left:-1px;right:-1px;bottom:0;background:", ";z-index:-1;}"], Color.SOFT_LIGHT);
11
+ const periodCss = css(["position:relative;z-index:0;&:before{content:'';position:absolute;top:0;left:-1px;right:-1px;bottom:0;background:", ";z-index:-1;}"], Color.SOFT_LIGHT);
12
+ const periodOutdatedCss = css(["position:relative;z-index:0;color:transparent;pointer-events:none;&:before{content:'';position:absolute;top:0;left:-1px;right:-1px;bottom:0;background:", ";z-index:-1;}"], Color.SOFT_LIGHT);
13
13
  const cssMap = {
14
14
  selected: selectedCss,
15
15
  selectedDisabled: selectedDisabledCss,
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render, screen } from '@testing-library/react';
3
+ import { CellBox } from '../CalendarMonth/styles';
4
+ const PERIOD_VARIANTS = ['period', 'periodOutdated'];
5
+ function variantCss(variant) {
6
+ const {
7
+ rules
8
+ } = CellBox.componentStyle;
9
+ const flatten = part => {
10
+ if (Array.isArray(part)) return part.map(flatten).join('');
11
+ return typeof part === 'string' ? part : '';
12
+ };
13
+ return rules.filter(rule => typeof rule === 'function').map(rule => flatten(rule({
14
+ $variant: variant
15
+ }))).join('');
16
+ }
17
+ describe('CellBox period variants', () => {
18
+ it.each(PERIOD_VARIANTS)('anchors :before of %s to the cell with &, so stylis 4 does not turn it into a descendant selector', variant => {
19
+ const css = variantCss(variant);
20
+ expect(css).toContain('&:before');
21
+ expect(css).not.toMatch(/(^|[\s;{}])::?before/);
22
+ });
23
+ it.each(PERIOD_VARIANTS)('paints the %s background on the cell pseudo-element', variant => {
24
+ render(_jsx(CellBox, {
25
+ "data-testid": "cell",
26
+ "$variant": variant,
27
+ children: "1"
28
+ }));
29
+ const [className] = [...screen.getByTestId('cell').classList].slice(-1);
30
+ const styles = [...document.querySelectorAll('style')].map(node => node.textContent).join('');
31
+ expect(styles).toMatch(new RegExp(`\\.${className}:before\\{[^}]*background:`));
32
+ expect(styles).not.toContain(`.${className} :before`);
33
+ });
34
+ });
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useRef } from 'react';
3
- import { EditorEmojiPickerStyled } from './EditorEmojiPicker.styles';
4
- import { EmojiPicker } from '../EmojiPicker';
5
- import { useThemeName } from '../hooks';
3
+ import { EditorEmojiPickerStyled } from './styles';
4
+ import { EmojiPicker } from '../../EmojiPicker';
5
+ import { useThemeName } from '../../hooks';
6
6
  export const EditorEmojiPicker = ({
7
7
  onEmojiSelect
8
8
  }) => {
@@ -0,0 +1 @@
1
+ export * from './EditorEmojiPicker';
@@ -0,0 +1 @@
1
+ export * from './EditorEmojiPicker';
@@ -3,7 +3,7 @@ import { Color, getThemeColors, Shadow, ShapeRadius } from '@pushwoosh/kit-const
3
3
  import { rgbChannels } from './EditorEmojiPicker.helpers';
4
4
  export const EditorEmojiPickerStyled = styled.div.withConfig({
5
5
  displayName: "EditorEmojiPickerStyled",
6
- componentId: "sc-1jl3t23-0"
6
+ componentId: "sc-1y0c927-0"
7
7
  })(["min-width:352px;em-emoji-picker{border:1px solid ", ";--border-radius:", ";--shadow:", ";background-color:", ";--rgb-background:", ";}"], Color.FORM, ShapeRadius.CONTROL, Shadow.REGULAR, Color.FROZEN, ({
8
8
  $theme
9
9
  }) => rgbChannels(getThemeColors($theme).FROZEN));
@@ -10,9 +10,9 @@ import EmojiIcon from './assets/EmojiIcon.svg';
10
10
  import PersonalizationIcon from './assets/PersonalizationIcon.svg';
11
11
  import { EditorEmojiPicker } from './EditorEmojiPicker';
12
12
  import { placementToDirection } from './RichMessageEditor.helpers';
13
- import { Arrow, DropArea, DropContent, ImSpan } from './RichMessageEditor.styles';
14
13
  import { getDcByPath } from './slate/helpers';
15
14
  import { SlateEditable, SlateEditor } from './slate/SlateEditor';
15
+ import { Arrow, DropArea, DropContent, ImSpan } from './styles';
16
16
  /**
17
17
  * Slate-based message editor with optional personalization (dynamic-content) tokens
18
18
  * and an emoji picker; serializes to a string via `onChange`. Render the result with
@@ -4,8 +4,8 @@ import { Slate } from 'slate-react';
4
4
  import { usePersistentFunction } from '@pushwoosh/kit-helpers';
5
5
  import { renderElement } from './DynamicContentElement';
6
6
  import { content2string, string2content } from './helpers';
7
- import { EditableStyled } from './SlateEditor.styles';
8
7
  import { createMKEditor } from './SlateEditor.utils';
8
+ import { EditableStyled } from './styles';
9
9
  export const SlateEditor = ({
10
10
  initialValue: initialValueString,
11
11
  onChange,
@@ -3,7 +3,7 @@ import styled from 'styled-components';
3
3
  import { Color, FontSize, FontWeight, ShapeRadius } from '@pushwoosh/kit-constants';
4
4
  export const EditableStyled = styled(Editable).withConfig({
5
5
  displayName: "EditableStyled",
6
- componentId: "sc-13jikil-0"
6
+ componentId: "sc-16lukqt-0"
7
7
  })(["font-weight:", ";font-size:", ";line-height:140%;padding:8px;color:", ";background:", ";caret-color:", ";border:1px solid ", ";border-radius:", ";overflow-x:auto;& [data-slate-placeholder='true']{color:", ";opacity:1 !important;}&:focus{border-color:", ";outline:none;}& > p{position:relative;margin:4px 0;&:first-child{margin-top:0;}&:last-child{margin-bottom:0;}}"], FontWeight.REGULAR, FontSize.REGULAR, Color.MAIN, Color.CLEAR, Color.BRIGHT, ({
8
8
  $isErrored
9
9
  }) => $isErrored ? Color.DANGER : Color.FORM, ShapeRadius.CONTROL, Color.PHANTOM, Color.BRIGHT);
@@ -3,15 +3,15 @@ import { Color, Shadow, ShapeRadius } from '@pushwoosh/kit-constants';
3
3
  import { Horizontal } from '@pushwoosh/kit-helpers';
4
4
  export const ImSpan = styled.span.withConfig({
5
5
  displayName: "ImSpan",
6
- componentId: "sc-1l3r9n8-0"
6
+ componentId: "sc-1n9vpwc-0"
7
7
  })(["color:", ";position:relative;padding-left:20px;font-size:12px;font-style:normal;font-weight:500;line-height:130%;text-transform:uppercase;cursor:pointer;> svg{position:absolute;left:0;top:-1px;}"], Color.SOFT);
8
8
  export const DropArea = styled.div.withConfig({
9
9
  displayName: "DropArea",
10
- componentId: "sc-1l3r9n8-1"
10
+ componentId: "sc-1n9vpwc-1"
11
11
  })(["z-index:1000;"]);
12
12
  export const DropContent = styled.div.withConfig({
13
13
  displayName: "DropContent",
14
- componentId: "sc-1l3r9n8-2"
14
+ componentId: "sc-1n9vpwc-2"
15
15
  })(["border:1px solid ", ";border-radius:", ";box-shadow:", ";background-color:", ";"], Color.FORM, ShapeRadius.CONTROL, Shadow.REGULAR, Color.FROZEN);
16
16
  const transforms = {
17
17
  left: 'scaleX(-1)',
@@ -23,7 +23,7 @@ export const Arrow = styled(Horizontal).attrs({
23
23
  $placeItems: 'center'
24
24
  }).withConfig({
25
25
  displayName: "Arrow",
26
- componentId: "sc-1l3r9n8-3"
26
+ componentId: "sc-1n9vpwc-3"
27
27
  })(["position:absolute;width:20px;height:20px;transform:", " translateX(11px);", ":0;"], ({
28
28
  $direction
29
29
  }) => transforms[$direction], ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "2.9.8",
3
+ "version": "2.9.10",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -0,0 +1,60 @@
1
+ import { renderHook } from '@testing-library/react';
2
+ import { useDropdownPosition } from '../useDropdownPosition';
3
+ const floating = {
4
+ middleware: []
5
+ };
6
+ jest.mock('@floating-ui/react-dom', () => ({
7
+ ...jest.requireActual('@floating-ui/react-dom'),
8
+ size: options => ({
9
+ name: 'size',
10
+ options
11
+ }),
12
+ useFloating: config => {
13
+ floating.middleware = config.middleware;
14
+ return {
15
+ refs: {
16
+ reference: {
17
+ current: null
18
+ },
19
+ floating: {
20
+ current: null
21
+ },
22
+ setReference: jest.fn(),
23
+ setFloating: jest.fn()
24
+ },
25
+ floatingStyles: {}
26
+ };
27
+ }
28
+ }));
29
+ const maxHeightFor = availableHeight => {
30
+ renderHook(() => useDropdownPosition({
31
+ isOpen: true
32
+ }));
33
+ const style = {};
34
+ floating.middleware.find(m => m.name === 'size').options.apply({
35
+ rects: {
36
+ reference: {
37
+ width: 200
38
+ }
39
+ },
40
+ elements: {
41
+ floating: {
42
+ style
43
+ }
44
+ },
45
+ availableWidth: 1000,
46
+ availableHeight
47
+ });
48
+ return style.maxHeight;
49
+ };
50
+ describe('useDropdownPosition max height', () => {
51
+ it('caps the dropdown at 300px when there is more room', () => {
52
+ expect(maxHeightFor(1200)).toBe('300px');
53
+ });
54
+ it('shrinks to the room below the field when it is less than the cap', () => {
55
+ expect(maxHeightFor(200)).toBe('192px');
56
+ });
57
+ it('never goes negative', () => {
58
+ expect(maxHeightFor(4)).toBe('0px');
59
+ });
60
+ });
@@ -1,7 +1,7 @@
1
1
  import { Color } from '@pushwoosh/kit-constants';
2
2
  export declare const LOADING_BORDER_COLORS: readonly [Color.PRIMARY, Color.BRIGHT, Color.BRAND_GREEN, Color.EXCEPTIONAL];
3
3
  export declare const LOADING_BORDER_ANIMATION_MS = 3000;
4
- export declare const DROPDOWN_MAX_HEIGHT = 280;
4
+ export declare const DROPDOWN_MAX_HEIGHT = 300;
5
5
  /** Default dropdown width cap. A field wider than this stretches the dropdown to its own width only when the field opts in via `fullWidth`; otherwise the dropdown stays capped here. */
6
6
  export declare const DROPDOWN_DEFAULT_WIDTH = 320;
7
7
  /** Default debounce (ms) before an async `loadItems` call fires after the query changes. */
@@ -1,7 +1,7 @@
1
1
  import { Color } from '@pushwoosh/kit-constants';
2
2
  export const LOADING_BORDER_COLORS = [Color.PRIMARY, Color.BRIGHT, Color.BRAND_GREEN, Color.EXCEPTIONAL];
3
3
  export const LOADING_BORDER_ANIMATION_MS = 3000;
4
- export const DROPDOWN_MAX_HEIGHT = 280;
4
+ export const DROPDOWN_MAX_HEIGHT = 300;
5
5
  /** Default dropdown width cap. A field wider than this stretches the dropdown to its own width only when the field opts in via `fullWidth`; otherwise the dropdown stays capped here. */
6
6
  export const DROPDOWN_DEFAULT_WIDTH = 320;
7
7
  /** Default debounce (ms) before an async `loadItems` call fires after the query changes. */
@@ -1,5 +1,5 @@
1
1
  import { autoUpdate, flip, offset, size, useFloating } from '@floating-ui/react-dom';
2
- import { DROPDOWN_DEFAULT_WIDTH } from './constants';
2
+ import { DROPDOWN_DEFAULT_WIDTH, DROPDOWN_MAX_HEIGHT } from './constants';
3
3
  import { useOnClickOutside } from '../../hooks';
4
4
  /**
5
5
  * Positions the dropdown relative to the field via floating-ui (flip, offset,
@@ -32,7 +32,7 @@ export function useDropdownPosition({
32
32
  Object.assign(elements.floating.style, {
33
33
  minWidth: `${minWidth}px`,
34
34
  maxWidth: `${maxWidth}px`,
35
- maxHeight: `${Math.max(0, availableHeight - 8)}px`
35
+ maxHeight: `${Math.max(0, Math.min(DROPDOWN_MAX_HEIGHT, availableHeight - 8))}px`
36
36
  });
37
37
  }
38
38
  })],