@pushwoosh/smart-components-kit 1.1.7 → 1.1.9

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,9 +1,11 @@
1
1
  import { type FC, type PropsWithChildren } from 'react';
2
2
  import { type DynamicContent } from '@pushwoosh/dumb-components/RichMessageEditor/slate/types';
3
+ import type { SystemVariable } from './types';
3
4
  type SimpleDynamicContentPickerFormSmartProps = {
4
5
  dc?: DynamicContent;
5
6
  onChange: (dc: DynamicContent) => void;
6
7
  update?: () => void;
8
+ systemVariables?: SystemVariable[];
7
9
  };
8
10
  export declare const SimpleDynamicContentPickerFormSmart: FC<PropsWithChildren<SimpleDynamicContentPickerFormSmartProps>>;
9
11
  export {};
@@ -5,6 +5,7 @@ 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
9
  const defaultDynamicContent = {
9
10
  tagName: '',
10
11
  modifier: 'regular',
@@ -14,6 +15,7 @@ export const SimpleDynamicContentPickerFormSmart = ({
14
15
  dc = defaultDynamicContent,
15
16
  onChange,
16
17
  update,
18
+ systemVariables,
17
19
  children
18
20
  }) => {
19
21
  const lang = useLang();
@@ -34,9 +36,10 @@ export const SimpleDynamicContentPickerFormSmart = ({
34
36
  })
35
37
  });
36
38
  }
37
- const tags = asyncResult.value || [];
38
- const currentTag = tags.find(tag => tag.name === dc.tagName) || {
39
+ const options = buildOptions(systemVariables ?? [], asyncResult.value || []);
40
+ const selectedTag = options.find(option => option.name === dc.tagName) || {
39
41
  name: '',
42
+ label: '',
40
43
  modifiers: ['regular']
41
44
  };
42
45
  return _jsxs(SimpleTagPickerDiv, {
@@ -51,18 +54,19 @@ export const SimpleDynamicContentPickerFormSmart = ({
51
54
  menuPlacement: "auto",
52
55
  value: {
53
56
  value: dc.tagName,
54
- label: dc.tagName
57
+ label: selectedTag.name ? selectedTag.label : dc.tagName
55
58
  },
56
59
  onChange: option => {
60
+ const picked = options.find(item => item.name === option.value);
57
61
  onChange({
58
62
  tagName: option.value,
59
- modifier: currentTag.modifiers[0],
63
+ modifier: (picked === null || picked === void 0 ? void 0 : picked.modifiers[0]) ?? 'regular',
60
64
  defaultValue: ''
61
65
  });
62
66
  },
63
- options: tags.map(tag => ({
64
- value: tag.name,
65
- label: tag.name
67
+ options: options.map(option => ({
68
+ value: option.name,
69
+ label: option.label
66
70
  }))
67
71
  }), _jsx(Select, {
68
72
  width: "auto",
@@ -77,11 +81,11 @@ export const SimpleDynamicContentPickerFormSmart = ({
77
81
  modifier: option.value
78
82
  });
79
83
  },
80
- options: currentTag.modifiers.map(modifier => ({
84
+ options: selectedTag.modifiers.map(modifier => ({
81
85
  value: modifier,
82
86
  label: modifier
83
87
  })),
84
- isDisabled: !currentTag.name
88
+ isDisabled: !selectedTag.name
85
89
  })]
86
90
  })
87
91
  }), _jsx(FieldBox, {
@@ -96,7 +100,7 @@ export const SimpleDynamicContentPickerFormSmart = ({
96
100
  defaultValue: e.target.value
97
101
  });
98
102
  },
99
- disabled: !currentTag.name
103
+ disabled: !selectedTag.name
100
104
  })
101
105
  }), children]
102
106
  });
@@ -1,3 +1,3 @@
1
1
  export { SimpleDynamicContentPickerFormSmart } from './SimpleDynamicContentPickerFormSmart';
2
- export type { VariedDynamicContent } from './types';
2
+ export type { VariedDynamicContent, SystemVariable, PickerOption } from './types';
3
3
  export * from './hooks';
@@ -2,6 +2,16 @@ import type { Tag } from '@pushwoosh/rpc-v2-http-api-data/tags';
2
2
  export type FullTagData = Tag & {
3
3
  modifiers: string[];
4
4
  };
