@wavv/ui 2.2.2-alpha.4 → 2.2.2-alpha.6

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 (230) hide show
  1. package/build/assets/icons/CaretDown.js +18 -0
  2. package/build/assets/icons/CaretUp.js +18 -0
  3. package/build/assets/icons/Checkbox.js +15 -0
  4. package/build/assets/icons/CheckboxOff.js +15 -0
  5. package/build/assets/icons/CheckboxPartial.js +15 -0
  6. package/build/assets/icons/Dialpad.js +18 -0
  7. package/build/assets/icons/Exclamation.js +25 -0
  8. package/build/assets/icons/Phone.js +13 -0
  9. package/build/assets/icons/PhoneAdd.js +21 -0
  10. package/build/assets/icons/PhoneBlocked.js +22 -0
  11. package/build/assets/icons/PhoneCallback.js +21 -0
  12. package/build/assets/icons/PhoneEnd.js +28 -0
  13. package/build/assets/icons/PhoneForward.js +22 -0
  14. package/build/assets/icons/PhoneHistory.js +21 -0
  15. package/build/assets/icons/PhoneHold.js +22 -0
  16. package/build/assets/icons/PhoneIncoming.js +22 -0
  17. package/build/assets/icons/PhoneMissed.js +22 -0
  18. package/build/assets/icons/PhoneTalk.js +22 -0
  19. package/build/assets/icons/PhoneTransfer.js +21 -0
  20. package/build/assets/icons/RadioButton.js +22 -0
  21. package/build/assets/icons/RadioButtonOff.js +15 -0
  22. package/build/assets/icons/Record.js +18 -0
  23. package/build/assets/icons/Screenshot.js +39 -0
  24. package/build/assets/icons/ShieldWavv.js +30 -0
  25. package/build/assets/icons/Spotify.js +15 -0
  26. package/build/assets/icons/SubArrow.js +16 -0
  27. package/build/assets/icons/ToggleOff.js +15 -0
  28. package/build/assets/icons/ToggleOn.js +15 -0
  29. package/build/assets/icons/TransferCancel.js +60 -0
  30. package/build/components/Accordion/Accordion.js +26 -0
  31. package/build/components/Accordion/Header.js +86 -0
  32. package/build/components/Accordion/Item.js +25 -0
  33. package/build/components/Accordion/Panel.js +64 -0
  34. package/build/components/Accordion/index.js +2 -0
  35. package/build/components/Audio.js +248 -0
  36. package/build/components/BarChart.js +123 -0
  37. package/build/components/Button/Button.js +258 -0
  38. package/build/components/Button/ButtonLoader.js +20 -0
  39. package/build/components/Button/ButtonTypes.js +0 -0
  40. package/build/components/Button/Group.js +58 -0
  41. package/build/components/Button/index.js +2 -0
  42. package/build/components/Calendar.js +49 -0
  43. package/build/components/CalendarParts/CalendarContainerStyles.js +15 -0
  44. package/build/components/CalendarParts/CalendarContent.js +138 -0
  45. package/build/components/CalendarParts/CalendarHeader.js +146 -0
  46. package/build/components/CalendarParts/useMinMax.js +23 -0
  47. package/build/components/CalendarParts/utils.js +6 -0
  48. package/build/components/ChartHelpers.js +121 -0
  49. package/build/components/Checkbox.js +85 -0
  50. package/build/components/Code/Code.js +117 -0
  51. package/build/components/Code/Copy.js +50 -0
  52. package/build/components/Code/Endpoint.js +82 -0
  53. package/build/components/Code/index.js +3 -0
  54. package/build/components/ComboBox.js +190 -0
  55. package/build/components/CommandMenu/CommandItem.js +32 -0
  56. package/build/components/CommandMenu/CommandMenu.js +136 -0
  57. package/build/components/CommandMenu/CommandOptions.js +24 -0
  58. package/build/components/CommandMenu/CommandSection.js +19 -0
  59. package/build/components/CommandMenu/index.js +2 -0
  60. package/build/components/DateRangeSelect.js +359 -0
  61. package/build/components/DocTable.js +32 -0
  62. package/build/components/Dot.js +60 -0
  63. package/build/components/DraftEditor.js +188 -0
  64. package/build/components/Dropdown.js +130 -0
  65. package/build/components/DropdownMenu.js +131 -0
  66. package/build/components/DropdownMenuParts/Menu.js +6 -0
  67. package/build/components/DropdownMenuParts/MenuItem.js +54 -0
  68. package/build/components/DropdownMenuParts/MenuOptions.js +47 -0
  69. package/build/components/DropdownMenuParts/MenuSection.js +14 -0
  70. package/build/components/DropdownSelect.js +171 -0
  71. package/build/components/DynamicIcon.js +49 -0
  72. package/build/components/Editor/Editor.js +356 -0
  73. package/build/components/Editor/EditorStyles.js +259 -0
  74. package/build/components/Editor/MergeFieldExtension.js +110 -0
  75. package/build/components/Editor/RichTextToolbar.js +515 -0
  76. package/build/components/Editor/editorUtils.js +213 -0
  77. package/build/components/Editor/index.js +3 -0
  78. package/build/components/Ellipsis.js +22 -0
  79. package/build/components/Focusable.js +20 -0
  80. package/build/components/Form.js +68 -0
  81. package/build/components/FormControl.js +72 -0
  82. package/build/components/Grid.js +53 -0
  83. package/build/components/Icon/Icon.js +89 -0
  84. package/build/components/Icon/customIcons.js +48 -0
  85. package/build/components/Icon/icons.js +145 -0
  86. package/build/components/Icon/index.js +3 -0
  87. package/build/components/ImageViewer.js +142 -0
  88. package/build/components/InlineCode.js +10 -0
  89. package/build/components/InputHelpers.js +106 -0
  90. package/build/components/Inputs/DatePicker.js +111 -0
  91. package/build/components/Inputs/DateRangePicker.js +166 -0
  92. package/build/components/Inputs/InlineInput.js +71 -0
  93. package/build/components/Inputs/NumberInput.js +117 -0
  94. package/build/components/Inputs/PhoneInput.js +96 -0
  95. package/build/components/Inputs/SearchInput.js +84 -0
  96. package/build/components/Inputs/TextArea.js +164 -0
  97. package/build/components/Inputs/TextInput.js +74 -0
  98. package/build/components/Inputs/TimeInput.js +74 -0
  99. package/build/components/Inputs/helpers/AriaButton.js +19 -0
  100. package/build/components/Inputs/helpers/DateSegment.js +22 -0
  101. package/build/components/Inputs/helpers/Description.js +11 -0
  102. package/build/components/Inputs/helpers/ErrorMessage.js +11 -0
  103. package/build/components/Inputs/helpers/Input.js +6 -0
  104. package/build/components/Inputs/helpers/InputContainerStyles.js +78 -0
  105. package/build/components/Inputs/helpers/InputMessage.js +30 -0
  106. package/build/components/Inputs/helpers/InputStyles.js +43 -0
  107. package/build/components/Inputs/helpers/Label.js +42 -0
  108. package/build/components/Inputs/helpers/LabelWrapper.js +14 -0
  109. package/build/components/Inputs/helpers/PickerToggle.js +7 -0
  110. package/build/components/Inputs/helpers/TextArea.js +8 -0
  111. package/build/components/Inputs/helpers/filterPastedText.js +9 -0
  112. package/build/components/Inputs/helpers/handlePaste.js +12 -0
  113. package/build/components/Inputs/helpers/isAcceptable.js +7 -0
  114. package/build/components/Inputs/helpers/useDynamicWidth.js +39 -0
  115. package/build/components/Inputs/helpers/useInputFocus.js +19 -0
  116. package/build/components/Label.js +42 -0
  117. package/build/components/LineChart.js +80 -0
  118. package/build/components/ListBoxParts/GridListItem.js +34 -0
  119. package/build/components/ListBoxParts/ListBoxItem.js +32 -0
  120. package/build/components/ListBoxParts/ListOptions.js +45 -0
  121. package/build/components/ListHelpers/GridListHeader.js +14 -0
  122. package/build/components/ListHelpers/GridListSection.js +14 -0
  123. package/build/components/ListHelpers/ItemHeaderBody.js +36 -0
  124. package/build/components/ListHelpers/ListHeader.js +14 -0
  125. package/build/components/ListHelpers/ListItemStyles.js +52 -0
  126. package/build/components/ListHelpers/ListRootStyles.js +14 -0
  127. package/build/components/ListHelpers/ListSection.js +14 -0
  128. package/build/components/ListHelpers/ListStyles.js +29 -0
  129. package/build/components/Menu.js +159 -0
  130. package/build/components/Message.js +107 -0
  131. package/build/components/MessageHr.js +32 -0
  132. package/build/components/Modal.js +212 -0
  133. package/build/components/MotionPopover.js +39 -0
  134. package/build/components/MultiSelect/MultiSelect.js +263 -0
  135. package/build/components/MultiSelect/SearchDropdown.js +155 -0
  136. package/build/components/MultiSelect/index.js +2 -0
  137. package/build/components/OptionHelpers/Container.js +34 -0
  138. package/build/components/OptionHelpers/Item.js +59 -0
  139. package/build/components/OptionHelpers/types.js +0 -0
  140. package/build/components/Pagination.js +121 -0
  141. package/build/components/PieChart.js +40 -0
  142. package/build/components/Popover.js +40 -0
  143. package/build/components/PortalScope.js +8 -0
  144. package/build/components/Progress/CirclePercent.js +56 -0
  145. package/build/components/Progress/Progress.js +59 -0
  146. package/build/components/Progress/index.js +3 -0
  147. package/build/components/Radio.js +45 -0
  148. package/build/components/RangeCalendar.js +60 -0
  149. package/build/components/Select.js +162 -0
  150. package/build/components/Slider.js +50 -0
  151. package/build/components/Spinner.js +70 -0
  152. package/build/components/Table/Body.js +49 -0
  153. package/build/components/Table/Cell.js +63 -0
  154. package/build/components/Table/Check.js +35 -0
  155. package/build/components/Table/Column.js +129 -0
  156. package/build/components/Table/ColumnSort.js +26 -0
  157. package/build/components/Table/Header.js +64 -0
  158. package/build/components/Table/Resizer.js +25 -0
  159. package/build/components/Table/Row.js +84 -0
  160. package/build/components/Table/SortCaret.js +24 -0
  161. package/build/components/Table/Table.js +88 -0
  162. package/build/components/Table/contentStyles.js +20 -0
  163. package/build/components/Table/context.js +4 -0
  164. package/build/components/Table/index.js +2 -0
  165. package/build/components/Table/types.js +0 -0
  166. package/build/components/Tabs.js +151 -0
  167. package/build/components/Tag.js +71 -0
  168. package/build/components/Toggle.js +59 -0
  169. package/build/components/ToggleButton/ToggleButton.js +104 -0
  170. package/build/components/ToggleButton/ToggleButtonGroup.js +36 -0
  171. package/build/components/ToggleButton/context.js +8 -0
  172. package/build/components/ToggleButton/index.js +3 -0
  173. package/build/components/Tooltip.js +136 -0
  174. package/build/components/TransferList.js +234 -0
  175. package/build/components/Tree/Tree.js +69 -0
  176. package/build/components/Tree/TreeContext.js +3 -0
  177. package/build/components/Tree/TreeItem.js +93 -0
  178. package/build/components/Tree/index.js +2 -0
  179. package/build/components/UnstyledButton.js +8 -0
  180. package/build/components/Waveform.js +243 -0
  181. package/build/components/draftUtils.js +193 -0
  182. package/build/components/helpers/getIcon.js +28 -0
  183. package/build/components/helpers/getPopPosition.js +20 -0
  184. package/build/components/helpers/isPropAllowed.js +3 -0
  185. package/build/components/helpers/mergePadding.js +47 -0
  186. package/build/components/helpers/styledProps.js +34 -0
  187. package/build/components/typeDefs/elementTypes.js +0 -0
  188. package/build/components/typeDefs/inputTypes.js +0 -0
  189. package/build/components/typeDefs/selectionTypes.js +0 -0
  190. package/build/components/typeDefs/tagTypes.js +0 -0
  191. package/build/components/types.js +0 -0
  192. package/build/global-styles/GlobalStorybookStyles.js +108 -0
  193. package/build/global-styles/ResetStyles.js +33 -0
  194. package/build/global-styles/ScrollbarStyles.js +26 -0
  195. package/build/global-styles/ToastStyles.js +66 -0
  196. package/build/global-styles/index.js +4 -0
  197. package/build/hooks/index.js +9 -0
  198. package/build/hooks/useConfirm.js +91 -0
  199. package/build/hooks/useControlledOpenState.js +22 -0
  200. package/build/hooks/useCopy.js +28 -0
  201. package/build/hooks/useElementObserver.js +6 -0
  202. package/build/hooks/useEventListener.js +19 -0
  203. package/build/hooks/useOnClickOutside.js +21 -0
  204. package/build/hooks/usePrevious.js +12 -0
  205. package/build/hooks/useSelectAll.js +60 -0
  206. package/build/hooks/useWindowSize.js +25 -0
  207. package/build/index.js +79 -12348
  208. package/build/theme/ThemeTypes.js +0 -0
  209. package/build/theme/common/button.js +33 -0
  210. package/build/theme/common/common.js +38 -0
  211. package/build/theme/common/index.js +4 -0
  212. package/build/theme/core/colors.js +77 -0
  213. package/build/theme/core/dark/dark.js +457 -0
  214. package/build/theme/core/dark/darkScale.js +36 -0
  215. package/build/theme/core/light/light.js +456 -0
  216. package/build/theme/core/light/lightScale.js +35 -0
  217. package/build/theme/eighties/colors.js +78 -0
  218. package/build/theme/eighties/dark/dark.js +457 -0
  219. package/build/theme/eighties/dark/darkScale.js +36 -0
  220. package/build/theme/eighties/light/light.js +456 -0
  221. package/build/theme/eighties/light/lightScale.js +35 -0
  222. package/build/theme/index.js +28 -0
  223. package/build/utils/chunk.js +13 -0
  224. package/build/utils/copyToClipboard.js +29 -0
  225. package/build/utils/flattenListOptions.js +4 -0
  226. package/build/utils/formatDate.js +55 -0
  227. package/build/utils/index.js +6 -0
  228. package/build/utils/numberWithCommas.js +3 -0
  229. package/build/utils/range.js +11 -0
  230. package/package.json +6 -2
