etudes 5.2.0 → 5.3.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.
Files changed (164) hide show
  1. package/components/Accordion.js +171 -205
  2. package/components/BurgerButton.js +40 -94
  3. package/components/Carousel.js +87 -123
  4. package/components/Collection.js +84 -120
  5. package/components/Counter.js +32 -63
  6. package/components/CoverImage.js +24 -68
  7. package/components/CoverVideo.js +25 -69
  8. package/components/DebugConsole.js +27 -79
  9. package/components/Dial.js +28 -65
  10. package/components/Dropdown.js +86 -98
  11. package/components/FlatSVG.js +22 -71
  12. package/components/Image.js +21 -50
  13. package/components/MasonryGrid.js +122 -257
  14. package/components/Panorama.js +48 -92
  15. package/components/PanoramaSlider.js +57 -113
  16. package/components/RangeSlider.js +125 -182
  17. package/components/RotatingGallery.js +28 -59
  18. package/components/SelectableButton.js +10 -54
  19. package/components/Slider.js +108 -159
  20. package/components/StepwiseSlider.js +124 -176
  21. package/components/SwipeContainer.js +30 -73
  22. package/components/TextField.js +12 -49
  23. package/components/Video.js +31 -61
  24. package/components/WithTooltip.js +117 -111
  25. package/components/index.js +24 -0
  26. package/hooks/index.js +17 -0
  27. package/hooks/useClickOutsideEffect.js +8 -38
  28. package/hooks/useDragEffect.js +20 -53
  29. package/hooks/useDragValueEffect.js +31 -81
  30. package/hooks/useImageSize.js +16 -38
  31. package/hooks/useInterval.js +9 -41
  32. package/hooks/useLoadImageEffect.js +15 -48
  33. package/hooks/useLoadVideoMetadataEffect.js +15 -48
  34. package/hooks/useMounted.js +5 -25
  35. package/hooks/usePrevious.js +4 -9
  36. package/hooks/useRect.js +9 -29
  37. package/hooks/useResizeEffect.js +10 -44
  38. package/hooks/useScrollPositionEffect.js +19 -50
  39. package/hooks/useSearchParamState.js +12 -34
  40. package/hooks/useSize.js +9 -29
  41. package/hooks/useTimeout.js +8 -38
  42. package/hooks/useVideoSize.js +16 -38
  43. package/hooks/useViewportSize.js +7 -27
  44. package/operators/Conditional.js +6 -11
  45. package/operators/Each.js +6 -14
  46. package/operators/ExtractChild.js +9 -36
  47. package/operators/ExtractChildren.js +7 -34
  48. package/operators/Repeat.js +4 -37
  49. package/operators/index.js +5 -0
  50. package/package.json +29 -42
  51. package/providers/ScrollPositionProvider.js +37 -60
  52. package/providers/index.js +1 -0
  53. package/utils/asClassNameDict.js +1 -5
  54. package/utils/asComponentDict.js +11 -16
  55. package/utils/asStyleDict.js +1 -5
  56. package/utils/cloneStyledElement.js +14 -61
  57. package/utils/index.js +5 -22
  58. package/utils/styles.js +5 -21
  59. package/components/Accordion.d.ts +0 -219
  60. package/components/Accordion.js.map +0 -1
  61. package/components/BurgerButton.d.ts +0 -34
  62. package/components/BurgerButton.js.map +0 -1
  63. package/components/Carousel.d.ts +0 -53
  64. package/components/Carousel.js.map +0 -1
  65. package/components/Collection.d.ts +0 -171
  66. package/components/Collection.js.map +0 -1
  67. package/components/Counter.d.ts +0 -11
  68. package/components/Counter.js.map +0 -1
  69. package/components/CoverImage.d.ts +0 -28
  70. package/components/CoverImage.js.map +0 -1
  71. package/components/CoverVideo.d.ts +0 -28
  72. package/components/CoverVideo.js.map +0 -1
  73. package/components/DebugConsole.d.ts +0 -15
  74. package/components/DebugConsole.js.map +0 -1
  75. package/components/Dial.d.ts +0 -79
  76. package/components/Dial.js.map +0 -1
  77. package/components/Dropdown.d.ts +0 -109
  78. package/components/Dropdown.js.map +0 -1
  79. package/components/FlatSVG.d.ts +0 -72
  80. package/components/FlatSVG.js.map +0 -1
  81. package/components/Image.d.ts +0 -144
  82. package/components/Image.js.map +0 -1
  83. package/components/MasonryGrid.d.ts +0 -29
  84. package/components/MasonryGrid.js.map +0 -1
  85. package/components/Panorama.d.ts +0 -77
  86. package/components/Panorama.js.map +0 -1
  87. package/components/PanoramaSlider.d.ts +0 -71
  88. package/components/PanoramaSlider.js.map +0 -1
  89. package/components/RangeSlider.d.ts +0 -34
  90. package/components/RangeSlider.js.map +0 -1
  91. package/components/RotatingGallery.d.ts +0 -91
  92. package/components/RotatingGallery.js.map +0 -1
  93. package/components/SelectableButton.d.ts +0 -19
  94. package/components/SelectableButton.js.map +0 -1
  95. package/components/Slider.d.ts +0 -160
  96. package/components/Slider.js.map +0 -1
  97. package/components/StepwiseSlider.d.ts +0 -215
  98. package/components/StepwiseSlider.js.map +0 -1
  99. package/components/SwipeContainer.d.ts +0 -21
  100. package/components/SwipeContainer.js.map +0 -1
  101. package/components/TextField.d.ts +0 -21
  102. package/components/TextField.js.map +0 -1
  103. package/components/Video.d.ts +0 -38
  104. package/components/Video.js.map +0 -1
  105. package/components/WithTooltip.d.ts +0 -32
  106. package/components/WithTooltip.js.map +0 -1
  107. package/hooks/useClickOutsideEffect.d.ts +0 -2
  108. package/hooks/useClickOutsideEffect.js.map +0 -1
  109. package/hooks/useDragEffect.d.ts +0 -48
  110. package/hooks/useDragEffect.js.map +0 -1
  111. package/hooks/useDragValueEffect.d.ts +0 -56
  112. package/hooks/useDragValueEffect.js.map +0 -1
  113. package/hooks/useImageSize.d.ts +0 -21
  114. package/hooks/useImageSize.js.map +0 -1
  115. package/hooks/useInterval.d.ts +0 -18
  116. package/hooks/useInterval.js.map +0 -1
  117. package/hooks/useLoadImageEffect.d.ts +0 -43
  118. package/hooks/useLoadImageEffect.js.map +0 -1
  119. package/hooks/useLoadVideoMetadataEffect.d.ts +0 -35
  120. package/hooks/useLoadVideoMetadataEffect.js.map +0 -1
  121. package/hooks/useMounted.d.ts +0 -1
  122. package/hooks/useMounted.js.map +0 -1
  123. package/hooks/usePrevious.d.ts +0 -19
  124. package/hooks/usePrevious.js.map +0 -1
  125. package/hooks/useRect.d.ts +0 -11
  126. package/hooks/useRect.js.map +0 -1
  127. package/hooks/useResizeEffect.d.ts +0 -17
  128. package/hooks/useResizeEffect.js.map +0 -1
  129. package/hooks/useScrollPositionEffect.d.ts +0 -13
  130. package/hooks/useScrollPositionEffect.js.map +0 -1
  131. package/hooks/useSearchParamState.d.ts +0 -34
  132. package/hooks/useSearchParamState.js.map +0 -1
  133. package/hooks/useSize.d.ts +0 -10
  134. package/hooks/useSize.js.map +0 -1
  135. package/hooks/useTimeout.d.ts +0 -10
  136. package/hooks/useTimeout.js.map +0 -1
  137. package/hooks/useVideoSize.d.ts +0 -21
  138. package/hooks/useVideoSize.js.map +0 -1
  139. package/hooks/useViewportSize.d.ts +0 -7
  140. package/hooks/useViewportSize.js.map +0 -1
  141. package/operators/Conditional.d.ts +0 -5
  142. package/operators/Conditional.js.map +0 -1
  143. package/operators/Each.d.ts +0 -7
  144. package/operators/Each.js.map +0 -1
  145. package/operators/ExtractChild.d.ts +0 -8
  146. package/operators/ExtractChild.js.map +0 -1
  147. package/operators/ExtractChildren.d.ts +0 -6
  148. package/operators/ExtractChildren.js.map +0 -1
  149. package/operators/Repeat.d.ts +0 -11
  150. package/operators/Repeat.js.map +0 -1
  151. package/providers/ScrollPositionProvider.d.ts +0 -15
  152. package/providers/ScrollPositionProvider.js.map +0 -1
  153. package/utils/asClassNameDict.d.ts +0 -3
  154. package/utils/asClassNameDict.js.map +0 -1
  155. package/utils/asComponentDict.d.ts +0 -5
  156. package/utils/asComponentDict.js.map +0 -1
  157. package/utils/asStyleDict.d.ts +0 -4
  158. package/utils/asStyleDict.js.map +0 -1
  159. package/utils/cloneStyledElement.d.ts +0 -18
  160. package/utils/cloneStyledElement.js.map +0 -1
  161. package/utils/index.d.ts +0 -5
  162. package/utils/index.js.map +0 -1
  163. package/utils/styles.d.ts +0 -2
  164. package/utils/styles.js.map +0 -1