5
+ export type SystemVariable = {
6
+ name: string;
7
+ label?: string;
8
+ modifiers?: string[];
9
+ };
10
+ export type PickerOption = {
11
+ name: string;
12
+ label: string;
13
+ modifiers: string[];
14
+ };
5
15
  export type TagDynamicContent = {
6
16
  kind: 'tag';
7
17
  dc: {
@@ -1,2 +1,3 @@
1
- import { type VariedDynamicContent } from './types';
1
+ import { type FullTagData, type PickerOption, type SystemVariable, type VariedDynamicContent } from './types';
2
+ export declare function buildOptions(systemVariables: SystemVariable[], tags: FullTagData[]): PickerOption[];
2
3
  export declare function createDefaultDynamicContent(kind: 'tag' | 'event' | 'customText'): VariedDynamicContent;
@@ -1,3 +1,17 @@
1
+ export function buildOptions(systemVariables, tags) {
2
+ const taken = new Set(systemVariables.map(v => v.name));
3
+ const system = systemVariables.map(v => ({
4
+ name: v.name,
5
+ label: v.label ?? v.name,
6
+ modifiers: v.modifiers ?? ['regular']
7
+ }));
8
+ const rest = tags.filter(tag => !taken.has(tag.name)).map(tag => ({
9
+ name: tag.name,
10
+ label: tag.name,
11
+ modifiers: tag.modifiers
12
+ }));
13
+ return [...system, ...rest];
14
+ }
1
15
  export function createDefaultDynamicContent(kind) {
2
16
  switch (kind) {
3
17
  case 'tag':
@@ -1,8 +1,10 @@
1
1
  import { type FC } from 'react';
2
2
  import { type DynamicContent } from '@pushwoosh/dumb-components/RichMessageEditor/slate/types';
3
+ import { type SystemVariable } from '../DynamicContentPickerForm';
3
4
  type NewDynamicContentFormProps = {
4
5
  update?: () => void;
5
6
  onSubmit: (dc: DynamicContent) => void;
7
+ systemVariables?: SystemVariable[];
6
8
  };
7
9
  export declare const NewDynamicContentForm: FC<NewDynamicContentFormProps>;
8
10
  export {};
@@ -2,11 +2,12 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
3
  import { Button } from '@pushwoosh/dumb-components';
4
4
  import { Horizontal } from '@pushwoosh/kit-helpers';
5
- import { SimpleDynamicContentPickerFormSmart } from '../DynamicContentPickerForm';
6
5
  import { useLang } from './polyglot';
6
+ import { SimpleDynamicContentPickerFormSmart } from '../DynamicContentPickerForm';
7
7
  export const NewDynamicContentForm = ({
8
8
  update,
9
- onSubmit
9
+ onSubmit,
10
+ systemVariables
10
11
  }) => {
11
12
  const [dc, setDc] = useState();
12
13
  const lang = useLang();
@@ -14,6 +15,7 @@ export const NewDynamicContentForm = ({
14
15
  dc: dc,
15
16
  onChange: setDc,
16
17
  update: update,
18
+ systemVariables: systemVariables,
17
19
  children: _jsx(Horizontal, {
18
20
  "$justifyContent": "end",
19
21
  children: _jsx(Button, {
@@ -1,5 +1,8 @@
1
1
  import { type FC } from 'react';
2
2
  import { type RichMessageEditorProps } from '@pushwoosh/dumb-components/RichMessageEditor/RichMessageEditor.types';
3
- type RichMessageEditorSmartProps = Omit<RichMessageEditorProps, 'renderDynamicContent'>;
3
+ import { type SystemVariable } from '../DynamicContentPickerForm';
4
+ type RichMessageEditorSmartProps = Omit<RichMessageEditorProps, 'renderDynamicContent'> & {
5
+ systemVariables?: SystemVariable[];
6
+ };
4
7
  export declare const RichMessageEditorSmart: FC<RichMessageEditorSmartProps>;
5
8
  export {};
@@ -1,8 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { RichMessageEditor } from '@pushwoosh/dumb-components';
3
- import { SimpleDynamicContentPickerFormSmart } from '../DynamicContentPickerForm';
4
3
  import { NewDynamicContentForm } from './NewDynamicContentForm';
5
- export const RichMessageEditorSmart = props => {
4
+ import { SimpleDynamicContentPickerFormSmart } from '../DynamicContentPickerForm';
5
+ export const RichMessageEditorSmart = ({
6
+ systemVariables,
7
+ ...props
8
+ }) => {
6
9
  return _jsx(RichMessageEditor, {
7
10
  ...props,
8
11
  renderDynamicContent: ({
@@ -12,10 +15,12 @@ export const RichMessageEditorSmart = props => {
12
15
  }) => dc ? _jsx(SimpleDynamicContentPickerFormSmart, {
13
16
  dc: dc,
14
17
  onChange: onChange,
15
- update: update
18
+ update: update,
19
+ systemVariables: systemVariables
16
20
  }) : _jsx(NewDynamicContentForm, {
17
21
  update: update,
18
- onSubmit: onChange
22
+ onSubmit: onChange,
23
+ systemVariables: systemVariables
19
24
  })
20
25
  });
21
26
  };
@@ -0,0 +1,6 @@
1
+ import { type ComponentProps } from 'react';
2
+ declare const StyledItemDetailLink: import("styled-components").StyledComponent<"a", any, {}, never>;
3
+ export declare function ItemDetailLink({ withChevron, children, ...props }: ComponentProps<typeof StyledItemDetailLink> & {
4
+ withChevron?: boolean;
5
+ }): import("react").JSX.Element;
6
+ export {};
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import styled from 'styled-components';
3
+ import { Color, FontWeight } from '@pushwoosh/kit-constants';
4
+ import { ChevronIcon } from '@pushwoosh/kit-icons';
5
+ const StyledItemDetailLink = styled.a.withConfig({
6
+ displayName: "StyledItemDetailLink",
7
+ componentId: "sc-v0vtp2-0"
8
+ })(["display:flex;align-items:center;text-decoration:none;font-weight:", ";color:", ";width:100%;min-width:0;&:hover{text-decoration:none;color:", ";}"], FontWeight.MEDIUM, Color.MAIN, Color.PRIMARY_HOVER);
9
+ const Truncate = styled.span.withConfig({
10
+ displayName: "Truncate",
11
+ componentId: "sc-v0vtp2-1"
12
+ })(["overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;"]);
13
+ const Chevron = styled(ChevronIcon).withConfig({
14
+ displayName: "Chevron",
15
+ componentId: "sc-v0vtp2-2"
16
+ })(["flex-shrink:0;"]);
17
+ export function ItemDetailLink({
18
+ withChevron,
19
+ children,
20
+ ...props
21
+ }) {
22
+ if (!withChevron) return _jsx(StyledItemDetailLink, {
23
+ ...props,
24
+ children: children
25
+ });
26
+ return _jsxs(StyledItemDetailLink, {
27
+ ...props,
28
+ children: [_jsx(Truncate, {
29
+ children: children
30
+ }), _jsx(Chevron, {
31
+ size: "small",
32
+ direction: "right"
33
+ })]
34
+ });
35
+ }
@@ -0,0 +1 @@
1
+ export { ItemDetailLink } from './ItemDetailLink';
@@ -0,0 +1 @@
1
+ export { ItemDetailLink } from './ItemDetailLink';
package/Table/index.d.ts CHANGED
@@ -6,5 +6,6 @@ export { DataTableSortableCell } from './components/DataTableSortableCell';
6
6
  export { Loading } from './components/Loading';
7
7
  export { TablePagination } from './components/TablePagination';
8
8
  export { useDataTableContext, useDataTableGetParams } from './hooks';
9
- export { Table, Td, Tr, Th, ElementHover, ItemDetailLink, ItemName, LockedText, Description, } from './styles';
9
+ export { Table, Td, Tr, Th, ElementHover, ItemName, LockedText, Description, } from './styles';
10
+ export { ItemDetailLink } from './components/ItemDetailLink';
10
11
  export type { DataTableParams, DataTableData, DataTableContextType } from './types';
package/Table/index.js CHANGED
@@ -6,4 +6,5 @@ export { DataTableSortableCell } from './components/DataTableSortableCell';
6
6
  export { Loading } from './components/Loading';
7
7
  export { TablePagination } from './components/TablePagination';
8
8
  export { useDataTableContext, useDataTableGetParams } from './hooks';
9
- export { Table, Td, Tr, Th, ElementHover, ItemDetailLink, ItemName, LockedText, Description } from './styles';
9
+ export { Table, Td, Tr, Th, ElementHover, ItemName, LockedText, Description } from './styles';
10
+ export { ItemDetailLink } from './components/ItemDetailLink';
package/Table/styles.d.ts CHANGED
@@ -60,7 +60,6 @@ export declare const Th: import("styled-components").StyledComponent<"div", any,
60
60
  } & {
61
61
  $color?: string;
62
62
  }, "$padding">;
63
- export declare const ItemDetailLink: import("styled-components").StyledComponent<"a", any, {}, never>;
64
63
  export declare const ItemName: import("styled-components").StyledComponent<"div", any, {}, never>;
65
64
  export declare const Description: import("styled-components").StyledComponent<"div", any, {
66
65
  $maxLines?: number;
package/Table/styles.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import styled, { css } from 'styled-components';
2
- import { Color, FontSize, FontWeight, ShapeRadius } from '@pushwoosh/kit-constants';
2
+ import { Color, FontSize, FontWeight, LineHeight, ShapeRadius } from '@pushwoosh/kit-constants';
3
3
  import { GridContainer, Horizontal, Vertical, toCssValue } from '@pushwoosh/kit-helpers';
4
4
  export const Table = styled(Vertical).withConfig({
5
5
  displayName: "Table",
@@ -30,31 +30,27 @@ export const Tr = styled(Horizontal).attrs({
30
30
  }).withConfig({
31
31
  displayName: "Tr",
32
32
  componentId: "sc-1vdjaze-3"
33
- })(["grid-template-columns:var(--table-columns);&:hover{background-color:#89A4BF0D;}&:hover ", "{display:block;}"], ElementHover);
33
+ })(["grid-template-columns:var(--table-columns);&:hover{background-color:", ";}&:hover ", "{display:block;}"], Color.ROW_HOVER, ElementHover);
34
34
  export const Th = styled(Td).withConfig({
35
35
  displayName: "Th",
36
36
  componentId: "sc-1vdjaze-4"
37
- })(["padding:8px 12px;color:#969ca3;font-weight:", ";font-size:", ";line-height:1;text-transform:uppercase;"], FontWeight.MEDIUM, FontSize.SMALL);
38
- export const ItemDetailLink = styled.a.withConfig({
39
- displayName: "ItemDetailLink",
40
- componentId: "sc-1vdjaze-5"
41
- })(["display:flex;align-items:center;text-decoration:none;font-weight:", ";color:", ";width:100%;&:hover{text-decoration:none;color:", ";}"], FontWeight.MEDIUM, Color.MAIN, Color.PRIMARY_HOVER);
37
+ })(["padding:8px 12px;color:", ";font-weight:", ";font-size:", ";line-height:", ";text-transform:uppercase;"], Color.LOCKED, FontWeight.MEDIUM, FontSize.HEADING5, LineHeight.HEADING5);
42
38
  export const ItemName = styled.div.withConfig({
43
39
  displayName: "ItemName",
44
- componentId: "sc-1vdjaze-6"
40
+ componentId: "sc-1vdjaze-5"
45
41
  })(["overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"]);
46
42
  const overflowStyles = css(["overflow:hidden;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:", ";"], ({
47
43
  $maxLines
48
44
  }) => $maxLines);
49
45
  export const Description = styled.div.withConfig({
50
46
  displayName: "Description",
51
- componentId: "sc-1vdjaze-7"
52
- })(["color:", ";font-size:", ";font-style:normal;font-weight:", ";line-height:130%;", ""], Color.LOCKED, FontSize.SMALL, FontWeight.REGULAR, ({
47
+ componentId: "sc-1vdjaze-6"
48
+ })(["color:", ";font-size:", ";font-weight:", ";line-height:", ";", ""], Color.LOCKED, FontSize.SMALL, FontWeight.REGULAR, LineHeight.SMALL, ({
53
49
  $maxLines
54
50
  }) => $maxLines ? overflowStyles : undefined);
55
51
  export const LockedText = styled.div.withConfig({
56
52
  displayName: "LockedText",
57
- componentId: "sc-1vdjaze-8"
53
+ componentId: "sc-1vdjaze-7"
58
54
  })(["color:", ";font-size:", ";font-weight:", ";max-width:", ";"], Color.LOCKED, ({
59
55
  $fontSize
60
56
  }) => $fontSize || FontSize.REGULAR, ({
package/package.json CHANGED
@@ -48,5 +48,5 @@
48
48
  "react": "^16.14.0 || ^18.0.0",
49
49
  "react-dom": "^16.14.0 || ^18.0.0"
50
50
  },
51
- "version": "1.1.7"
51
+ "version": "1.1.9"
52
52
  }