@pushwoosh/smart-components-kit 1.3.20 → 1.3.22

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.
@@ -1,14 +1,16 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect } from 'react';
3
- import { FieldBox, NativeInput, Select, Spinner } from '@pushwoosh/dumb-components';
3
+ import { Combobox, FieldBox, NativeInput, Spinner } from '@pushwoosh/dumb-components';
4
4
  import { Horizontal, Vertical } from '@pushwoosh/kit-helpers';
5
5
  import { useDynamicContentTags } from './hooks';
6
6
  import { useLang } from './polyglot';
7
7
  import { SimpleTagPickerDiv } from './styled';
8
- import { buildOptions } from './utils';
8
+ import { allDynamicContentModifiers, buildOptions } from './utils';
9
+ const defaultModifier = 'regular';
10
+ const matchesQuery = (value, query) => value.toLowerCase().includes(query.trim().toLowerCase());
9
11
  const defaultDynamicContent = {
10
12
  tagName: '',
11
- modifier: 'regular',
13
+ modifier: defaultModifier,
12
14
  defaultValue: ''
13
15
  };
14
16
  export const SimpleDynamicContentPickerFormSmart = ({
@@ -37,10 +39,19 @@ export const SimpleDynamicContentPickerFormSmart = ({
37
39
  });
38
40
  }
39
41
  const options = buildOptions(systemVariables ?? [], asyncResult.value || []);
40
- const selectedTag = options.find(option => option.name === dc.tagName) || {
41
- name: '',
42
- label: '',
43
- modifiers: ['regular']
42
+ const pickedOption = options.find(option => option.name === dc.tagName);
43
+ const modifiers = pickedOption?.modifiers ?? allDynamicContentModifiers;
44
+ const isEmpty = !dc.tagName.trim();
45
+ const labelOf = name => options.find(option => option.name === name)?.label ?? name;
46
+ const changeTagName = (tagName, isPicked) => {
47
+ const option = options.find(item => item.name === tagName);
48
+ const nextModifiers = option?.modifiers ?? allDynamicContentModifiers;
49
+ const keepModifier = !isPicked && nextModifiers.includes(dc.modifier);
50
+ onChange({
51
+ tagName,
52
+ modifier: keepModifier ? dc.modifier : nextModifiers[0] ?? defaultModifier,
53
+ defaultValue: isPicked ? '' : dc.defaultValue
54
+ });
44
55
  };
45
56
  return _jsxs(SimpleTagPickerDiv, {
46
57
  children: [_jsx(FieldBox, {
@@ -49,43 +60,30 @@ export const SimpleDynamicContentPickerFormSmart = ({
49
60
  }),
50
61
  children: _jsxs(Vertical, {
51
62
  "$gap": 8,
52
- children: [_jsx(Select, {
53
- width: "auto",
54
- menuPlacement: "auto",
55
- value: {
56
- value: dc.tagName,
57
- label: selectedTag.name ? selectedTag.label : dc.tagName
58
- },
59
- onChange: option => {
60
- const picked = options.find(item => item.name === option.value);
61
- onChange({
62
- tagName: option.value,
63
- modifier: picked?.modifiers[0] ?? 'regular',
64
- defaultValue: ''
65
- });
66
- },
67
- options: options.map(option => ({
68
- value: option.name,
69
- label: option.label
70
- }))
71
- }), _jsx(Select, {
72
- width: "auto",
73
- menuPlacement: "auto",
74
- value: {
75
- value: dc.modifier,
76
- label: dc.modifier
77
- },
78
- onChange: option => {
63
+ children: [_jsx(Combobox, {
64
+ value: dc.tagName,
65
+ onChange: (value, meta) => changeTagName(value, meta.source === 'select'),
66
+ items: options.map(option => option.name),
67
+ getLabel: name => name,
68
+ renderItem: name => labelOf(name),
69
+ filter: (name, query) => matchesQuery(name, query) || matchesQuery(labelOf(name), query),
70
+ placeholder: lang({
71
+ message: 'SMART.DYNAMIC_CONTENT_PICKER_FORM.TAG.PLACEHOLDER'
72
+ }),
73
+ fullWidth: true
74
+ }), _jsx(Combobox, {
75
+ select: true,
76
+ value: dc.modifier || null,
77
+ onChange: modifier => {
79
78
  onChange({
80
79
  ...dc,
81
- modifier: option.value
80
+ modifier: modifier ?? ''
82
81
  });
83
82
  },
84
- options: selectedTag.modifiers.map(modifier => ({
85
- value: modifier,
86
- label: modifier
87
- })),
88
- isDisabled: !selectedTag.name
83
+ items: modifiers,
84
+ getLabel: modifier => modifier,
85
+ disabled: isEmpty,
86
+ fullWidth: true
89
87
  })]
90
88
  })
91
89
  }), _jsx(FieldBox, {
@@ -100,7 +98,7 @@ export const SimpleDynamicContentPickerFormSmart = ({
100
98
  defaultValue: e.target.value
101
99
  });
102
100
  },
103
- disabled: !selectedTag.name
101
+ disabled: isEmpty
104
102
  })
105
103
  }), children]
106
104
  });
@@ -1,3 +1,4 @@
1
1
  import { type FullTagData, type PickerOption, type SystemVariable, type VariedDynamicContent } from './types';
2
2
  export declare function buildOptions(systemVariables: SystemVariable[], tags: FullTagData[]): PickerOption[];
3
3
  export declare function createDefaultDynamicContent(kind: 'tag' | 'event' | 'customText'): VariedDynamicContent;
4
+ export declare const allDynamicContentModifiers: string[];
@@ -1,3 +1,4 @@
1
+ import { DynamicContentModifiers } from '@pushwoosh/kit-constants';
1
2
  export function buildOptions(systemVariables, tags) {
2
3
  const taken = new Set(systemVariables.map(v => v.name));
3
4
  const system = systemVariables.map(v => ({
@@ -40,4 +41,5 @@ export function createDefaultDynamicContent(kind) {
40
41
  }
41
42
  };
42
43
  }
43
- }
44
+ }
45
+ export const allDynamicContentModifiers = [...DynamicContentModifiers.string, ...DynamicContentModifiers.integer.filter(modifier => !DynamicContentModifiers.string.includes(modifier))];
@@ -1,4 +1,11 @@
1
1
  export declare const CardImage: import("styled-components").StyledComponent<"img", any, {}, never>;
2
2
  export declare const ContentBox: import("styled-components").StyledComponent<"div", any, {}, never>;
3
- export declare const List: import("styled-components").StyledComponent<"ul", any, {}, never>;
3
+ export declare const List: import("styled-components").StyledComponent<"span", any, {
4
+ $color?: string;
5
+ $uppercase?: boolean;
6
+ $ellipsis?: boolean;
7
+ $variant?: import("@pushwoosh/kit-typography").TypographyVariant;
8
+ } & {
9
+ as: string;
10
+ }, "as">;
4
11
  export declare const Bold: import("styled-components").StyledComponent<"strong", any, {}, never>;
@@ -1,5 +1,6 @@
1
1
  import styled from 'styled-components';
2
2
  import { FontWeight, ShapeRadius } from '@pushwoosh/kit-constants';
3
+ import { Text } from '@pushwoosh/kit-typography';
3
4
  // The only rule kit-helpers cannot express: object-fit has no prop there, and it is
4
5
  // what keeps a wrongly proportioned upload from stretching the card.
5
6
  export const CardImage = styled.img.withConfig({
@@ -12,7 +13,11 @@ export const ContentBox = styled.div.withConfig({
12
13
  displayName: "ContentBox",
13
14
  componentId: "sc-11vonu6-1"
14
15
  })(["> * + *{margin-top:0.5em;}"]);
15
- export const List = styled.ul.withConfig({
16
+ // Built on Text, not on a bare <ul>: the paragraph typography lives in that variant, and
17
+ // a plain list would keep the surrounding font size — 16px next to the card's 14px.
18
+ export const List = styled(Text).attrs({
19
+ as: 'ul'
20
+ }).withConfig({
16
21
  displayName: "List",
17
22
  componentId: "sc-11vonu6-2"
18
23
  })(["margin:0;padding-left:1.25em;list-style:disc outside;li + li{margin-top:0.25em;}"]);
@@ -21,7 +21,7 @@ export const NewDynamicContentForm = ({
21
21
  children: _jsx(Button, {
22
22
  color: "secondary",
23
23
  onClick: () => onSubmit(dc),
24
- isDisabled: !dc,
24
+ isDisabled: !dc?.tagName.trim(),
25
25
  children: lang({
26
26
  message: 'SMART.RICH_MESSAGE_EDITOR.INSERT'
27
27
  })
package/package.json CHANGED
@@ -54,5 +54,5 @@
54
54
  "react": "^16.14.0 || ^18.0.0",
55
55
  "react-dom": "^16.14.0 || ^18.0.0"
56
56
  },
57
- "version": "1.3.20"
57
+ "version": "1.3.22"
58
58
  }