etudes 5.0.0 → 5.1.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.
Files changed (160) hide show
  1. package/package.json +31 -27
  2. package/components/Accordion.d.ts +0 -219
  3. package/components/Accordion.js +0 -346
  4. package/components/Accordion.js.map +0 -1
  5. package/components/BurgerButton.d.ts +0 -34
  6. package/components/BurgerButton.js +0 -205
  7. package/components/BurgerButton.js.map +0 -1
  8. package/components/Carousel.d.ts +0 -53
  9. package/components/Carousel.js +0 -255
  10. package/components/Carousel.js.map +0 -1
  11. package/components/Collection.d.ts +0 -171
  12. package/components/Collection.js +0 -204
  13. package/components/Collection.js.map +0 -1
  14. package/components/Counter.d.ts +0 -11
  15. package/components/Counter.js +0 -127
  16. package/components/Counter.js.map +0 -1
  17. package/components/CoverImage.d.ts +0 -28
  18. package/components/CoverImage.js +0 -122
  19. package/components/CoverImage.js.map +0 -1
  20. package/components/CoverVideo.d.ts +0 -28
  21. package/components/CoverVideo.js +0 -123
  22. package/components/CoverVideo.js.map +0 -1
  23. package/components/DebugConsole.d.ts +0 -15
  24. package/components/DebugConsole.js +0 -153
  25. package/components/DebugConsole.js.map +0 -1
  26. package/components/Dial.d.ts +0 -79
  27. package/components/Dial.js +0 -165
  28. package/components/Dial.js.map +0 -1
  29. package/components/Dropdown.d.ts +0 -109
  30. package/components/Dropdown.js +0 -227
  31. package/components/Dropdown.js.map +0 -1
  32. package/components/FlatSVG.d.ts +0 -72
  33. package/components/FlatSVG.js +0 -115
  34. package/components/FlatSVG.js.map +0 -1
  35. package/components/Image.d.ts +0 -144
  36. package/components/Image.js +0 -98
  37. package/components/Image.js.map +0 -1
  38. package/components/MasonryGrid.d.ts +0 -29
  39. package/components/MasonryGrid.js +0 -416
  40. package/components/MasonryGrid.js.map +0 -1
  41. package/components/Panorama.d.ts +0 -77
  42. package/components/Panorama.js +0 -163
  43. package/components/Panorama.js.map +0 -1
  44. package/components/PanoramaSlider.d.ts +0 -71
  45. package/components/PanoramaSlider.js +0 -229
  46. package/components/PanoramaSlider.js.map +0 -1
  47. package/components/RangeSlider.d.ts +0 -34
  48. package/components/RangeSlider.js +0 -326
  49. package/components/RangeSlider.js.map +0 -1
  50. package/components/RotatingGallery.d.ts +0 -91
  51. package/components/RotatingGallery.js +0 -112
  52. package/components/RotatingGallery.js.map +0 -1
  53. package/components/SelectableButton.d.ts +0 -19
  54. package/components/SelectableButton.js +0 -90
  55. package/components/SelectableButton.js.map +0 -1
  56. package/components/Slider.d.ts +0 -160
  57. package/components/Slider.js +0 -300
  58. package/components/Slider.js.map +0 -1
  59. package/components/StepwiseSlider.d.ts +0 -215
  60. package/components/StepwiseSlider.js +0 -381
  61. package/components/StepwiseSlider.js.map +0 -1
  62. package/components/SwipeContainer.d.ts +0 -21
  63. package/components/SwipeContainer.js +0 -132
  64. package/components/SwipeContainer.js.map +0 -1
  65. package/components/TextField.d.ts +0 -21
  66. package/components/TextField.js +0 -79
  67. package/components/TextField.js.map +0 -1
  68. package/components/Video.d.ts +0 -38
  69. package/components/Video.js +0 -118
  70. package/components/Video.js.map +0 -1
  71. package/components/WithTooltip.d.ts +0 -32
  72. package/components/WithTooltip.js +0 -267
  73. package/components/WithTooltip.js.map +0 -1
  74. package/hooks/useClickOutsideEffect.d.ts +0 -2
  75. package/hooks/useClickOutsideEffect.js +0 -58
  76. package/hooks/useClickOutsideEffect.js.map +0 -1
  77. package/hooks/useDragEffect.d.ts +0 -48
  78. package/hooks/useDragEffect.js +0 -99
  79. package/hooks/useDragEffect.js.map +0 -1
  80. package/hooks/useDragValueEffect.d.ts +0 -56
  81. package/hooks/useDragValueEffect.js +0 -136
  82. package/hooks/useDragValueEffect.js.map +0 -1
  83. package/hooks/useImageSize.d.ts +0 -21
  84. package/hooks/useImageSize.js +0 -67
  85. package/hooks/useImageSize.js.map +0 -1
  86. package/hooks/useInterval.d.ts +0 -18
  87. package/hooks/useInterval.js +0 -56
  88. package/hooks/useInterval.js.map +0 -1
  89. package/hooks/useLoadImageEffect.d.ts +0 -43
  90. package/hooks/useLoadImageEffect.js +0 -70
  91. package/hooks/useLoadImageEffect.js.map +0 -1
  92. package/hooks/useLoadVideoMetadataEffect.d.ts +0 -35
  93. package/hooks/useLoadVideoMetadataEffect.js +0 -66
  94. package/hooks/useLoadVideoMetadataEffect.js.map +0 -1
  95. package/hooks/useMounted.d.ts +0 -1
  96. package/hooks/useMounted.js +0 -32
  97. package/hooks/useMounted.js.map +0 -1
  98. package/hooks/usePrevious.d.ts +0 -19
  99. package/hooks/usePrevious.js +0 -20
  100. package/hooks/usePrevious.js.map +0 -1
  101. package/hooks/useRect.d.ts +0 -11
  102. package/hooks/useRect.js +0 -45
  103. package/hooks/useRect.js.map +0 -1
  104. package/hooks/useResizeEffect.d.ts +0 -17
  105. package/hooks/useResizeEffect.js +0 -63
  106. package/hooks/useResizeEffect.js.map +0 -1
  107. package/hooks/useScrollPositionEffect.d.ts +0 -13
  108. package/hooks/useScrollPositionEffect.js +0 -70
  109. package/hooks/useScrollPositionEffect.js.map +0 -1
  110. package/hooks/useSearchParamState.d.ts +0 -34
  111. package/hooks/useSearchParamState.js +0 -77
  112. package/hooks/useSearchParamState.js.map +0 -1
  113. package/hooks/useSize.d.ts +0 -10
  114. package/hooks/useSize.js +0 -44
  115. package/hooks/useSize.js.map +0 -1
  116. package/hooks/useTimeout.d.ts +0 -10
  117. package/hooks/useTimeout.js +0 -52
  118. package/hooks/useTimeout.js.map +0 -1
  119. package/hooks/useVideoSize.d.ts +0 -21
  120. package/hooks/useVideoSize.js +0 -67
  121. package/hooks/useVideoSize.js.map +0 -1
  122. package/hooks/useViewportSize.d.ts +0 -7
  123. package/hooks/useViewportSize.js +0 -41
  124. package/hooks/useViewportSize.js.map +0 -1
  125. package/operators/Conditional.d.ts +0 -5
  126. package/operators/Conditional.js +0 -22
  127. package/operators/Conditional.js.map +0 -1
  128. package/operators/Each.d.ts +0 -7
  129. package/operators/Each.js +0 -41
  130. package/operators/Each.js.map +0 -1
  131. package/operators/ExtractChild.d.ts +0 -8
  132. package/operators/ExtractChild.js +0 -74
  133. package/operators/ExtractChild.js.map +0 -1
  134. package/operators/ExtractChildren.d.ts +0 -6
  135. package/operators/ExtractChildren.js +0 -67
  136. package/operators/ExtractChildren.js.map +0 -1
  137. package/operators/Repeat.d.ts +0 -11
  138. package/operators/Repeat.js +0 -66
  139. package/operators/Repeat.js.map +0 -1
  140. package/providers/ScrollPositionProvider.d.ts +0 -15
  141. package/providers/ScrollPositionProvider.js +0 -112
  142. package/providers/ScrollPositionProvider.js.map +0 -1
  143. package/utils/asClassNameDict.d.ts +0 -3
  144. package/utils/asClassNameDict.js +0 -8
  145. package/utils/asClassNameDict.js.map +0 -1
  146. package/utils/asComponentDict.d.ts +0 -5
  147. package/utils/asComponentDict.js +0 -24
  148. package/utils/asComponentDict.js.map +0 -1
  149. package/utils/asStyleDict.d.ts +0 -4
  150. package/utils/asStyleDict.js +0 -8
  151. package/utils/asStyleDict.js.map +0 -1
  152. package/utils/cloneStyledElement.d.ts +0 -18
  153. package/utils/cloneStyledElement.js +0 -63
  154. package/utils/cloneStyledElement.js.map +0 -1
  155. package/utils/index.d.ts +0 -5
  156. package/utils/index.js +0 -22
  157. package/utils/index.js.map +0 -1
  158. package/utils/styles.d.ts +0 -2
  159. package/utils/styles.js +0 -23
  160. package/utils/styles.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "etudes",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "A study of headless React components",