@@ -1,264 +1,214 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
- var __read = (this && this.__read) || function (o, n) {
25
- var m = typeof Symbol === "function" && o[Symbol.iterator];
26
- if (!m) return o;
27
- var i = m.call(o), r, ar = [], e;
28
- try {
29
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
- }
31
- catch (error) { e = { error: error }; }
32
- finally {
33
- try {
34
- if (r && !r.done && (m = i["return"])) m.call(i);
35
- }
36
- finally { if (e) throw e.error; }
37
- }
38
- return ar;
39
- };
40
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
- if (ar || !(i in from)) {
43
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
- ar[i] = from[i];
45
- }
46
- }
47
- return to.concat(ar || Array.prototype.slice.call(from));
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.Accordion = void 0;
54
- var jsx_runtime_1 = require("react/jsx-runtime");
55
- var clsx_1 = __importDefault(require("clsx"));
56
- var react_1 = __importDefault(require("fast-deep-equal/react"));
57
- var react_2 = require("react");
58
- var Each_1 = require("../operators/Each");
59
- var utils_1 = require("../utils");
60
- var Collection_1 = require("./Collection");
61
- var FlatSVG_1 = require("./FlatSVG");
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import clsx from 'clsx';
3
+ import isDeepEqual from 'fast-deep-equal/react';
4
+ import { forwardRef, useEffect, useRef } from 'react';
5
+ import { Each } from '../operators/Each.js';
6
+ import { asStyleDict, cloneStyledElement, styles } from '../utils/index.js';
7
+ import { Collection } from './Collection.js';
8
+ import { FlatSVG } from './FlatSVG.js';
62
9
  /**
63
10
  * A collection of selectable items laid out in sections in an accordion. Items
64
11
  * are generated based on the provided `ItemComponent` while each section header
65
12
  * is optionally provided by `HeaderComponent` or generated automatically.
66
13
  */
