@synerise/ds-filter 0.15.21 → 0.16.1

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 CHANGED
@@ -3,6 +3,28 @@
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.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-filter@0.16.0...@synerise/ds-filter@0.16.1) (2024-01-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **filter:** fixed zindex issues ([71ce5bc](https://github.com/Synerise/synerise-design/commit/71ce5bcf25f2107fd1b43969d2c255e18c112b47))
12
+
13
+
14
+
15
+
16
+
17
+ # [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)
18
+
19
+
20
+ ### Features
21
+
22
+ * **filter:** reorder cruds in filter step conditions ([8d4019b](https://github.com/Synerise/synerise-design/commit/8d4019b49c7579000e093aabbcd31a75626d9c1c))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [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)
7
29
 
8
30
  **Note:** Version bump only for package @synerise/ds-filter
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,20 @@ 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
+ var DRAGGING_TRANSITION_ZINDEX = 10004;
27
+
28
+ var rearrangeItems = function rearrangeItems(sourceArray, oldIndex, newIndex) {
29
+ sourceArray.splice(newIndex, 0, sourceArray.splice(oldIndex, 1)[0]);
30
+ return [].concat(sourceArray);
31
+ };
30
32
 
31
33
  var Filter = function Filter(_ref) {
32
34
  var _texts$overwritten;
@@ -59,6 +61,63 @@ var Filter = function Filter(_ref) {
59
61
  activeExpressionId = _useState[0],
60
62
  setActiveExpressionId = _useState[1];
61
63
 
64
+ var expressionRefs = useRef({});
65
+ var movedExpressionId = useRef(null);
66
+ var SORTABLE_CONFIG = {
67
+ ghostClass: 'ghost-element',
68
+ className: 'sortable-list',
69
+ handle: '.step-card-drag-handler',
70
+ animation: 200,
71
+ forceFallback: true,
72
+ filter: '.ds-matching-toggle, .step-card-right-side',
73
+ onStart: function onStart() {
74
+ movedExpressionId.current = null;
75
+ },
76
+ onChoose: function onChoose(evt) {
77
+ // eslint-disable-next-line no-param-reassign
78
+ evt.item.style.zIndex = DRAGGING_TRANSITION_ZINDEX;
79
+ },
80
+ onUnchoose: function onUnchoose(evt) {
81
+ evt.item.style.removeProperty('z-index');
82
+ }
83
+ };
84
+ useEffect(function () {
85
+ if (movedExpressionId.current && previousExpressions != null && previousExpressions.length) {
86
+ var oldIndex = previousExpressions == null ? void 0 : previousExpressions.findIndex(function (expression) {
87
+ return expression.id === movedExpressionId.current;
88
+ });
89
+ var newIndex = expressions == null ? void 0 : expressions.findIndex(function (expression) {
90
+ return expression.id === movedExpressionId.current;
91
+ });
92
+
93
+ if (oldIndex !== undefined && oldIndex !== newIndex) {
94
+ var sign = oldIndex < newIndex ? 1 : -1;
95
+ var low = Math.min(oldIndex, newIndex);
96
+ var high = Math.max(oldIndex, newIndex);
97
+ var movedExpressionHeight = sign * expressionRefs.current[movedExpressionId.current].getBoundingClientRect().height;
98
+ var expressionOffset = 0;
99
+ var movedCardTransformDuration = Math.min((high - low) * TRANSITION_DURATION, TRANSITION_DURATION_MAX);
100
+ expressions.forEach(function (expression, index) {
101
+ if (expression.id !== movedExpressionId.current && index >= low && index <= high) {
102
+ expressionOffset += expressionRefs.current[expression.id].getBoundingClientRect().height;
103
+ expressionRefs.current[expression.id].style.transition = '';
104
+ expressionRefs.current[expression.id].style.zIndex = BOTTOM_TRANSITION_ZINDEX;
105
+ expressionRefs.current[expression.id].style.transform = "translateY(" + movedExpressionHeight + "px)";
106
+ }
107
+ });
108
+ expressionRefs.current[movedExpressionId.current].style.transition = '';
109
+ expressionRefs.current[movedExpressionId.current].style.zIndex = TOP_TRANSITION_ZINDEX;
110
+ expressionRefs.current[movedExpressionId.current].style.transform = "translateY(" + -sign * expressionOffset + "px)";
111
+ requestAnimationFrame(function () {
112
+ expressions.forEach(function (expression) {
113
+ expressionRefs.current[expression.id].style.transition = "transform " + (expression.id === movedExpressionId.current ? movedCardTransformDuration : TRANSITION_DURATION) + "s";
114
+ expressionRefs.current[expression.id].style.transform = '';
115
+ });
116
+ movedExpressionId.current = null;
117
+ });
118
+ }
119
+ }
120
+ });
62
121
  useEffect(function () {
63
122
  if (previousExpressions && expressions.length > previousExpressions.length) {
64
123
  setActiveExpressionId(expressions[expressions.length - 1].id);
@@ -165,8 +224,32 @@ var Filter = function Filter(_ref) {
165
224
  var isLimitExceeded = useMemo(function () {
166
225
  return maxConditionsLimit ? expressions.length >= maxConditionsLimit : false;
167
226
  }, [expressions, maxConditionsLimit]);
227
+ var stepExpressionCount = useMemo(function () {
228
+ return expressions.filter(function (expression) {
229
+ return expression.type === 'STEP';
230
+ }).length;
231
+ }, [expressions]);
232
+
233
+ var handleTransitionEnd = function handleTransitionEnd(event) {
234
+ if (event.currentTarget && event.currentTarget instanceof HTMLElement) {
235
+ event.currentTarget.style.removeProperty('z-index');
236
+ }
237
+ };
238
+
239
+ var handleMove = useCallback(function (index, offset) {
240
+ var newIndex = index + offset;
241
+ var newOrder = rearrangeItems([].concat(expressions), index, newIndex);
242
+ movedExpressionId.current = newOrder[newIndex].id;
243
+ onChangeOrder && onChangeOrder(newOrder);
244
+ }, [expressions, onChangeOrder]);
168
245
  var componentProps = useCallback(function (expression, index) {
169
246
  var contextTypeTexts = getContextTypeTexts(expression);
247
+ var reorderProps = {
248
+ expressionIndex: index,
249
+ expressionMoved: movedExpressionId.current === expression.id,
250
+ expressionCount: stepExpressionCount,
251
+ onMove: handleMove
252
+ };
170
253
  var props = {
171
254
  LOGIC: {
172
255
  onChange: function onChange(value) {
@@ -174,7 +257,7 @@ var Filter = function Filter(_ref) {
174
257
  },
175
258
  options: logicOptions
176
259
  },
177
- STEP: {
260
+ STEP: _objectSpread({}, reorderProps, {
178
261
  onChangeMatching: function onChangeMatching(value) {
179
262
  return onChangeStepMatching(expression.id, value);
180
263
  },
@@ -192,20 +275,21 @@ var Filter = function Filter(_ref) {
192
275
  isHeaderVisible: visibilityConfig.isStepCardHeaderVisible,
193
276
  headerRightSide: renderStepHeaderRightSide && renderStepHeaderRightSide(expression, index),
194
277
  texts: _objectSpread({}, text.step, {}, contextTypeTexts)
195
- }
278
+ })
196
279
  };
197
280
  return props[expression.type];
198
- }, [activeExpressionId, getContextTypeTexts, isActive, isLimitExceeded, logicOptions, onChangeLogic, onChangeStepMatching, onChangeStepName, onDeleteStep, onDuplicateStep, renderStepContent, renderStepFooter, renderStepHeaderRightSide, text.step, visibilityConfig.isStepCardHeaderVisible]);
281
+ }, [activeExpressionId, getContextTypeTexts, handleMove, isActive, isLimitExceeded, logicOptions, movedExpressionId, onChangeLogic, onChangeStepMatching, onChangeStepName, onDeleteStep, onDuplicateStep, renderStepContent, renderStepFooter, renderStepHeaderRightSide, stepExpressionCount, text.step, visibilityConfig.isStepCardHeaderVisible]);
199
282
  var renderExpression = useCallback(function (expression, index) {
200
283
  var Component = component[expression.type];
201
284
  var LogicComponent = expression.logic && component[expression.logic.type];
202
285
  return /*#__PURE__*/React.createElement(S.ExpressionWrapper, {
286
+ onTransitionEnd: handleTransitionEnd,
287
+ ref: function ref(element) {
288
+ return expressionRefs.current[expression.id] = element;
289
+ },
203
290
  key: expression.id,
204
291
  "data-dropLabel": text.dropMeHere,
205
292
  index: index,
206
- style: !readOnly && isActive(expression) ? {
207
- zIndex: 10001
208
- } : undefined,
209
293
  onMouseDown: function onMouseDown() {
210
294
  return setActiveExpressionId(expression.id);
211
295
  }
@@ -214,7 +298,7 @@ var Filter = function Filter(_ref) {
214
298
  })), expression.logic && index + 1 < expressions.length && /*#__PURE__*/React.createElement(S.LogicWrapper, null, /*#__PURE__*/React.createElement(LogicComponent, _extends({}, expression.logic.data, componentProps(expression.logic, index), {
215
299
  readOnly: readOnly
216
300
  }))));
217
- }, [text.dropMeHere, isActive, componentProps, expressions.length, readOnly]);
301
+ }, [text.dropMeHere, componentProps, expressions.length, readOnly]);
218
302
  return /*#__PURE__*/React.createElement(S.FilterWrapper, null, /*#__PURE__*/React.createElement(S.FilterHeader, null, texts != null && (_texts$overwritten = texts.overwritten) != null && _texts$overwritten.filterTitle ? /*#__PURE__*/React.createElement(S.FilterTitle, null, texts.overwritten.filterTitle) : /*#__PURE__*/React.createElement(S.MatchingWrapper, null, /*#__PURE__*/React.createElement("div", null, matching && /*#__PURE__*/React.createElement(Matching, _extends({}, matching, {
219
303
  texts: text.matching,
220
304
  readOnly: readOnly
@@ -31,9 +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;}", "{display:none;}", "{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
- return 1000 - props.index;
36
- }, DragIcon, Body, Footer, LogicWrapper, function (props) {
34
+ })(["width:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;position:relative;&.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;}}"], DragIcon, Body, Footer, LogicWrapper, function (props) {
37
35
  return props.theme.palette['blue-050'];
38
36
  }, function (props) {
39
37
  return props.theme.palette['blue-600'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-filter",
3
- "version": "0.15.21",
3
+ "version": "0.16.1",
4
4
  "description": "Filter UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -33,9 +33,9 @@
33
33
  ],
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
- "@synerise/ds-button": "^0.18.9",
37
- "@synerise/ds-logic": "^0.8.18",
38
- "@synerise/ds-step-card": "^0.9.20",
36
+ "@synerise/ds-button": "^0.18.10",
37
+ "@synerise/ds-logic": "^0.8.19",
38
+ "@synerise/ds-step-card": "^0.10.1",
39
39
  "@synerise/ds-utils": "^0.24.23",
40
40
  "react-intl": "3.12.0",
41
41
  "react-sortablejs": "^6.0.0",
@@ -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": "76edb4723a30c59f1a54f666f66fcd814de0af70"
54
+ "gitHead": "ba51e38beff83b8adba409f09311131f429ada01"
55
55
  }