@pushwoosh/smart-components-kit 1.3.21 → 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,
|
|
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:
|
|
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
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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:
|
|
80
|
+
modifier: modifier ?? ''
|
|
82
81
|
});
|
|
83
82
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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:
|
|
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))];
|
package/package.json
CHANGED