@synerise/ds-filter 0.15.20 → 0.16.0
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.
- package/CHANGELOG.md +19 -0
- package/dist/Filter.js +91 -12
- package/dist/Filter.styles.js +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.16.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-filter@0.15.21...@synerise/ds-filter@0.16.0) (2023-12-14)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **filter:** reorder cruds in filter step conditions ([8d4019b](https://github.com/Synerise/synerise-design/commit/8d4019b49c7579000e093aabbcd31a75626d9c1c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.15.21](https://github.com/Synerise/synerise-design/compare/@synerise/ds-filter@0.15.20...@synerise/ds-filter@0.15.21) (2023-12-13)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @synerise/ds-filter
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [0.15.20](https://github.com/Synerise/synerise-design/compare/@synerise/ds-filter@0.15.19...@synerise/ds-filter@0.15.20) (2023-12-11)
|
|
7
26
|
|
|
8
27
|
|
package/dist/Filter.js
CHANGED
|
@@ -6,7 +6,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6
6
|
|
|
7
7
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
8
|
|
|
9
|
-
import React, { useCallback, useMemo, useEffect, useState } from 'react';
|
|
9
|
+
import React, { useCallback, useMemo, useEffect, useState, useRef } from 'react';
|
|
10
10
|
import { useIntl } from 'react-intl';
|
|
11
11
|
import { ReactSortable } from 'react-sortablejs';
|
|
12
12
|
import Logic from '@synerise/ds-logic';
|
|
@@ -15,18 +15,19 @@ import Placeholder from '@synerise/ds-logic/dist/Placeholder/Placeholder';
|
|
|
15
15
|
import StepCard from '@synerise/ds-step-card';
|
|
16
16
|
import { usePrevious } from '@synerise/ds-utils';
|
|
17
17
|
import * as S from './Filter.styles';
|
|
18
|
-
var SORTABLE_CONFIG = {
|
|
19
|
-
ghostClass: 'ghost-element',
|
|
20
|
-
className: 'sortable-list',
|
|
21
|
-
handle: '.step-card-drag-handler',
|
|
22
|
-
animation: 200,
|
|
23
|
-
forceFallback: true,
|
|
24
|
-
filter: '.ds-matching-toggle, .step-card-right-side'
|
|
25
|
-
};
|
|
26
18
|
var component = {
|
|
27
19
|
LOGIC: Logic,
|
|
28
20
|
STEP: StepCard
|
|
29
21
|
};
|
|
22
|
+
var TRANSITION_DURATION = 0.5;
|
|
23
|
+
var TRANSITION_DURATION_MAX = 1.5;
|
|
24
|
+
var TOP_TRANSITION_ZINDEX = '10003';
|
|
25
|
+
var BOTTOM_TRANSITION_ZINDEX = '10002';
|
|
26
|
+
|
|
27
|
+
var rearrangeItems = function rearrangeItems(sourceArray, oldIndex, newIndex) {
|
|
28
|
+
sourceArray.splice(newIndex, 0, sourceArray.splice(oldIndex, 1)[0]);
|
|
29
|
+
return [].concat(sourceArray);
|
|
30
|
+
};
|
|
30
31
|
|
|
31
32
|
var Filter = function Filter(_ref) {
|
|
32
33
|
var _texts$overwritten;
|
|
@@ -59,6 +60,56 @@ var Filter = function Filter(_ref) {
|
|
|
59
60
|
activeExpressionId = _useState[0],
|
|
60
61
|
setActiveExpressionId = _useState[1];
|
|
61
62
|
|
|
63
|
+
var expressionRefs = useRef({});
|
|
64
|
+
var movedExpressionId = useRef(null);
|
|
65
|
+
var SORTABLE_CONFIG = {
|
|
66
|
+
ghostClass: 'ghost-element',
|
|
67
|
+
className: 'sortable-list',
|
|
68
|
+
handle: '.step-card-drag-handler',
|
|
69
|
+
animation: 200,
|
|
70
|
+
forceFallback: true,
|
|
71
|
+
filter: '.ds-matching-toggle, .step-card-right-side',
|
|
72
|
+
onStart: function onStart() {
|
|
73
|
+
movedExpressionId.current = null;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
useEffect(function () {
|
|
77
|
+
if (movedExpressionId.current && previousExpressions != null && previousExpressions.length) {
|
|
78
|
+
var oldIndex = previousExpressions == null ? void 0 : previousExpressions.findIndex(function (expression) {
|
|
79
|
+
return expression.id === movedExpressionId.current;
|
|
80
|
+
});
|
|
81
|
+
var newIndex = expressions == null ? void 0 : expressions.findIndex(function (expression) {
|
|
82
|
+
return expression.id === movedExpressionId.current;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (oldIndex !== undefined && oldIndex !== newIndex) {
|
|
86
|
+
var sign = oldIndex < newIndex ? 1 : -1;
|
|
87
|
+
var low = Math.min(oldIndex, newIndex);
|
|
88
|
+
var high = Math.max(oldIndex, newIndex);
|
|
89
|
+
var movedExpressionHeight = sign * expressionRefs.current[movedExpressionId.current].getBoundingClientRect().height;
|
|
90
|
+
var expressionOffset = 0;
|
|
91
|
+
var movedCardTransformDuration = Math.min((high - low) * TRANSITION_DURATION, TRANSITION_DURATION_MAX);
|
|
92
|
+
expressions.forEach(function (expression, index) {
|
|
93
|
+
if (expression.id !== movedExpressionId.current && index >= low && index <= high) {
|
|
94
|
+
expressionOffset += expressionRefs.current[expression.id].getBoundingClientRect().height;
|
|
95
|
+
expressionRefs.current[expression.id].style.transition = '';
|
|
96
|
+
expressionRefs.current[expression.id].style.zIndex = BOTTOM_TRANSITION_ZINDEX;
|
|
97
|
+
expressionRefs.current[expression.id].style.transform = "translateY(" + movedExpressionHeight + "px)";
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
expressionRefs.current[movedExpressionId.current].style.transition = '';
|
|
101
|
+
expressionRefs.current[movedExpressionId.current].style.zIndex = TOP_TRANSITION_ZINDEX;
|
|
102
|
+
expressionRefs.current[movedExpressionId.current].style.transform = "translateY(" + -sign * expressionOffset + "px)";
|
|
103
|
+
requestAnimationFrame(function () {
|
|
104
|
+
expressions.forEach(function (expression) {
|
|
105
|
+
expressionRefs.current[expression.id].style.transition = "transform " + (expression.id === movedExpressionId.current ? movedCardTransformDuration : TRANSITION_DURATION) + "s";
|
|
106
|
+
expressionRefs.current[expression.id].style.transform = '';
|
|
107
|
+
});
|
|
108
|
+
movedExpressionId.current = null;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
62
113
|
useEffect(function () {
|
|
63
114
|
if (previousExpressions && expressions.length > previousExpressions.length) {
|
|
64
115
|
setActiveExpressionId(expressions[expressions.length - 1].id);
|
|
@@ -165,8 +216,32 @@ var Filter = function Filter(_ref) {
|
|
|
165
216
|
var isLimitExceeded = useMemo(function () {
|
|
166
217
|
return maxConditionsLimit ? expressions.length >= maxConditionsLimit : false;
|
|
167
218
|
}, [expressions, maxConditionsLimit]);
|
|
219
|
+
var stepExpressionCount = useMemo(function () {
|
|
220
|
+
return expressions.filter(function (expression) {
|
|
221
|
+
return expression.type === 'STEP';
|
|
222
|
+
}).length;
|
|
223
|
+
}, [expressions]);
|
|
224
|
+
|
|
225
|
+
var handleTransitionEnd = function handleTransitionEnd(event) {
|
|
226
|
+
if (event.currentTarget && event.currentTarget instanceof HTMLElement) {
|
|
227
|
+
event.currentTarget.style.removeProperty('z-index');
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
var handleMove = useCallback(function (index, offset) {
|
|
232
|
+
var newIndex = index + offset;
|
|
233
|
+
var newOrder = rearrangeItems([].concat(expressions), index, newIndex);
|
|
234
|
+
movedExpressionId.current = newOrder[newIndex].id;
|
|
235
|
+
onChangeOrder && onChangeOrder(newOrder);
|
|
236
|
+
}, [expressions, onChangeOrder]);
|
|
168
237
|
var componentProps = useCallback(function (expression, index) {
|
|
169
238
|
var contextTypeTexts = getContextTypeTexts(expression);
|
|
239
|
+
var reorderProps = {
|
|
240
|
+
expressionIndex: index,
|
|
241
|
+
expressionMoved: movedExpressionId.current === expression.id,
|
|
242
|
+
expressionCount: stepExpressionCount,
|
|
243
|
+
onMove: handleMove
|
|
244
|
+
};
|
|
170
245
|
var props = {
|
|
171
246
|
LOGIC: {
|
|
172
247
|
onChange: function onChange(value) {
|
|
@@ -174,7 +249,7 @@ var Filter = function Filter(_ref) {
|
|
|
174
249
|
},
|
|
175
250
|
options: logicOptions
|
|
176
251
|
},
|
|
177
|
-
STEP: {
|
|
252
|
+
STEP: _objectSpread({}, reorderProps, {
|
|
178
253
|
onChangeMatching: function onChangeMatching(value) {
|
|
179
254
|
return onChangeStepMatching(expression.id, value);
|
|
180
255
|
},
|
|
@@ -192,14 +267,18 @@ var Filter = function Filter(_ref) {
|
|
|
192
267
|
isHeaderVisible: visibilityConfig.isStepCardHeaderVisible,
|
|
193
268
|
headerRightSide: renderStepHeaderRightSide && renderStepHeaderRightSide(expression, index),
|
|
194
269
|
texts: _objectSpread({}, text.step, {}, contextTypeTexts)
|
|
195
|
-
}
|
|
270
|
+
})
|
|
196
271
|
};
|
|
197
272
|
return props[expression.type];
|
|
198
|
-
}, [activeExpressionId, getContextTypeTexts, isActive, isLimitExceeded, logicOptions, onChangeLogic, onChangeStepMatching, onChangeStepName, onDeleteStep, onDuplicateStep, renderStepContent, renderStepFooter, renderStepHeaderRightSide, text.step, visibilityConfig.isStepCardHeaderVisible]);
|
|
273
|
+
}, [activeExpressionId, getContextTypeTexts, handleMove, isActive, isLimitExceeded, logicOptions, movedExpressionId, onChangeLogic, onChangeStepMatching, onChangeStepName, onDeleteStep, onDuplicateStep, renderStepContent, renderStepFooter, renderStepHeaderRightSide, stepExpressionCount, text.step, visibilityConfig.isStepCardHeaderVisible]);
|
|
199
274
|
var renderExpression = useCallback(function (expression, index) {
|
|
200
275
|
var Component = component[expression.type];
|
|
201
276
|
var LogicComponent = expression.logic && component[expression.logic.type];
|
|
202
277
|
return /*#__PURE__*/React.createElement(S.ExpressionWrapper, {
|
|
278
|
+
onTransitionEnd: handleTransitionEnd,
|
|
279
|
+
ref: function ref(element) {
|
|
280
|
+
return expressionRefs.current[expression.id] = element;
|
|
281
|
+
},
|
|
203
282
|
key: expression.id,
|
|
204
283
|
"data-dropLabel": text.dropMeHere,
|
|
205
284
|
index: index,
|
package/dist/Filter.styles.js
CHANGED
|
@@ -31,7 +31,7 @@ export var LogicWrapper = styled.div.withConfig({
|
|
|
31
31
|
export var ExpressionWrapper = styled.div.withConfig({
|
|
32
32
|
displayName: "Filterstyles__ExpressionWrapper",
|
|
33
33
|
componentId: "w5f27p-7"
|
|
34
|
-
})(["width:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;position:relative;z-index:", ";&.sortable-chosen{cursor:grabbing;width:100%;opacity:1 !important;height:50px;display:flex;align-items:center;justify-content:center;padding:0;box-shadow:0 16px 32px 0 #23293619;", "{visibility:visible;opacity:1;}", "{position:absolute;opacity:0;height:0;}", "
|
|
34
|
+
})(["width:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;position:relative;z-index:", ";&.sortable-chosen{cursor:grabbing;width:100%;opacity:1 !important;height:50px;display:flex;align-items:center;justify-content:center;padding:0;box-shadow:0 16px 32px 0 #23293619;", "{visibility:visible;opacity:1;}", "{position:absolute;opacity:0;height:0;}", ",", "{display:none;}}&.ghost-element{cursor:grabbing;width:100%;background-color:", ";border-left:2px solid ", ";border-radius:3px;display:flex;align-items:center;justify-content:center;padding:0;margin-bottom:24px;height:68px;box-shadow:none;position:relative;&:before{content:attr(data-dropLabel);text-align:center;position:relative;color:", ";}*{position:absolute;opacity:0;height:0;}}"], function (props) {
|
|
35
35
|
return 1000 - props.index;
|
|
36
36
|
}, DragIcon, Body, Footer, LogicWrapper, function (props) {
|
|
37
37
|
return props.theme.palette['blue-050'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-filter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Filter UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
],
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@synerise/ds-button": "^0.18.
|
|
37
|
-
"@synerise/ds-logic": "^0.8.
|
|
38
|
-
"@synerise/ds-step-card": "^0.
|
|
39
|
-
"@synerise/ds-utils": "^0.24.
|
|
36
|
+
"@synerise/ds-button": "^0.18.9",
|
|
37
|
+
"@synerise/ds-logic": "^0.8.18",
|
|
38
|
+
"@synerise/ds-step-card": "^0.10.0",
|
|
39
|
+
"@synerise/ds-utils": "^0.24.23",
|
|
40
40
|
"react-intl": "3.12.0",
|
|
41
41
|
"react-sortablejs": "^6.0.0",
|
|
42
42
|
"sortablejs": "1.15.1"
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"@testing-library/dom": "^7.0.2",
|
|
52
52
|
"@testing-library/jest-dom": "5.1.1"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "0a23e5f431033a6180383d3e0e19e885b5a66778"
|
|
55
55
|
}
|