5
5
  "main": "lib",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "predemo": "npm run clean",
12
12
  "demo": "concurrently \"cross-env NODE_ENV=production tsc -w --diagnostics false\" \"wait-on lib && cross-env NODE_ENV=development webpack-cli serve --mode development --hot --config demo/config/build.conf.ts\"",
13
13
  "test": "echo \"No tests yet :)\"",
14
- "lint": "eslint --ext .ts --ext .tsx src demo",
14
+ "lint": "eslint",
15
15
  "lint:fix": "npm run lint -- --fix",
16
16
  "scan": "dotenv -- sh -c 'sonar-scanner -Dsonar.projectKey=$SONAR_PROJECT_KEY -Dsonar.sources=. -Dsonar.host.url=$SONAR_HOST_URL -Dsonar.token=$SONAR_TOKEN'"
17
17
  },
@@ -35,55 +35,59 @@
35
35
  "utils"
36
36
  ],
37
37
  "devDependencies": {
38
- "@babel/core": "^7.24.4",
39
- "@babel/plugin-transform-runtime": "^7.24.3",
40
- "@babel/preset-env": "^7.24.4",
41
- "@babel/preset-react": "^7.24.1",
42
- "@babel/preset-typescript": "^7.24.1",
38
+ "@babel/core": "^7.24.7",
39
+ "@babel/plugin-transform-runtime": "^7.24.7",
40
+ "@babel/preset-env": "^7.24.7",
41
+ "@babel/preset-react": "^7.24.7",
42
+ "@babel/preset-typescript": "^7.24.7",
43
+ "@eslint/js": "^9.4.0",
44
+ "@semantic-release/changelog": "^6.0.3",
45
+ "@semantic-release/git": "^10.0.1",
46
+ "@stylistic/eslint-plugin": "^2.1.0",
43
47
  "@types/debug": "^4.1.12",
44
48
  "@types/html-webpack-plugin": "^3.2.9",
45
49
  "@types/node-polyglot": "^2.5.0",
46
- "@types/react": "^18.2.79",
47
- "@types/react-dom": "^18.2.25",
50
+ "@types/react": "^18.3.3",
51
+ "@types/react-dom": "^18.3.0",
48
52
  "@types/styled-components": "^5.1.34",
49
53
  "@types/webpack": "^5.28.5",
50
- "@types/webpack-env": "^1.18.4",
51
- "@typescript-eslint/eslint-plugin": "^7.7.0",
52
- "@typescript-eslint/parser": "^7.7.0",
54
+ "@types/webpack-env": "^1.18.5",
53
55
  "babel-loader": "^9.1.3",
54
56
  "babel-plugin-styled-components": "^2.1.4",
55
57
  "concurrently": "^8.2.2",
56
58
  "cross-env": "^7.0.3",
57
- "debug": "^4.3.4",
58
- "dotenv-cli": "^7.4.1",
59
- "eslint": "^8.56.0",
59
+ "debug": "^4.3.5",
60
+ "dotenv-cli": "^7.4.2",
61
+ "eslint": "^9.4.0",
60
62
  "html-webpack-plugin": "^5.6.0",
61
- "react": "^18.2.0",
62
- "react-dom": "^18.2.0",
63
- "react-router": "^6.22.3",
64
- "react-router-dom": "^6.22.3",
65
- "rimraf": "^5.0.5",
66
- "styled-components": "^6.1.8",
63
+ "react": "^18.3.1",
64
+ "react-dom": "^18.3.1",
65
+ "react-router": "^6.23.1",
66
+ "react-router-dom": "^6.23.1",
67
+ "rimraf": "^5.0.7",
68
+ "semantic-release": "^24.0.0",
69
+ "styled-components": "^6.1.11",
67
70
  "ts-node": "^10.9.2",
68
71
  "typescript": "^5.4.5",
72
+ "typescript-eslint": "^8.0.0-alpha.10",
69
73
  "wait-on": "^7.2.0",
70
74
  "webpack": "^5.91.0",
71
75
  "webpack-cli": "^5.1.4",
72
- "webpack-dev-server": "^4.15.1"
76
+ "webpack-dev-server": "^5.0.4"
73
77
  },