@@ -0,0 +1,243 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useTheme } from "@emotion/react";
3
+ import styled from "@emotion/styled";
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { Label, Slider, SliderOutput, SliderThumb, SliderTrack } from "react-aria-components";
6
+ import { marginProps } from "./helpers/styledProps.js";
7
+ const Waveform2 = ({ src, label, showOutput = false, showHoverTime = false, unplayedColor, playedColor, barCount = 1200, heightMultiplier = 1, width, height, formatOptions, ...sliderProps })=>{
8
+ const { background4, color } = useTheme();
9
+ const canvasRef = useRef(null);
10
+ const trackRef = useRef(null);
11
+ const [peaks, setPeaks] = useState([]);
12
+ const [isHovering, setIsHovering] = useState(false);
13
+ const [hoverSeconds, setHoverSeconds] = useState(null);
14
+ const currentValue = Number(sliderProps.value ?? sliderProps.defaultValue ?? 0);
15
+ const maxValue = Number(sliderProps.maxValue ?? 100);
16
+ useEffect(()=>{
17
+ let cancelled = false;
18
+ const buildPeaks = async ()=>{
19
+ try {
20
+ if (!src) return;
21
+ const resp = await fetch(src, {
22
+ cache: 'force-cache'
23
+ });
24
+ const buf = await resp.arrayBuffer();
25
+ const Ctx = window.AudioContext || window.webkitAudioContext;
26
+ const audioCtx = new Ctx();
27
+ const audioBuffer = await audioCtx.decodeAudioData(buf.slice(0));
28
+ const samplesPerBar = Math.max(1, Math.floor(audioBuffer.length / barCount));
29
+ const left = audioBuffer.getChannelData(0);
30
+ const right = audioBuffer.numberOfChannels > 1 ? audioBuffer.getChannelData(1) : left;
31
+ const computed = [];
32
+ for(let i = 0; i < barCount; i += 1){
33
+ const start = i * samplesPerBar;
34
+ const end = Math.min(start + samplesPerBar, audioBuffer.length);
35
+ let peak = 0;
36
+ for(let j = start; j < end; j += 1){
37
+ const v = Math.max(Math.abs(left[j] || 0), Math.abs(right[j] || 0));
38
+ if (v > peak) peak = v;
39
+ }
40
+ computed.push(peak);
41
+ }
42
+ audioCtx.close?.();
43
+ if (!cancelled) setPeaks(computed);
44
+ } catch (_e) {
45
+ if (!cancelled) setPeaks([]);
46
+ }
47
+ };
48
+ buildPeaks();
49
+ return ()=>{
50
+ cancelled = true;
51
+ };
52
+ }, [
53
+ src,
54
+ barCount
55
+ ]);
56
+ useEffect(()=>{
57
+ const canvas = canvasRef.current;
58
+ const track = trackRef.current;
59
+ if (!canvas || !track) return;
60
+ const drawWaveform = ()=>{
61
+ const ctx = canvas.getContext('2d');
62
+ if (!ctx) return;
63
+ const rect = track.getBoundingClientRect();
64
+ const w = rect.width || track.clientWidth || 0;
65
+ const h = rect.height || track.clientHeight || 0;
66
+ if (0 === w || 0 === h) return;
67
+ const dpr = window.devicePixelRatio || 1;
68
+ canvas.width = Math.max(1, Math.floor(w * dpr));
69
+ canvas.height = Math.max(1, Math.floor(h * dpr));
70
+ canvas.style.width = `${w}px`;
71
+ canvas.style.height = `${h}px`;
72
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
73
+ ctx.clearRect(0, 0, w, h);
74
+ const centerY = h / 2;
75
+ const gap = 2;
76
+ const barWidth = 3;
77
+ const maxBars = Math.max(1, Math.floor(w / (barWidth + gap)));
78
+ const bars = Math.min(maxBars, Math.max(peaks.length, maxBars));
79
+ const getPeak = (i, totalBars)=>{
80
+ if (0 === peaks.length) return 0.08;
81
+ const idx = Math.floor(i / totalBars * peaks.length);
82
+ return Math.min(1, Math.max(0, peaks[idx]));
83
+ };
84
+ const ratioPlayed = maxValue ? currentValue / maxValue : 0;
85
+ const playedCutoffIndex = Math.floor(ratioPlayed * bars);
86
+ for(let i = 0; i < bars; i += 1){
87
+ const peak = getPeak(i, bars);
88
+ const barHeight = Math.max(1, peak * (h - 4) * heightMultiplier);
89
+ const x = i * (barWidth + gap);
90
+ const unplayedFill = unplayedColor ?? background4;
91
+ const playedFill = playedColor ?? color.brand;
92
+ ctx.fillStyle = i <= playedCutoffIndex ? playedFill : unplayedFill;
93
+ ctx.fillRect(x, centerY - barHeight / 2, barWidth, barHeight);
94
+ }
95
+ };
96
+ drawWaveform();
97
+ const resizeObserver = new ResizeObserver(()=>{
98
+ drawWaveform();
99
+ });
100
+ resizeObserver.observe(track);
101
+ return ()=>{
102
+ resizeObserver.disconnect();
103
+ };
104
+ }, [
105
+ peaks,
106
+ currentValue,
107
+ maxValue,
108
+ unplayedColor,
109
+ playedColor,
110
+ height
111
+ ]);
112
+ const formatTime = (seconds)=>{
113
+ const mins = Math.floor(seconds / 60);
114
+ const secs = Math.floor(seconds % 60);
115
+ return `${mins}:${secs.toString().padStart(2, '0')}`;
116
+ };
117
+ const getSecondsFromClientX = (clientX)=>{
118
+ if (!trackRef.current || !maxValue) return 0;
119
+ const rect = trackRef.current.getBoundingClientRect();
120
+ const x = Math.min(Math.max(clientX - rect.left, 0), rect.width);
121
+ const ratio = rect.width ? x / rect.width : 0;
122
+ return Math.min(Math.max(ratio * maxValue, 0), maxValue);
123
+ };
124
+ const leftOffset = `calc(${maxValue ? (hoverSeconds ?? 0) / maxValue * 100 : 0}% - 20px)`;
125
+ return /*#__PURE__*/ jsxs(StyledSlider, {
126
+ "aria-label": "Audio waveform track",
127
+ ...sliderProps,
128
+ width: width,
129
+ children: [
130
+ label && /*#__PURE__*/ jsx(Label, {
131
+ children: label
132
+ }),
133
+ showOutput && /*#__PURE__*/ jsx(SliderOutput, {
134
+ children: ({ state })=>formatTime(state.values[0])
135
+ }),
136
+ /*#__PURE__*/ jsxs(StyledSliderTrack, {
137
+ ref: trackRef,
138
+ height: height,
139
+ onMouseEnter: ()=>setIsHovering(true),
140
+ onMouseLeave: ()=>{
141
+ setIsHovering(false);
142
+ setHoverSeconds(null);
143
+ },
144
+ onMouseMove: (e)=>{
145
+ if (showHoverTime) setHoverSeconds(getSecondsFromClientX(e.clientX));
146
+ },
147
+ children: [
148
+ /*#__PURE__*/ jsx(Canvas, {
149
+ ref: canvasRef
150
+ }),
151
+ /*#__PURE__*/ jsx(HiddenThumb, {
152
+ children: ({ isFocusVisible })=>{
153
+ if (trackRef.current) if (isFocusVisible) trackRef.current.setAttribute('data-focus-visible', 'true');
154
+ else trackRef.current.removeAttribute('data-focus-visible');
155
+ return null;
156
+ }
157
+ }),
158
+ showHoverTime && isHovering && null !== hoverSeconds && /*#__PURE__*/ jsxs(Fragment, {
159
+ children: [
160
+ /*#__PURE__*/ jsx(HoverTooltip, {
161
+ style: {
162
+ left: leftOffset
163
+ },
164
+ children: formatTime(hoverSeconds)
165
+ }),
166
+ /*#__PURE__*/ jsx(HoverLine, {
167
+ style: {
168
+ left: `calc(${maxValue ? hoverSeconds / maxValue * 100 : 0}%)`
169
+ }
170
+ })
171
+ ]
172
+ })
173
+ ]
174
+ })
175
+ ]
176
+ });
177
+ };
178
+ const StyledSlider = styled(Slider)(({ width })=>({
179
+ display: 'flex',
180
+ flexDirection: 'column',
181
+ width: width || '100%',
182
+ position: 'relative',
183
+ gap: 4,
184
+ '& .react-aria-Label': {
185
+ fontSize: 14,
186
+ fontWeight: 500
187
+ },
188
+ '& .react-aria-SliderOutput': {
189
+ fontSize: 12,
190
+ fontVariantNumeric: 'tabular-nums'
191
+ }
192
+ }), marginProps);
193
+ const StyledSliderTrack = styled(SliderTrack)(({ theme, height })=>({
194
+ position: 'relative',
195
+ width: '100%',
196
+ height,
197
+ cursor: 'pointer',
198
+ borderRadius: 4,
199
+ '&[data-focus-visible]': {
200
+ outline: `1px solid ${theme.accent}`
201
+ },
202
+ '&[data-disabled]': {
203
+ opacity: 0.4,
204
+ cursor: 'not-allowed'
205
+ }
206
+ }));
207
+ const HiddenThumb = styled(SliderThumb)({
208
+ width: 0,
209
+ height: 0,
210
+ opacity: 0,
211
+ position: 'absolute',
212
+ top: '50%'
213
+ });
214
+ const Canvas = styled.canvas({
215
+ width: '100%',
216
+ height: '100%',
217
+ userSelect: 'none',
218
+ pointerEvents: 'none'
219
+ });
220
+ const HoverTooltip = styled.div(({ theme })=>({
221
+ position: 'absolute',
222
+ top: -28,
223
+ padding: '4px 8px',
224
+ borderRadius: 4,
225
+ backgroundColor: theme.background4,
226
+ color: theme.scale10,
227
+ fontSize: 12,
228
+ fontWeight: 500,
229
+ userSelect: 'none',
230
+ pointerEvents: 'none',
231
+ whiteSpace: 'nowrap',
232
+ boxShadow: theme.elevation2
233
+ }));
234
+ const HoverLine = styled.div(({ theme })=>({
235
+ position: 'absolute',
236
+ top: 0,
237
+ bottom: 0,
238
+ width: 1,
239
+ backgroundColor: theme.scale8,
240
+ pointerEvents: 'none'
241
+ }));
242
+ const Waveform = Waveform2;
243
+ export { Waveform as default };
@@ -0,0 +1,193 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import styled from "@emotion/styled";
3
+ import { CompositeDecorator, EditorState, Modifier, SelectionState, convertFromRaw, convertToRaw } from "draft-js";
4
+ import { get } from "es-toolkit/compat";
5
+ const FOUND_FIELD = 'FOUND_FIELD';
6
+ const NOT_FOUND = 'NOT_FOUND';
7
+ const IMMUTABLE = 'IMMUTABLE';
8
+ const getVisualLength = (text)=>Array.from(text).length;
9
+ const visualSlice = (text, start, end)=>{
10
+ const chars = Array.from(text);
11
+ return chars.slice(start, end).join('');
12
+ };
13
+ const Field = styled.span(({ theme, error })=>({
14
+ display: 'inline-block',
15
+ color: error ? theme.color.error : theme.accent
16
+ }));
17
+ const FoundField = ({ children })=>/*#__PURE__*/ jsx(Field, {
18
+ children: children
19
+ });
20
+ const NotFoundField = ({ children })=>/*#__PURE__*/ jsx(Field, {
21
+ error: true,
22
+ children: children
23
+ });
24
+ const strategy = (block, callback, contentState, type)=>{
25
+ block.findEntityRanges((character)=>{
26
+ const key = character.getEntity();
27
+ if (key) {
28
+ const entityInstance = contentState.getEntity(key);
29
+ return entityInstance.getType() === type;
30
+ }
31
+ return false;
32
+ }, callback);
33
+ };
34
+ const decorator = new CompositeDecorator([
35
+ {
36
+ strategy: (block, callback, contentState)=>strategy(block, callback, contentState, FOUND_FIELD),
37
+ component: FoundField
38
+ },
39
+ {
40
+ strategy: (block, callback, contentState)=>strategy(block, callback, contentState, NOT_FOUND),
41
+ component: NotFoundField
42
+ }
43
+ ]);
44
+ const validateField = (testField, fields, displayValue)=>{
45
+ const field = fields.find(({ id })=>id === testField.id);
46
+ const composeMode = fields.every((item)=>!item.value);
47
+ const someFieldsHaveValues = fields.some((item)=>item.value);
48
+ let isValid = true;
49
+ let entityLabel = '';
50
+ if (field) {
51
+ if (composeMode) isValid = true;
52
+ else if ((displayValue || someFieldsHaveValues) && !field?.value) isValid = false;
53
+ } else isValid = false;
54
+ entityLabel = isValid ? displayValue && !composeMode ? field?.value || '' : field?.label || '' : field?.id || testField.id;
55
+ const label = displayValue && field?.value ? entityLabel : `{${entityLabel}}`;
56
+ return {
57
+ label,
58
+ isValid
59
+ };
60
+ };
61
+ const decode = (data)=>{
62
+ const parts = data.blocks.map((block)=>{
63
+ const { text, entityRanges } = block;
64
+ if (entityRanges.length < 1) return text;
65
+ const list = [];
66
+ let index = 0;
67
+ for (const { key, offset, length } of entityRanges){
68
+ if (offset > index) list.push(visualSlice(text, index, offset));
69
+ const id = get(data, `entityMap[${key}].data.id`, 'unknown');
70
+ list.push(`<<${id}>>`);
71
+ index = offset + length;
72
+ }
73
+ list.push(visualSlice(text, index));
74
+ return list.join('');
75
+ });
76
+ return parts.join(' ');
77
+ };
78
+ const encode = (text, fields, displayValue)=>{
79
+ const entityMap = {};
80
+ const block = {
81
+ text: '',
82
+ type: 'unstyled',
83
+ entityRanges: [],
84
+ key: '',
85
+ depth: 1,
86
+ inlineStyleRanges: []
87
+ };
88
+ const parts = text.replace(/(<<\w+?>>)/g, '~~$1~~').split('~~');
89
+ for(let i = 0; i < parts.length; i++){
90
+ let part = parts[i];
91
+ if (part.startsWith('<<')) {
92
+ const id = part.replace(/<<|>>/g, '');
93
+ const field = fields?.find((item)=>item.id === id);
94
+ const fieldToValidate = field || {
95
+ id,
96
+ label: ''
97
+ };
98
+ const { label, isValid } = validateField(fieldToValidate, fields || [], displayValue);
99
+ part = label;
100
+ block.entityRanges.push({
101
+ key: i,
102
+ offset: getVisualLength(block.text),
103
+ length: getVisualLength(part)
104
+ });
105
+ entityMap[i] = {
106
+ type: isValid ? FOUND_FIELD : NOT_FOUND,
107
+ mutability: IMMUTABLE,
108
+ data: {
109
+ id
110
+ }
111
+ };
112
+ }
113
+ block.text += part;
114
+ }
115
+ return convertFromRaw({
116
+ blocks: [
117
+ block
118
+ ],
119
+ entityMap
120
+ });
121
+ };
122
+ const createStateWithContent = (value, fields, displayValue)=>{
123
+ const encoded = encode(value, fields, displayValue);
124
+ const newEditorState = EditorState.createWithContent(encoded, decorator);
125
+ return newEditorState;
126
+ };
127
+ const getRawState = (state, decoded = true)=>{
128
+ const content = state.getCurrentContent();
129
+ const convertedState = convertToRaw(content);
130
+ return decoded ? decode(convertedState) : convertedState;
131
+ };
132
+ const getEntities = (state)=>{
133
+ const convertedState = getRawState(state, false);
134
+ const entities = 'string' != typeof convertedState ? Object.values(convertedState.entityMap) : [];
135
+ return entities;
136
+ };
137
+ const hasMissingEntities = (state)=>{
138
+ const entities = getEntities(state);
139
+ const hasMissing = entities.some((entity)=>entity.type === NOT_FOUND);
140
+ return hasMissing;
141
+ };
142
+ const insertFieldEntity = (field, fields, state, displayValue)=>{
143
+ const { id } = field;
144
+ const content = state.getCurrentContent();
145
+ const selection = state.getSelection();
146
+ const { label, isValid } = validateField(field, fields, displayValue);
147
+ const type = isValid ? FOUND_FIELD : NOT_FOUND;
148
+ const contentStateWithEntity = content.createEntity(type, IMMUTABLE, {
149
+ id
150
+ });
151
+ const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
152
+ const textWithEntity = Modifier.insertText(content, selection, label, void 0, entityKey);
153
+ const newState = EditorState.push(state, textWithEntity, 'insert-characters');
154
+ return EditorState.forceSelection(newState, textWithEntity.getSelectionAfter());
155
+ };
156
+ const getFocusStateAtEnd = (state)=>{
157
+ const content = state.getCurrentContent();
158
+ const block = content.getLastBlock();
159
+ const key = block.getKey();
160
+ const length = block.getLength();
161
+ const selection = new SelectionState({
162
+ anchorKey: key,
163
+ anchorOffset: length,
164
+ focusKey: key,
165
+ focusOffset: length
166
+ });
167
+ const atEnd = EditorState.forceSelection(state, selection);
168
+ return atEnd;
169
+ };
170
+ const getPastedState = (text, state)=>{
171
+ const currentContent = state.getCurrentContent();
172
+ const selection = state.getSelection();
173
+ const block = {
174
+ text,
175
+ type: 'unstyled',
176
+ entityRanges: [],
177
+ key: '',
178
+ depth: 1,
179
+ inlineStyleRanges: []
180
+ };
181
+ const content = convertFromRaw({
182
+ blocks: [
183
+ block
184
+ ],
185
+ entityMap: {}
186
+ });
187
+ const pastedState = EditorState.createWithContent(content, decorator);
188
+ const pastedBlocks = pastedState.getCurrentContent().getBlockMap();
189
+ const newState = Modifier.replaceWithFragment(currentContent, selection, pastedBlocks);
190
+ const newEditorState = EditorState.push(state, newState, 'insert-fragment');
191
+ return newEditorState;
192
+ };
193
+ export { createStateWithContent, decode, decorator, encode, getEntities, getFocusStateAtEnd, getPastedState, getRawState, hasMissingEntities, insertFieldEntity };
@@ -0,0 +1,28 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { cloneElement } from "react";
3
+ import Icon from "../Icon/Icon.js";
4
+ const getIcon = (icon, props)=>{
5
+ const getClonedIcon = (element)=>/*#__PURE__*/ cloneElement(element, props);
6
+ if ('string' == typeof icon) {
7
+ const { width, height, ...rest } = props || {};
8
+ return /*#__PURE__*/ jsx(Icon, {
9
+ name: icon,
10
+ ...rest
11
+ });
12
+ }
13
+ if ('object' == typeof icon && 'props' in icon && 'trigger' in icon.props) return /*#__PURE__*/ cloneElement(icon, {
14
+ trigger: getClonedIcon(icon.props.trigger)
15
+ });
16
+ if ('object' == typeof icon && 'props' in icon) return getClonedIcon(icon);
17
+ if (icon.svg) return /*#__PURE__*/ jsx(Icon, {
18
+ ...icon,
19
+ ...props
20
+ });
21
+ const { width, height, ...rest } = props || {};
22
+ return /*#__PURE__*/ jsx(Icon, {
23
+ ...icon,
24
+ ...rest
25
+ });
26
+ };
27
+ const helpers_getIcon = getIcon;
28
+ export { helpers_getIcon as default };
@@ -0,0 +1,20 @@
1
+ const getPopPosition = (pos)=>{
2
+ let side = 'top';
3
+ let align = 'center';
4
+ if (!pos) return {
5
+ side,
6
+ align
7
+ };
8
+ const [sideProp, alignProp] = pos.split(' ');
9
+ if ('left' === sideProp) side = 'left';
10
+ if ('right' === sideProp) side = 'right';
11
+ if ('bottom' === sideProp) side = 'bottom';
12
+ if ('left' === alignProp || 'top' === alignProp) align = 'start';
13
+ if ('right' === alignProp || 'bottom' === alignProp) align = 'end';
14
+ return {
15
+ side,
16
+ align
17
+ };
18
+ };
19
+ const helpers_getPopPosition = getPopPosition;
20
+ export { helpers_getPopPosition as default };
@@ -0,0 +1,3 @@
1
+ const isPropAllowed = (prop, propArray)=>!propArray.includes(prop);
2
+ const helpers_isPropAllowed = isPropAllowed;
3
+ export { helpers_isPropAllowed as default };
@@ -0,0 +1,47 @@
1
+ const parseValue = (value)=>{
2
+ if ('number' == typeof value) return value;
3
+ if ('string' == typeof value) return Number.parseInt(value.replace('px', ''), 10);
4
+ return 0;
5
+ };
6
+ const mergePadding_mergePadding = (paddingObj)=>{
7
+ const paddingValues = {
8
+ top: 0,
9
+ right: 0,
10
+ bottom: 0,
11
+ left: 0
12
+ };
13
+ const { padding, paddingTop, paddingRight, paddingBottom, paddingLeft } = paddingObj;
14
+ if (padding) {
15
+ const paddingString = 'string' == typeof padding ? padding : padding.toString();
16
+ const values = paddingString.split(' ').map(parseValue);
17
+ switch(values.length){
18
+ case 1:
19
+ paddingValues.top = paddingValues.right = paddingValues.bottom = paddingValues.left = values[0];
20
+ break;
21
+ case 2:
22
+ paddingValues.top = paddingValues.bottom = values[0];
23
+ paddingValues.right = paddingValues.left = values[1];
24
+ break;
25
+ case 3:
26
+ paddingValues.top = values[0];
27
+ paddingValues.right = paddingValues.left = values[1];
28
+ paddingValues.bottom = values[2];
29
+ break;
30
+ case 4:
31
+ paddingValues.top = values[0];
32
+ paddingValues.right = values[1];
33
+ paddingValues.bottom = values[2];
34
+ paddingValues.left = values[3];
35
+ break;
36
+ default:
37
+ break;
38
+ }
39
+ }
40
+ if (void 0 !== paddingTop) paddingValues.top = parseValue(paddingTop);
41
+ if (void 0 !== paddingRight) paddingValues.right = parseValue(paddingRight);
42
+ if (void 0 !== paddingBottom) paddingValues.bottom = parseValue(paddingBottom);
43
+ if (void 0 !== paddingLeft) paddingValues.left = parseValue(paddingLeft);
44
+ return paddingValues;
45
+ };
46
+ const mergePadding = mergePadding_mergePadding;
47
+ export { mergePadding as default };
@@ -0,0 +1,34 @@
1
+ const widthHeightProps = ({ width, height })=>({
2
+ width,
3
+ height
4
+ });
5
+ const maxWidthHeightProps = ({ maxWidth, maxHeight })=>({
6
+ maxWidth,
7
+ maxHeight
8
+ });
9
+ const minWidthHeightProps = ({ minWidth, minHeight })=>({
10
+ minWidth,
11
+ minHeight
12
+ });
13
+ const paddingProps = ({ padding, paddingTop, paddingBottom, paddingRight, paddingLeft })=>({
14
+ padding,
15
+ paddingTop,
16
+ paddingBottom,
17
+ paddingRight,
18
+ paddingLeft
19
+ });
20
+ const marginProps = ({ margin, marginTop, marginBottom, marginRight, marginLeft })=>({
21
+ margin,
22
+ marginTop,
23
+ marginBottom,
24
+ marginRight,
25
+ marginLeft
26
+ });
27
+ const positionProps = ({ position, top, bottom, right, left })=>({
28
+ position,
29
+ top,
30
+ bottom,
31
+ right,
32
+ left
33
+ });
34
+ export { marginProps, maxWidthHeightProps, minWidthHeightProps, paddingProps, positionProps, widthHeightProps };
File without changes
File without changes
File without changes
File without changes
File without changes