67
- exports.Accordion = (0, react_2.forwardRef)(function (_a, ref) {
68
- var children = _a.children, style = _a.style, _b = _a.autoCollapseSections, autoCollapseSections = _b === void 0 ? false : _b, collapseIconSvg = _a.collapseIconSvg, externalExpandedSectionIndices = _a.expandedSectionIndices, expandIconSvg = _a.expandIconSvg, _c = _a.orientation, orientation = _c === void 0 ? 'vertical' : _c, _d = _a.sectionPadding, sectionPadding = _d === void 0 ? 0 : _d, sections = _a.sections, externalSelection = _a.selection, _e = _a.selectionMode, selectionMode = _e === void 0 ? 'single' : _e, _f = _a.usesDefaultStyles, usesDefaultStyles = _f === void 0 ? false : _f, onActivateAt = _a.onActivateAt, onCollapseSectionAt = _a.onCollapseSectionAt, onDeselectAt = _a.onDeselectAt, onExpandedSectionsChange = _a.onExpandedSectionsChange, onExpandSectionAt = _a.onExpandSectionAt, onHeaderCustomEvent = _a.onHeaderCustomEvent, onItemCustomEvent = _a.onItemCustomEvent, onSelectAt = _a.onSelectAt, onSelectionChange = _a.onSelectionChange, HeaderComponent = _a.HeaderComponent, ItemComponent = _a.ItemComponent, props = __rest(_a, ["children", "style", "autoCollapseSections", "collapseIconSvg", "expandedSectionIndices", "expandIconSvg", "orientation", "sectionPadding", "sections", "selection", "selectionMode", "usesDefaultStyles", "onActivateAt", "onCollapseSectionAt", "onDeselectAt", "onExpandedSectionsChange", "onExpandSectionAt", "onHeaderCustomEvent", "onItemCustomEvent", "onSelectAt", "onSelectionChange", "HeaderComponent", "ItemComponent"]);
69
- var isSectionIndexOutOfRange = function (sectionIndex) {
14
+ export const Accordion = forwardRef(({ children, style, autoCollapseSections = false, collapseIconSvg, expandedSectionIndices: externalExpandedSectionIndices, expandIconSvg, orientation = 'vertical', sectionPadding = 0, sections, selection: externalSelection, selectionMode = 'single', usesDefaultStyles = false, onActivateAt, onCollapseSectionAt, onDeselectAt, onExpandedSectionsChange, onExpandSectionAt, onHeaderCustomEvent, onItemCustomEvent, onSelectAt, onSelectionChange, HeaderComponent, ItemComponent, ...props }, ref) => {
15
+ const isSectionIndexOutOfRange = (sectionIndex) => {
70
16
  if (sectionIndex >= sections.length)
71
17
  return true;
72
18
  if (sectionIndex < 0)
73
19
  return true;
74
20
  return false;
75
21
  };
76
- var isItemIndexOutOfRange = function (itemIndex, sectionIndex) {
22
+ const isItemIndexOutOfRange = (itemIndex, sectionIndex) => {
77
23
  if (isSectionIndexOutOfRange(sectionIndex))
78
24
  return true;
79
- var items = sections[sectionIndex].items;
25
+ const items = sections[sectionIndex].items;
80
26
  if (itemIndex >= items.length)
81
27
  return true;
82
28
  if (itemIndex < 0)
83
29
  return true;
84
30
  return false;
85
31
  };
86
- var isSelectedAt = function (itemIndex, sectionIndex) { var _a, _b; return ((_b = (_a = selection[sectionIndex]) === null || _a === void 0 ? void 0 : _a.indexOf(itemIndex)) !== null && _b !== void 0 ? _b : -1) >= 0; };
87
- var sanitizeExpandedSectionIndices = function (sectionIndices) { return sortIndices(sectionIndices).filter(function (t) { return !isSectionIndexOutOfRange(t); }); };
88
- var sanitizeSelection = function (selection) {
89
- var _a;
90
- var newValue = {};
91
- var _loop_1 = function (sectionIndex) {
32
+ const isSelectedAt = (itemIndex, sectionIndex) => (selection[sectionIndex]?.indexOf(itemIndex) ?? -1) >= 0;
33
+ const sanitizeExpandedSectionIndices = (sectionIndices) => sortIndices(sectionIndices).filter(t => !isSectionIndexOutOfRange(t));
34
+ const sanitizeSelection = (selection) => {
35
+ const newValue = {};
36
+ for (const sectionIndex in sections) {
92
37
  if (!Object.hasOwn(sections, sectionIndex))
93
- return "continue";
94
- var indices = sortIndices(__spreadArray([], __read((_a = selection[sectionIndex]) !== null && _a !== void 0 ? _a : []), false));
95
- newValue[Number(sectionIndex)] = sortIndices(indices).filter(function (t) { return !isItemIndexOutOfRange(t, Number(sectionIndex)); });
96
- };
97
- for (var sectionIndex in sections) {
98
- _loop_1(sectionIndex);
38
+ continue;
39
+ const indices = sortIndices([...selection[sectionIndex] ?? []]);
40
+ newValue[Number(sectionIndex)] = sortIndices(indices).filter(t => !isItemIndexOutOfRange(t, Number(sectionIndex)));
99
41
  }
100
42
  return newValue;
101
43
  };
102
- var isSectionExpandedAt = function (sectionIndex) { return expandedSectionIndices.indexOf(sectionIndex) >= 0; };
103
- var toggleSectionAt = function (sectionIndex) {
104
- var transform;
44
+ const isSectionExpandedAt = (sectionIndex) => expandedSectionIndices.indexOf(sectionIndex) >= 0;
45
+ const toggleSectionAt = (sectionIndex) => {
46
+ let transform;
105
47
  if (isSectionExpandedAt(sectionIndex)) {
106
- transform = function (val) { return val.filter(function (t) { return t !== sectionIndex; }); };
48
+ transform = val => val.filter(t => t !== sectionIndex);
107
49
  }
108
50
  else if (autoCollapseSections) {
109
- transform = function (val) { return [sectionIndex]; };
51
+ transform = val => [sectionIndex];
110
52
  }
111
53
  else {
112
- transform = function (val) { return __spreadArray(__spreadArray([], __read(val.filter(function (t) { return t !== sectionIndex; })), false), [sectionIndex], false); };
54
+ transform = val => [...val.filter(t => t !== sectionIndex), sectionIndex];
113
55
  }
114
56
  handleExpandedSectionsChange(expandedSectionIndices, transform(expandedSectionIndices));
115
57
  };
116
- var handleSelectAt = function (itemIndex, sectionIndex) {
58
+ const handleSelectAt = (itemIndex, sectionIndex) => {
117
59
  if (isSelectedAt(itemIndex, sectionIndex))
118
60
  return;
119
- var transform;
61
+ let transform;
120
62
  switch (selectionMode) {
121
63
  case 'multiple':
122
- transform = function (val) {
123
- var _a;
124
- var _b;
125
- return (__assign(__assign({}, val), (_a = {}, _a[sectionIndex] = sortIndices(__spreadArray(__spreadArray([], __read(((_b = val[sectionIndex]) !== null && _b !== void 0 ? _b : []).filter(function (t) { return t !== itemIndex; })), false), [itemIndex], false)), _a)));
126
- };
64
+ transform = val => ({
65
+ ...val,
66
+ [sectionIndex]: sortIndices([...(val[sectionIndex] ?? []).filter(t => t !== itemIndex), itemIndex]),
67
+ });
127
68
  break;
128
69
  case 'single':
129
- transform = function (val) {
130
- var _a;
131
- return (_a = {},
132
- _a[sectionIndex] = [itemIndex],
133
- _a);
134
- };
70
+ transform = val => ({
71
+ [sectionIndex]: [itemIndex],
72
+ });
135
73
  break;
136
74
  default:
137
75
  return;
138
76
  }
139
- var newValue = transform(selection);
77
+ const newValue = transform(selection);
140
78
  prevSelectionRef.current = newValue;
141
79
  handleSelectionChange(selection, newValue);
142
80
  };
143
- var handleDeselectAt = function (itemIndex, sectionIndex) {
81
+ const handleDeselectAt = (itemIndex, sectionIndex) => {
144
82
  if (!isSelectedAt(itemIndex, sectionIndex))
145
83
  return;
146
- var transform = function (val) {
147
- var _a;
148
- var _b;
149
- return (__assign(__assign({}, val), (_a = {}, _a[sectionIndex] = ((_b = val[sectionIndex]) !== null && _b !== void 0 ? _b : []).filter(function (t) { return t !== itemIndex; }), _a)));
150
- };
151
- var newValue = transform(selection);
84
+ const transform = (val) => ({
85
+ ...val,
86
+ [sectionIndex]: (val[sectionIndex] ?? []).filter(t => t !== itemIndex),
87
+ });
88
+ const newValue = transform(selection);
152
89
  prevSelectionRef.current = newValue;
153
90
  handleSelectionChange(selection, newValue);
154
91
  };
155
- var handleExpandedSectionsChange = function (oldValue, newValue) {
156
- var _a;
157
- if ((0, react_1.default)(oldValue, newValue))
92
+ const handleExpandedSectionsChange = (oldValue, newValue) => {
93
+ if (isDeepEqual(oldValue, newValue))
158
94
  return;
159
- var collapsed = (_a = oldValue === null || oldValue === void 0 ? void 0 : oldValue.filter(function (t) { return newValue.indexOf(t) === -1; })) !== null && _a !== void 0 ? _a : [];
160
- var expanded = newValue.filter(function (t) { return (oldValue === null || oldValue === void 0 ? void 0 : oldValue.indexOf(t)) === -1; });
161
- collapsed.forEach(function (t) { return onCollapseSectionAt === null || onCollapseSectionAt === void 0 ? void 0 : onCollapseSectionAt(t); });
162
- expanded.forEach(function (t) { return onExpandSectionAt === null || onExpandSectionAt === void 0 ? void 0 : onExpandSectionAt(t); });
163
- onExpandedSectionsChange === null || onExpandedSectionsChange === void 0 ? void 0 : onExpandedSectionsChange(newValue);
95
+ const collapsed = oldValue?.filter(t => newValue.indexOf(t) === -1) ?? [];
96
+ const expanded = newValue.filter(t => oldValue?.indexOf(t) === -1);
97
+ collapsed.forEach(t => onCollapseSectionAt?.(t));
98
+ expanded.forEach(t => onExpandSectionAt?.(t));
99
+ onExpandedSectionsChange?.(newValue);
164
100
  };
165
- var handleSelectionChange = function (oldValue, newValue) {
166
- var _a, _b;
167
- if ((0, react_1.default)(oldValue, newValue))
101
+ const handleSelectionChange = (oldValue, newValue) => {
102
+ if (isDeepEqual(oldValue, newValue))
168
103
  return;
169
- var numSections = sections.length;
170
- var allDeselected = [];
171
- var allSelected = [];
172
- var _loop_2 = function (i) {
173
- var oldSection = (_a = oldValue === null || oldValue === void 0 ? void 0 : oldValue[i]) !== null && _a !== void 0 ? _a : [];
174
- var newSection = (_b = newValue[i]) !== null && _b !== void 0 ? _b : [];
175
- var deselected = oldSection.filter(function (t) { return newSection.indexOf(t) === -1; });
176
- var selected = newSection.filter(function (t) { return (oldSection === null || oldSection === void 0 ? void 0 : oldSection.indexOf(t)) === -1; });
177
- allDeselected = __spreadArray(__spreadArray([], __read(allDeselected), false), __read(deselected.map(function (t) { return [t, i]; })), false);
178
- allSelected = __spreadArray(__spreadArray([], __read(allSelected), false), __read(selected.map(function (t) { return [t, i]; })), false);
179
- };
180
- for (var i = 0; i < numSections; i++) {
181
- _loop_2(i);
104
+ const numSections = sections.length;
105
+ let allDeselected = [];
106
+ let allSelected = [];
107
+ for (let i = 0; i < numSections; i++) {
108
+ const oldSection = oldValue?.[i] ?? [];
109
+ const newSection = newValue[i] ?? [];
110
+ const deselected = oldSection.filter(t => newSection.indexOf(t) === -1);
111
+ const selected = newSection.filter(t => oldSection?.indexOf(t) === -1);
112
+ allDeselected = [...allDeselected, ...deselected.map(t => [t, i])];
113
+ allSelected = [...allSelected, ...selected.map(t => [t, i])];
182
114
  }
183
- allDeselected.forEach(function (t) { return onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(t[0], t[1]); });
184
- allSelected.forEach(function (t) { return onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(t[0], t[1]); });
185
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(newValue);
115
+ allDeselected.forEach(t => onDeselectAt?.(t[0], t[1]));
116
+ allSelected.forEach(t => onSelectAt?.(t[0], t[1]));
117
+ onSelectionChange?.(newValue);
186
118
  };
187
- var selection = sanitizeSelection(externalSelection !== null && externalSelection !== void 0 ? externalSelection : {});
188
- var expandedSectionIndices = sanitizeExpandedSectionIndices(externalExpandedSectionIndices !== null && externalExpandedSectionIndices !== void 0 ? externalExpandedSectionIndices : []);
189
- var fixedStyles = getFixedStyles({ orientation: orientation });
190
- var defaultStyles = usesDefaultStyles ? getDefaultStyles({ orientation: orientation }) : undefined;
191
- var prevSelectionRef = (0, react_2.useRef)();
192
- var prevSelection = prevSelectionRef.current;
193
- (0, react_2.useEffect)(function () {
119
+ const selection = sanitizeSelection(externalSelection ?? {});
120
+ const expandedSectionIndices = sanitizeExpandedSectionIndices(externalExpandedSectionIndices ?? []);
121
+ const fixedStyles = getFixedStyles({ orientation });
122
+ const defaultStyles = usesDefaultStyles ? getDefaultStyles({ orientation }) : undefined;
123
+ const prevSelectionRef = useRef();
124
+ const prevSelection = prevSelectionRef.current;
125
+ useEffect(() => {
194
126
  prevSelectionRef.current = selection;
195
127
  if (prevSelection === undefined)
196
128
  return;
197
129
  handleSelectionChange(prevSelection, selection);
198
130
  }, [JSON.stringify(selection)]);
199
- return ((0, jsx_runtime_1.jsx)("div", __assign({}, props, { ref: ref, "data-component": 'accordion', style: (0, utils_1.styles)(style, fixedStyles.root), children: (0, jsx_runtime_1.jsx)(Each_1.Each, { in: sections, children: function (section, sectionIndex) {
200
- var _a;
201
- var _b = section.collectionPadding, collectionPadding = _b === void 0 ? 0 : _b, items = section.items, _c = section.itemLength, itemLength = _c === void 0 ? 50 : _c, _d = section.itemPadding, itemPadding = _d === void 0 ? 0 : _d, isSelectionTogglable = section.isSelectionTogglable, _e = section.layout, layout = _e === void 0 ? 'list' : _e, _f = section.maxVisible, maxVisible = _f === void 0 ? -1 : _f, _g = section.numSegments, numSegments = _g === void 0 ? 1 : _g;
202
- var allVisible = layout === 'list' ? items.length : Math.ceil(items.length / numSegments);
203
- var numVisible = maxVisible < 0 ? allVisible : Math.min(allVisible, maxVisible);
204
- var maxLength = itemLength * numVisible + itemPadding * (numVisible - 1);
205
- var isCollapsed = !isSectionExpandedAt(sectionIndex);
206
- var expandIconComponent = expandIconSvg ? (0, jsx_runtime_1.jsx)(FlatSVG_1.FlatSVG, { style: defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.expandIcon, svg: expandIconSvg }) : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
207
- var collapseIconComponent = collapseIconSvg ? (0, jsx_runtime_1.jsx)(FlatSVG_1.FlatSVG, { style: defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.collapseIcon, svg: collapseIconSvg }) : expandIconComponent;
208
- return ((0, jsx_runtime_1.jsxs)("div", { style: (0, utils_1.styles)(fixedStyles.section, orientation === 'vertical' ? {
209
- marginTop: sectionIndex === 0 ? '0px' : "".concat(sectionPadding, "px"),
131
+ return (_jsx("div", { ...props, ref: ref, "data-component": 'accordion', style: styles(style, fixedStyles.root), children: _jsx(Each, { in: sections, children: (section, sectionIndex) => {
132
+ const { collectionPadding = 0, items, itemLength = 50, itemPadding = 0, isSelectionTogglable, layout = 'list', maxVisible = -1, numSegments = 1 } = section;
133
+ const allVisible = layout === 'list' ? items.length : Math.ceil(items.length / numSegments);
134
+ const numVisible = maxVisible < 0 ? allVisible : Math.min(allVisible, maxVisible);
135
+ const maxLength = itemLength * numVisible + itemPadding * (numVisible - 1);
136
+ const isCollapsed = !isSectionExpandedAt(sectionIndex);
137
+ const expandIconComponent = expandIconSvg ? _jsx(FlatSVG, { style: defaultStyles?.expandIcon, svg: expandIconSvg }) : _jsx(_Fragment, {});
138
+ const collapseIconComponent = collapseIconSvg ? _jsx(FlatSVG, { style: defaultStyles?.collapseIcon, svg: collapseIconSvg }) : expandIconComponent;
139
+ return (_jsxs("div", { style: styles(fixedStyles.section, orientation === 'vertical' ? {
140
+ marginTop: sectionIndex === 0 ? '0px' : `${sectionPadding}px`,
210
141
  } : {
211
- marginLeft: sectionIndex === 0 ? '0px' : "".concat(sectionPadding, "px"),
212
- }), children: [HeaderComponent ? ((0, jsx_runtime_1.jsx)(HeaderComponent, { className: (0, clsx_1.default)({ collapsed: isCollapsed, expanded: !isCollapsed }), "data-child": 'header', index: sectionIndex, isCollapsed: isCollapsed, section: section, style: (0, utils_1.styles)(fixedStyles.header), onClick: function () { return toggleSectionAt(sectionIndex); }, onCustomEvent: function (name, info) { return onHeaderCustomEvent === null || onHeaderCustomEvent === void 0 ? void 0 : onHeaderCustomEvent(sectionIndex, name, info); } })) : ((0, jsx_runtime_1.jsxs)("button", { className: (0, clsx_1.default)({ collapsed: isCollapsed, expanded: !isCollapsed }), "data-child": 'header', style: (0, utils_1.styles)(fixedStyles.header, defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.header), onClick: function () { return toggleSectionAt(sectionIndex); }, children: [(0, jsx_runtime_1.jsx)("span", { dangerouslySetInnerHTML: { __html: section.label }, style: (0, utils_1.styles)(defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.headerLabel) }), (0, utils_1.cloneStyledElement)(isCollapsed ? expandIconComponent : collapseIconComponent, {
213
- style: (0, utils_1.styles)(isCollapsed ? fixedStyles.expandIcon : fixedStyles.collapseIcon),
214
- })] })), (0, jsx_runtime_1.jsx)(Collection_1.Collection, { className: (0, clsx_1.default)({ collapsed: isCollapsed, expanded: !isCollapsed }), "data-child": 'collection', isSelectionTogglable: isSelectionTogglable, ItemComponent: ItemComponent, itemLength: itemLength, itemPadding: itemPadding, items: items, layout: layout, numSegments: numSegments, orientation: orientation, selection: (_a = selection[sectionIndex]) !== null && _a !== void 0 ? _a : [], selectionMode: selectionMode, style: (0, utils_1.styles)(fixedStyles.list, defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.collection, orientation === 'vertical' ? {
142
+ marginLeft: sectionIndex === 0 ? '0px' : `${sectionPadding}px`,
143
+ }), children: [HeaderComponent ? (_jsx(HeaderComponent, { className: clsx({ collapsed: isCollapsed, expanded: !isCollapsed }), "data-child": 'header', index: sectionIndex, isCollapsed: isCollapsed, section: section, style: styles(fixedStyles.header), onClick: () => toggleSectionAt(sectionIndex), onCustomEvent: (name, info) => onHeaderCustomEvent?.(sectionIndex, name, info) })) : (_jsxs("button", { className: clsx({ collapsed: isCollapsed, expanded: !isCollapsed }), "data-child": 'header', style: styles(fixedStyles.header, defaultStyles?.header), onClick: () => toggleSectionAt(sectionIndex), children: [_jsx("span", { dangerouslySetInnerHTML: { __html: section.label }, style: styles(defaultStyles?.headerLabel) }), cloneStyledElement(isCollapsed ? expandIconComponent : collapseIconComponent, {
144
+ style: styles(isCollapsed ? fixedStyles.expandIcon : fixedStyles.collapseIcon),
145
+ })] })), _jsx(Collection, { className: clsx({ collapsed: isCollapsed, expanded: !isCollapsed }), "data-child": 'collection', isSelectionTogglable: isSelectionTogglable, ItemComponent: ItemComponent, itemLength: itemLength, itemPadding: itemPadding, items: items, layout: layout, numSegments: numSegments, orientation: orientation, selection: selection[sectionIndex] ?? [], selectionMode: selectionMode, style: styles(fixedStyles.list, defaultStyles?.collection, orientation === 'vertical' ? {
215
146
  width: '100%',
216
- height: isCollapsed ? '0px' : "".concat(maxLength, "px"),
217
- marginTop: isCollapsed ? '0px' : "".concat(collectionPadding, "px"),
147
+ height: isCollapsed ? '0px' : `${maxLength}px`,
148
+ marginTop: isCollapsed ? '0px' : `${collectionPadding}px`,
218
149
  overflowY: maxVisible < 0 || maxVisible >= allVisible ? 'hidden' : 'scroll',
219
150
  } : {
220
- marginLeft: isCollapsed ? '0px' : "".concat(collectionPadding, "px"),
151
+ marginLeft: isCollapsed ? '0px' : `${collectionPadding}px`,
221
152
  overflowX: maxVisible < 0 || maxVisible >= allVisible ? 'hidden' : 'scroll',
222
- width: isCollapsed ? '0px' : "".concat(maxLength, "px"),
153
+ width: isCollapsed ? '0px' : `${maxLength}px`,
223
154
  height: '100%',
224
- }), onActivateAt: function (itemIndex) {
225
- onActivateAt === null || onActivateAt === void 0 ? void 0 : onActivateAt(itemIndex, sectionIndex);
226
- }, onDeselectAt: function (itemIndex) {
227
- handleDeselectAt === null || handleDeselectAt === void 0 ? void 0 : handleDeselectAt(itemIndex, sectionIndex);
228
- }, onItemCustomEvent: function (itemIndex, name, info) {
229
- onItemCustomEvent === null || onItemCustomEvent === void 0 ? void 0 : onItemCustomEvent(itemIndex, sectionIndex, name, info);
230
- }, onSelectAt: function (itemIndex) {
231
- handleSelectAt === null || handleSelectAt === void 0 ? void 0 : handleSelectAt(itemIndex, sectionIndex);
155
+ }), onActivateAt: itemIndex => {
156
+ onActivateAt?.(itemIndex, sectionIndex);
157
+ }, onDeselectAt: itemIndex => {
158
+ handleDeselectAt?.(itemIndex, sectionIndex);
159
+ }, onItemCustomEvent: (itemIndex, name, info) => {
160
+ onItemCustomEvent?.(itemIndex, sectionIndex, name, info);
161
+ }, onSelectAt: itemIndex => {
162
+ handleSelectAt?.(itemIndex, sectionIndex);
232
163
  } })] }));
233
- } }) })));
164
+ } }) }));
234
165
  });
235
- Object.defineProperty(exports.Accordion, 'displayName', { value: 'Accordion', writable: false });
166
+ Object.defineProperty(Accordion, 'displayName', { value: 'Accordion', writable: false });
236
167
  function sortIndices(indices) {
237
- return indices.sort(function (a, b) { return a - b; });
168
+ return indices.sort((a, b) => a - b);
238
169
  }
239
- function getFixedStyles(_a) {
240
- var _b = _a.orientation, orientation = _b === void 0 ? 'vertical' : _b;
241
- return (0, utils_1.asStyleDict)({
242
- root: __assign({ alignItems: 'center', boxSizing: 'border-box', display: 'flex', flex: '0 0 auto', justifyContent: 'flex-start', padding: '0' }, orientation === 'vertical' ? {
243
- flexDirection: 'column',
244
- height: 'auto',
245
- } : {
246
- flexDirection: 'row',
247
- width: 'auto',
248
- }),
249
- section: __assign({ alignItems: 'flex-start', display: 'flex', flex: '0 0 auto', justifyContent: 'flex-start', margin: '0', padding: '0' }, orientation === 'vertical' ? {
250
- flexDirection: 'column',
251
- width: '100%',
252
- } : {
253
- flexDirection: 'row',
254
- height: '100%',
255
- }),
170
+ function getFixedStyles({ orientation = 'vertical' }) {
171
+ return asStyleDict({
172
+ root: {
173
+ alignItems: 'center',
174
+ boxSizing: 'border-box',
175
+ display: 'flex',
176
+ flex: '0 0 auto',
177
+ justifyContent: 'flex-start',
178
+ padding: '0',
179
+ ...orientation === 'vertical' ? {
180
+ flexDirection: 'column',
181
+ height: 'auto',
182
+ } : {
183
+ flexDirection: 'row',
184
+ width: 'auto',
185
+ },
186
+ },
187
+ section: {
188
+ alignItems: 'flex-start',
189
+ display: 'flex',
190
+ flex: '0 0 auto',
191
+ justifyContent: 'flex-start',
192
+ margin: '0',
193
+ padding: '0',
194
+ ...orientation === 'vertical' ? {
195
+ flexDirection: 'column',
196
+ width: '100%',
197
+ } : {
198
+ flexDirection: 'row',
199
+ height: '100%',
200
+ },
201
+ },
256
202
  list: {},
257
- header: __assign({ cursor: 'pointer', margin: '0' }, orientation === 'vertical' ? {
258
- width: '100%',
259
- } : {
260
- height: '100%',
261
- }),
203
+ header: {
204
+ cursor: 'pointer',
205
+ margin: '0',
206
+ ...orientation === 'vertical' ? {
207
+ width: '100%',
208
+ } : {
209
+ height: '100%',
210
+ },
211
+ },
262
212
  expandIcon: {
263
213
  margin: '0',
264
214
  padding: '0',
@@ -269,19 +219,36 @@ function getFixedStyles(_a) {
269
219
  },
270
220
  });
271
221
  }
272
- function getDefaultStyles(_a) {
273
- var _b = _a.orientation, orientation = _b === void 0 ? 'vertical' : _b;
274
- return (0, utils_1.asStyleDict)({
275
- collection: __assign({ transitionDuration: '100ms', transitionTimingFunction: 'ease-out' }, orientation === 'vertical' ? {
276
- transitionProperty: 'height, margin',
277
- } : {
278
- transitionProperty: 'width, margin',
279
- }),
280
- header: __assign({ border: 'none', outline: 'none', alignItems: 'center', background: '#fff', boxSizing: 'border-box', display: 'flex', flexDirection: 'row', justifyContent: 'space-between', padding: '0 10px', transitionDuration: '100ms', transitionProperty: 'transform, opacity, background, color', transitionTimingFunction: 'ease-out' }, orientation === 'vertical' ? {
281
- height: '50px',
282
- } : {
283
- width: '50px',
284
- }),
222
+ function getDefaultStyles({ orientation = 'vertical' }) {
223
+ return asStyleDict({
224
+ collection: {
225
+ transitionDuration: '100ms',
226
+ transitionTimingFunction: 'ease-out',
227
+ ...orientation === 'vertical' ? {
228
+ transitionProperty: 'height, margin',
229
+ } : {
230
+ transitionProperty: 'width, margin',
231
+ },
232
+ },
233
+ header: {
234
+ border: 'none',
235
+ outline: 'none',
236
+ alignItems: 'center',
237
+ background: '#fff',
238
+ boxSizing: 'border-box',
239
+ display: 'flex',
240
+ flexDirection: 'row',
241
+ justifyContent: 'space-between',
242
+ padding: '0 10px',
243
+ transitionDuration: '100ms',
244
+ transitionProperty: 'transform, opacity, background, color',
245
+ transitionTimingFunction: 'ease-out',
246
+ ...orientation === 'vertical' ? {
247
+ height: '50px',
248
+ } : {
249
+ width: '50px',
250
+ },
251
+ },
285
252
  headerLabel: {
286
253
  color: 'inherit',
287
254
  fontFamily: 'inherit',
@@ -316,4 +283,3 @@ function getDefaultStyles(_a) {
316
283
  },
317
284
  });
318
285
  }
319
- //# sourceMappingURL=Accordion.js.map