74
78
  "dependencies": {
75
- "clsx": "^2.1.0",
79
+ "clsx": "^2.1.1",
76
80
  "fast-deep-equal": "^3.1.3",
77
- "fast-xml-parser": "^4.3.6",
81
+ "fast-xml-parser": "^4.4.0",
78
82
  "interactjs": "^1.10.27",
79
83
  "resize-observer-polyfill": "^1.5.1",
80
- "spase": "^7.1.0"
84
+ "spase": "^7.2.1"
81
85
  },
82
86
  "peerDependencies": {
83
87
  "react": "^18.2.0"
84
88
  },
85
89
  "optionalDependencies": {
86
- "react-router": "^6.22.3",
87
- "react-router-dom": "^6.22.3"
90
+ "react-router": "^6.23.1",
91
+ "react-router-dom": "^6.23.1"
88
92
  }
89
93
  }
@@ -1,219 +0,0 @@
1
- import { type ComponentType, type HTMLAttributes, type PropsWithChildren, type ReactElement, type Ref } from 'react';
2
- import { type CollectionItemProps, type CollectionOrientation, type CollectionProps, type CollectionSelectionMode } from './Collection';
3
- /**
4
- * Type describing the current item selection of {@link Accordion}, composed of
5
- * a dictionary whose key corresponds the section index and value corresponds to
6
- * an array of selected item indices. If the selection mode of the
7
- * {@link Accordion} is `single`, only one key will be present and one index in
8
- * the array value.
9
- */
10
- export type AccordionSelection = Record<number, number[]>;
11
- /**
12
- * Type describing the data of each section in {@link Accordion}.
13
- */
14
- export type AccordionSection<T> = Pick<CollectionProps<T>, 'isSelectionTogglable' | 'itemLength' | 'itemPadding' | 'items' | 'layout' | 'numSegments'> & {
15
- /**
16
- * Padding (in pixels) between the sectionheader and the internal collection.
17
- */
18
- collectionPadding?: number;
19
- /**
20
- * Label for the section header.
21
- */
22
- label: string;
23
- /**
24
- * Maximum number of visible rows (if section orientation is `vertical`) or
25
- * columns (if section orientation is `horizontal`). If number of rows exceeds
26
- * the number of visible, a scrollbar will be put in place.
27
- */
28
- maxVisible?: number;
29
- };
30
- /**
31
- * Type describing the props of each `ItemComponent` provided to
32
- * {@link Accordion}.
33
- */
34
- export type AccordionItemProps<T> = CollectionItemProps<T>;
35
- /**
36
- * Type describing the props of each `HeaderComponent` provided to
37
- * {@link Accordion}.
38
- */
39
- export type AccordionHeaderProps<I, S extends AccordionSection<I> = AccordionSection<I>> = HTMLAttributes<HTMLElement> & PropsWithChildren<{
40
- /**
41
- * The index of the corresponding section.
42
- */
43
- index: number;
44
- /**
45
- * Indicates whether the corresponding section is collapsed.
46
- */
47
- isCollapsed: boolean;
48
- /**
49
- * Data provided to the corresponding section.
50
- */
51
- section: S;
52
- /**
53
- * Handler invoked to dispatch a custom event.
54
- *
55
- * @param name User-defined name of the custom event.
56
- * @param info Optional user-defined info of the custom event.
57
- */
58
- onCustomEvent?: (name: string, info?: any) => void;
59
- }>;
60
- /**
61
- * Type describing the props of {@link Accordion}.
62
- */
63
- export type AccordionProps<I, S extends AccordionSection<I> = AccordionSection<I>> = HTMLAttributes<HTMLDivElement> & PropsWithChildren<{
64
- /**
65
- * Specifies if expanded sections should automatically collapse upon expanding
66
- * another section.
67
- */
68
- autoCollapseSections?: boolean;
69
- /**
70
- * SVG markup to use as the collapse icon when a toggle button is
71
- * automatically generated (when `HeaderComponent` is absent).
72
- */
73
- collapseIconSvg?: string;
74
- /**
75
- * Indices of sections that are expanded. If specified, the component will not
76
- * manage expansion states.
77
- */
78
- expandedSectionIndices?: number[];
79
- /**
80
- * SVG markup to use as the expand icon when a toggle button is automatically
81
- * generated (when `HeaderComponent` is absent).
82
- */
83
- expandIconSvg?: string;
84
- /**
85
- * Orientation of this component.
86
- *
87
- * @see {@link CollectionOrientation}
88
- */
89
- orientation?: CollectionOrientation;
90
- /**
91
- * Padding (in pixels) between each section.
92
- */
93
- sectionPadding?: number;
94
- /**
95
- * Data provided to each section.
96
- */
97
- sections: S[];
98
- /**
99
- * Indices of selected items per section.
100
- *
101
- * @see {@link AccordionSelection}
102
- */
103
- selection?: AccordionSelection;
104
- /**
105
- * Selection mode of each section.
106
- *
107
- * @see {@link CollectionSelectionMode}
108
- */
109
- selectionMode?: CollectionSelectionMode;
110
- /**
111
- * Specifies if the component should use default styles.
112
- */
113
- usesDefaultStyles?: boolean;
114
- /**
115
- * Handler invoked when an item is activated in a section. The order of
116
- * handlers invoked when any selection changes take place is:
117
- * 1. `onActivateAt`
118
- * 2. `onDeselectAt`
119
- * 3. `onSelectAt`
120
- * 4. `onSelectionChange`
121
- *
122
- * @param itemIndex Item index.
123
- * @param sectionIndex Section index.
124
- */
125
- onActivateAt?: (itemIndex: number, sectionIndex: number) => void;
126
- /**
127
- * Handler invoked when a section is collapsed. The order of handlers invoked
128
- * when any section expansion changes take place is:
129
- * 1. `onCollapseSectionAt`
130
- * 2. `onExpandSectionAt`
131
- *
132
- * @param sectionIndex Section index.
133
- */
134
- onCollapseSectionAt?: (sectionIndex: number) => void;
135
- /**
136
- * Handler invoked when an item is deselected in a section. The order of
137
- * handlers invoked when any selection changes take place is:
138
- * 1. `onActivateAt`
139
- * 2. `onDeselectAt`
140
- * 3. `onSelectAt`
141
- * 4. `onSelectionChange`
142
- *
143
- * @param itemIndex Item index.
144
- * @param sectionIndex Section index.
145
- */
146
- onDeselectAt?: (itemIndex: number, sectionIndex: number) => void;
147
- /**
148
- * Handler invoked when the expansion state of any section changes.
149
- *
150
- * @param expandedSectionIndices Indices of sections that are expanded.
151
- */
152
- onExpandedSectionsChange?: (expandedSectionIndices: number[]) => void;
153
- /**
154
- * Handler invoked when a section is expanded. The order of handlers invoked
155
- * when any section expansion changes take place is:
156
- * 1. `onCollapseSectionAt`
157
- * 2. `onExpandSectionAt`
158
- *
159
- * @param sectionIndex Section index.
160
- */
161
- onExpandSectionAt?: (sectionIndex: number) => void;
162
- /**
163
- * Handler invoked when a custom event is dispatched from a section header.
164
- *
165
- * @param sectionIndex Index of the section which the header belongs.
166
- * @param eventName User-defined name of the dispatched event.
167
- * @param eventInfo Optional user-defined info of the dispatched event.
168
- */
169
- onHeaderCustomEvent?: (sectionIndex: number, eventName: string, eventInfo?: any) => void;
170
- /**
171
- * Handler invoked when a custom event is dispatched from an item.
172
- *
173
- * @param itemIndex Item index.
174
- * @param sectionIndex Section index.
175
- * @param eventName User-defined name of the dispatched event.
176
- * @param eventInfo Optional user-defined info of the dispatched event.
177
- */
178
- onItemCustomEvent?: (itemIndex: number, sectionIndex: number, eventName: string, eventInfo?: any) => void;
179
- /**
180
- * Handler invoked when an item is selected in a section. The order of
181
- * handlers invoked when any selection changes take place is:
182
- * 1. `onActivateAt`
183
- * 2. `onDeselectAt`
184
- * 3. `onSelectAt`
185
- * 4. `onSelectionChange`
186
- *
187
- * @param itemIndex Item index.
188
- * @param sectionIndex Section index.
189
- */
190
- onSelectAt?: (itemIndex: number, sectionIndex: number) => void;
191
- /**
192
- * Handler invoked when selected items have changed. The order of handlers
193
- * invoked when any selection changes take place is:
194
- * 1. `onActivateAt`
195
- * 2. `onDeselectAt`
196
- * 3. `onSelectAt`
197
- * 4. `onSelectionChange`
198
- *
199
- * @param selectedIndices Dictionary of indices of selected items per section.
200
- */
201
- onSelectionChange?: (selection: AccordionSelection) => void;
202
- /**
203
- * Component type for generating section headers inside the component. When
204
- * absent, one will be generated automatically.
205
- */
206
- HeaderComponent?: ComponentType<AccordionHeaderProps<I, S>>;
207
- /**
208
- * Component type for generating items for each section.
209
- */
210
- ItemComponent?: ComponentType<AccordionItemProps<I>>;
211
- }>;
212
- /**
213
- * A collection of selectable items laid out in sections in an accordion. Items
214
- * are generated based on the provided `ItemComponent` while each section header
215
- * is optionally provided by `HeaderComponent` or generated automatically.
216
- */
217
- export declare const Accordion: <I, S extends AccordionSection<I> = AccordionSection<I>>(props: AccordionProps<I, S> & {
218
- ref?: Ref<HTMLDivElement>;
219
- }) => ReactElement;
@@ -1,346 +0,0 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
36
- var __rest = (this && this.__rest) || function (s, e) {
37
- var t = {};
38
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
39
- t[p] = s[p];
40
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
41
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
42
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
43
- t[p[i]] = s[p[i]];
44
- }
45
- return t;
46
- };
47
- var __read = (this && this.__read) || function (o, n) {
48
- var m = typeof Symbol === "function" && o[Symbol.iterator];
49
- if (!m) return o;
50
- var i = m.call(o), r, ar = [], e;
51
- try {
52
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
53
- }
54
- catch (error) { e = { error: error }; }
55
- finally {
56
- try {
57
- if (r && !r.done && (m = i["return"])) m.call(i);
58
- }
59
- finally { if (e) throw e.error; }
60
- }
61
- return ar;
62
- };
63
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
64
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
65
- if (ar || !(i in from)) {
66
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
67
- ar[i] = from[i];
68
- }
69
- }
70
- return to.concat(ar || Array.prototype.slice.call(from));
71
- };
72
- var __importDefault = (this && this.__importDefault) || function (mod) {
73
- return (mod && mod.__esModule) ? mod : { "default": mod };
74
- };
75
- Object.defineProperty(exports, "__esModule", { value: true });
76
- exports.Accordion = void 0;
77
- var clsx_1 = __importDefault(require("clsx"));
78
- var react_1 = __importDefault(require("fast-deep-equal/react"));
79
- var react_2 = __importStar(require("react"));
80
- var Each_1 = require("../operators/Each");
81
- var utils_1 = require("../utils");
82
- var Collection_1 = require("./Collection");
83
- var FlatSVG_1 = require("./FlatSVG");
84
- /**
85
- * A collection of selectable items laid out in sections in an accordion. Items
86
- * are generated based on the provided `ItemComponent` while each section header
87
- * is optionally provided by `HeaderComponent` or generated automatically.
88
- */
89
- exports.Accordion = (0, react_2.forwardRef)(function (_a, ref) {
90
- 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"]);
91
- var isSectionIndexOutOfRange = function (sectionIndex) {
92
- if (sectionIndex >= sections.length)
93
- return true;
94
- if (sectionIndex < 0)
95
- return true;
96
- return false;
97
- };
98
- var isItemIndexOutOfRange = function (itemIndex, sectionIndex) {
99
- if (isSectionIndexOutOfRange(sectionIndex))
100
- return true;
101
- var items = sections[sectionIndex].items;
102
- if (itemIndex >= items.length)
103
- return true;
104
- if (itemIndex < 0)
105
- return true;
106
- return false;
107
- };
108
- 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; };
109
- var sanitizeExpandedSectionIndices = function (sectionIndices) { return sortIndices(sectionIndices).filter(function (t) { return !isSectionIndexOutOfRange(t); }); };
110
- var sanitizeSelection = function (selection) {
111
- var _a;
112
- var newValue = {};
113
- var _loop_1 = function (sectionIndex) {
114
- if (!Object.hasOwn(sections, sectionIndex))
115
- return "continue";
116
- var indices = sortIndices(__spreadArray([], __read((_a = selection[sectionIndex]) !== null && _a !== void 0 ? _a : []), false));
117
- newValue[Number(sectionIndex)] = sortIndices(indices).filter(function (t) { return !isItemIndexOutOfRange(t, Number(sectionIndex)); });
118
- };
119
- for (var sectionIndex in sections) {
120
- _loop_1(sectionIndex);
121
- }
122
- return newValue;
123
- };
124
- var isSectionExpandedAt = function (sectionIndex) { return expandedSectionIndices.indexOf(sectionIndex) >= 0; };
125
- var toggleSectionAt = function (sectionIndex) {
126
- var transform;
127
- if (isSectionExpandedAt(sectionIndex)) {
128
- transform = function (val) { return val.filter(function (t) { return t !== sectionIndex; }); };
129
- }
130
- else if (autoCollapseSections) {
131
- transform = function (val) { return [sectionIndex]; };
132
- }
133
- else {
134
- transform = function (val) { return __spreadArray(__spreadArray([], __read(val.filter(function (t) { return t !== sectionIndex; })), false), [sectionIndex], false); };
135
- }
136
- handleExpandedSectionsChange(expandedSectionIndices, transform(expandedSectionIndices));
137
- };
138
- var handleSelectAt = function (itemIndex, sectionIndex) {
139
- if (isSelectedAt(itemIndex, sectionIndex))
140
- return;
141
- var transform;
142
- switch (selectionMode) {
143
- case 'multiple':
144
- transform = function (val) {
145
- var _a;
146
- var _b;
147
- 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)));
148
- };
149
- break;
150
- case 'single':
151
- transform = function (val) {
152
- var _a;
153
- return (_a = {},
154
- _a[sectionIndex] = [itemIndex],
155
- _a);
156
- };
157
- break;
158
- default:
159
- return;
160
- }
161
- var newValue = transform(selection);
162
- prevSelectionRef.current = newValue;
163
- handleSelectionChange(selection, newValue);
164
- };
165
- var handleDeselectAt = function (itemIndex, sectionIndex) {
166
- if (!isSelectedAt(itemIndex, sectionIndex))
167
- return;
168
- var transform = function (val) {
169
- var _a;
170
- var _b;
171
- return (__assign(__assign({}, val), (_a = {}, _a[sectionIndex] = ((_b = val[sectionIndex]) !== null && _b !== void 0 ? _b : []).filter(function (t) { return t !== itemIndex; }), _a)));
172
- };
173
- var newValue = transform(selection);
174
- prevSelectionRef.current = newValue;
175
- handleSelectionChange(selection, newValue);
176
- };
177
- var handleExpandedSectionsChange = function (oldValue, newValue) {
178
- var _a;
179
- if ((0, react_1.default)(oldValue, newValue))
180
- return;
181
- var collapsed = (_a = oldValue === null || oldValue === void 0 ? void 0 : oldValue.filter(function (t) { return newValue.indexOf(t) === -1; })) !== null && _a !== void 0 ? _a : [];
182
- var expanded = newValue.filter(function (t) { return (oldValue === null || oldValue === void 0 ? void 0 : oldValue.indexOf(t)) === -1; });
183
- collapsed.forEach(function (t) { return onCollapseSectionAt === null || onCollapseSectionAt === void 0 ? void 0 : onCollapseSectionAt(t); });
184
- expanded.forEach(function (t) { return onExpandSectionAt === null || onExpandSectionAt === void 0 ? void 0 : onExpandSectionAt(t); });
185
- onExpandedSectionsChange === null || onExpandedSectionsChange === void 0 ? void 0 : onExpandedSectionsChange(newValue);
186
- };
187
- var handleSelectionChange = function (oldValue, newValue) {
188
- var _a, _b;
189
- if ((0, react_1.default)(oldValue, newValue))
190
- return;
191
- var numSections = sections.length;
192
- var allDeselected = [];
193
- var allSelected = [];
194
- var _loop_2 = function (i) {
195
- var oldSection = (_a = oldValue === null || oldValue === void 0 ? void 0 : oldValue[i]) !== null && _a !== void 0 ? _a : [];
196
- var newSection = (_b = newValue[i]) !== null && _b !== void 0 ? _b : [];
197
- var deselected = oldSection.filter(function (t) { return newSection.indexOf(t) === -1; });
198
- var selected = newSection.filter(function (t) { return (oldSection === null || oldSection === void 0 ? void 0 : oldSection.indexOf(t)) === -1; });
199
- allDeselected = __spreadArray(__spreadArray([], __read(allDeselected), false), __read(deselected.map(function (t) { return [t, i]; })), false);
200
- allSelected = __spreadArray(__spreadArray([], __read(allSelected), false), __read(selected.map(function (t) { return [t, i]; })), false);
201
- };
202
- for (var i = 0; i < numSections; i++) {
203
- _loop_2(i);
204
- }
205
- allDeselected.forEach(function (t) { return onDeselectAt === null || onDeselectAt === void 0 ? void 0 : onDeselectAt(t[0], t[1]); });
206
- allSelected.forEach(function (t) { return onSelectAt === null || onSelectAt === void 0 ? void 0 : onSelectAt(t[0], t[1]); });
207
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(newValue);
208
- };
209
- var selection = sanitizeSelection(externalSelection !== null && externalSelection !== void 0 ? externalSelection : {});
210
- var expandedSectionIndices = sanitizeExpandedSectionIndices(externalExpandedSectionIndices !== null && externalExpandedSectionIndices !== void 0 ? externalExpandedSectionIndices : []);
211
- var fixedStyles = getFixedStyles({ orientation: orientation });
212
- var defaultStyles = usesDefaultStyles ? getDefaultStyles({ orientation: orientation }) : undefined;
213
- var prevSelectionRef = (0, react_2.useRef)();
214
- var prevSelection = prevSelectionRef.current;
215
- (0, react_2.useEffect)(function () {
216
- prevSelectionRef.current = selection;
217
- if (prevSelection === undefined)
218
- return;
219
- handleSelectionChange(prevSelection, selection);
220
- }, [JSON.stringify(selection)]);
221
- return (react_2.default.createElement("div", __assign({}, props, { "data-component": 'accordion', style: (0, utils_1.styles)(style, fixedStyles.root), ref: ref }),
222
- react_2.default.createElement(Each_1.Each, { in: sections }, function (section, sectionIndex) {
223
- var _a;
224
- 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;
225
- var allVisible = layout === 'list' ? items.length : Math.ceil(items.length / numSegments);
226
- var numVisible = maxVisible < 0 ? allVisible : Math.min(allVisible, maxVisible);
227
- var maxLength = itemLength * numVisible + itemPadding * (numVisible - 1);
228
- var isCollapsed = !isSectionExpandedAt(sectionIndex);
229
- var expandIconComponent = expandIconSvg ? react_2.default.createElement(FlatSVG_1.FlatSVG, { svg: expandIconSvg, style: defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.expandIcon }) : react_2.default.createElement(react_2.default.Fragment, null);
230
- var collapseIconComponent = collapseIconSvg ? react_2.default.createElement(FlatSVG_1.FlatSVG, { svg: collapseIconSvg, style: defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.collapseIcon }) : expandIconComponent;
231
- return (react_2.default.createElement("div", { style: (0, utils_1.styles)(fixedStyles.section, orientation === 'vertical' ? {
232
- marginTop: sectionIndex === 0 ? '0px' : "".concat(sectionPadding, "px"),
233
- } : {
234
- marginLeft: sectionIndex === 0 ? '0px' : "".concat(sectionPadding, "px"),
235
- }) },
236
- HeaderComponent ? (react_2.default.createElement(HeaderComponent, { "data-child": 'header', className: (0, clsx_1.default)({ collapsed: isCollapsed, expanded: !isCollapsed }), style: (0, utils_1.styles)(fixedStyles.header), index: sectionIndex, isCollapsed: isCollapsed, section: section, onClick: function () { return toggleSectionAt(sectionIndex); }, onCustomEvent: function (name, info) { return onHeaderCustomEvent === null || onHeaderCustomEvent === void 0 ? void 0 : onHeaderCustomEvent(sectionIndex, name, info); } })) : (react_2.default.createElement("button", { "data-child": 'header', className: (0, clsx_1.default)({ collapsed: isCollapsed, expanded: !isCollapsed }), style: (0, utils_1.styles)(fixedStyles.header, defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.header), onClick: function () { return toggleSectionAt(sectionIndex); } },
237
- react_2.default.createElement("span", { style: (0, utils_1.styles)(defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.headerLabel), dangerouslySetInnerHTML: { __html: section.label } }),
238
- (0, utils_1.cloneStyledElement)(isCollapsed ? expandIconComponent : collapseIconComponent, {
239
- style: (0, utils_1.styles)(isCollapsed ? fixedStyles.expandIcon : fixedStyles.collapseIcon),
240
- }))),
241
- react_2.default.createElement(Collection_1.Collection, { "data-child": 'collection', className: (0, clsx_1.default)({ collapsed: isCollapsed, expanded: !isCollapsed }), style: (0, utils_1.styles)(fixedStyles.list, defaultStyles === null || defaultStyles === void 0 ? void 0 : defaultStyles.collection, orientation === 'vertical' ? {
242
- width: '100%',
243
- height: isCollapsed ? '0px' : "".concat(maxLength, "px"),
244
- marginTop: isCollapsed ? '0px' : "".concat(collectionPadding, "px"),
245
- overflowY: maxVisible < 0 || maxVisible >= allVisible ? 'hidden' : 'scroll',
246
- } : {
247
- marginLeft: isCollapsed ? '0px' : "".concat(collectionPadding, "px"),
248
- overflowX: maxVisible < 0 || maxVisible >= allVisible ? 'hidden' : 'scroll',
249
- width: isCollapsed ? '0px' : "".concat(maxLength, "px"),
250
- height: '100%',
251
- }), selectionMode: selectionMode, isSelectionTogglable: isSelectionTogglable, itemLength: itemLength, itemPadding: itemPadding, items: items, orientation: orientation, layout: layout, numSegments: numSegments, selection: (_a = selection[sectionIndex]) !== null && _a !== void 0 ? _a : [], onActivateAt: function (itemIndex) {
252
- onActivateAt === null || onActivateAt === void 0 ? void 0 : onActivateAt(itemIndex, sectionIndex);
253
- }, onDeselectAt: function (itemIndex) {
254
- handleDeselectAt === null || handleDeselectAt === void 0 ? void 0 : handleDeselectAt(itemIndex, sectionIndex);
255
- }, onItemCustomEvent: function (itemIndex, name, info) {
256
- onItemCustomEvent === null || onItemCustomEvent === void 0 ? void 0 : onItemCustomEvent(itemIndex, sectionIndex, name, info);
257
- }, onSelectAt: function (itemIndex) {
258
- handleSelectAt === null || handleSelectAt === void 0 ? void 0 : handleSelectAt(itemIndex, sectionIndex);
259
- }, ItemComponent: ItemComponent })));
260
- })));
261
- });
262
- Object.defineProperty(exports.Accordion, 'displayName', { value: 'Accordion', writable: false });
263
- function sortIndices(indices) {
264
- return indices.sort(function (a, b) { return a - b; });
265
- }
266
- function getFixedStyles(_a) {
267
- var _b = _a.orientation, orientation = _b === void 0 ? 'vertical' : _b;
268
- return (0, utils_1.asStyleDict)({
269
- root: __assign({ alignItems: 'center', boxSizing: 'border-box', display: 'flex', flex: '0 0 auto', justifyContent: 'flex-start', padding: '0' }, orientation === 'vertical' ? {
270
- flexDirection: 'column',
271
- height: 'auto',
272
- } : {
273
- flexDirection: 'row',
274
- width: 'auto',
275
- }),
276
- section: __assign({ alignItems: 'flex-start', display: 'flex', flex: '0 0 auto', justifyContent: 'flex-start', margin: '0', padding: '0' }, orientation === 'vertical' ? {
277
- flexDirection: 'column',
278
- width: '100%',
279
- } : {
280
- flexDirection: 'row',
281
- height: '100%',
282
- }),
283
- list: {},
284
- header: __assign({ cursor: 'pointer', margin: '0' }, orientation === 'vertical' ? {
285
- width: '100%',
286
- } : {
287
- height: '100%',
288
- }),
289
- expandIcon: {
290
- margin: '0',
291
- padding: '0',
292
- },
293
- collapseIcon: {
294
- margin: '0',
295
- padding: '0',
296
- },
297
- });
298
- }
299
- function getDefaultStyles(_a) {
300
- var _b = _a.orientation, orientation = _b === void 0 ? 'vertical' : _b;
301
- return (0, utils_1.asStyleDict)({
302
- collection: __assign({ transitionDuration: '100ms', transitionTimingFunction: 'ease-out' }, orientation === 'vertical' ? {
303
- transitionProperty: 'height, margin',
304
- } : {
305
- transitionProperty: 'width, margin',
306
- }),
307
- 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' ? {
308
- height: '50px',
309
- } : {
310
- width: '50px',
311
- }),
312
- headerLabel: {
313
- color: 'inherit',
314
- fontFamily: 'inherit',
315
- fontSize: 'inherit',
316
- fontWeight: 'inherit',
317
- letterSpacing: 'inherit',
318
- lineHeight: 'inherit',
319
- pointerEvents: 'none',
320
- transition: 'inherit',
321
- },
322
- expandIcon: {
323
- boxSizing: 'border-box',
324
- display: 'block',
325
- fill: '#000',
326
- height: '15px',
327
- transformOrigin: 'center',
328
- transitionDuration: '100ms',
329
- transitionProperty: 'transform',
330
- transitionTimingFunction: 'ease-out',
331
- width: '15px',
332
- },
333
- collapseIcon: {
334
- boxSizing: 'border-box',
335
- display: 'block',
336
- fill: '#000',
337
- height: '15px',
338
- transformOrigin: 'center',
339
- transitionDuration: '100ms',
340
- transitionProperty: 'transform',
341
- transitionTimingFunction: 'ease-out',
342
- width: '15px',
343
- },
344
- });
345
- }
346
- //# sourceMappingURL=Accordion.js.map