@geneui/components 2.11.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 (154) hide show
  1. package/ActionableList.js +1761 -0
  2. package/AdvancedSearch.js +872 -0
  3. package/Alert.js +98 -0
  4. package/Avatar.js +77 -0
  5. package/Badge.js +76 -0
  6. package/Breadcrumb.js +128 -0
  7. package/BusyLoader.js +69 -0
  8. package/Button.js +130 -0
  9. package/CHANGELOG.md +424 -0
  10. package/Card.js +513 -0
  11. package/CardList.js +705 -0
  12. package/CellMeasurerCache-c11cec83.js +229 -0
  13. package/Charts.js +99 -0
  14. package/Checkbox.js +232 -0
  15. package/CheckboxGroup.js +206 -0
  16. package/CheckboxGroupWithSearch.js +279 -0
  17. package/Collapse.js +196 -0
  18. package/ColorPicker.js +210 -0
  19. package/ComboBox.js +99 -0
  20. package/Counter.js +99 -0
  21. package/DateFilter.js +179 -0
  22. package/DatePicker.js +1231 -0
  23. package/DatePickerInput.js +30 -0
  24. package/Divider.js +56 -0
  25. package/Drawer.js +264 -0
  26. package/Dropdown.js +99 -0
  27. package/Editor.js +22965 -0
  28. package/Empty.js +132 -0
  29. package/ExtendedInput.js +578 -0
  30. package/Form.js +116 -0
  31. package/FormContainer.js +189 -0
  32. package/FormableCheckbox.js +27 -0
  33. package/FormableDatePicker.js +39 -0
  34. package/FormableDropdown.js +105 -0
  35. package/FormableEditor.js +24 -0
  36. package/FormableHOC-21051057.js +83 -0
  37. package/FormableMultiSelectDropdown.js +105 -0
  38. package/FormableNumberInput.js +31 -0
  39. package/FormableRadio.js +23 -0
  40. package/FormableSwitcher.js +23 -0
  41. package/FormableTextInput.js +31 -0
  42. package/FormableUploader.js +40 -0
  43. package/GeneUIProvider.js +256 -0
  44. package/Grid.js +166 -0
  45. package/Holder.js +99 -0
  46. package/Icon.js +63 -0
  47. package/Image.js +130 -0
  48. package/ImagePreview.js +99 -0
  49. package/KeyValue.js +63 -0
  50. package/Label.js +58 -0
  51. package/LinkButton.js +104 -0
  52. package/Menu.js +277 -0
  53. package/MobileNavigation.js +95 -0
  54. package/MobilePopup.js +180 -0
  55. package/Modal.js +251 -0
  56. package/ModuleTitle.js +99 -0
  57. package/NavigationMenu.js +212 -0
  58. package/Notification.js +120 -0
  59. package/Option.js +186 -0
  60. package/Overlay.js +99 -0
  61. package/Overspread.js +343 -0
  62. package/Pagination.js +258 -0
  63. package/Paper.js +97 -0
  64. package/Popover-f4d1cac0.js +411 -0
  65. package/Popover.js +20 -0
  66. package/PopoverV2.js +19 -0
  67. package/Portal.js +58 -0
  68. package/Products.js +115 -0
  69. package/Profile.js +99 -0
  70. package/Progress.js +200 -0
  71. package/QRCode.js +816 -0
  72. package/README.md +90 -0
  73. package/Radio.js +152 -0
  74. package/RadioGroup.js +105 -0
  75. package/Range.js +14 -0
  76. package/RichEditor-b7928765.js +228 -0
  77. package/RichEditor.js +13 -0
  78. package/Scrollbar.js +1587 -0
  79. package/Search.js +72 -0
  80. package/SearchWithDropdown.js +195 -0
  81. package/Section.js +62 -0
  82. package/SkeletonLoader.js +82 -0
  83. package/Slider.js +256 -0
  84. package/Status.js +104 -0
  85. package/Steps.js +312 -0
  86. package/SuggestionList.js +15 -0
  87. package/Switcher.js +194 -0
  88. package/Table.js +102 -0
  89. package/TableCompositions.js +17028 -0
  90. package/Tabs.js +236 -0
  91. package/Tag.js +103 -0
  92. package/TextLink.js +22 -0
  93. package/Textarea.js +239 -0
  94. package/Time.js +63 -0
  95. package/TimePicker.js +99 -0
  96. package/Timeline.js +114 -0
  97. package/Title.js +66 -0
  98. package/Toaster.js +116 -0
  99. package/Tooltip.js +157 -0
  100. package/TransferList.js +502 -0
  101. package/Uploader.js +32 -0
  102. package/ValidatableCheckbox.js +126 -0
  103. package/ValidatableDatePicker.js +312 -0
  104. package/ValidatableDropdown.js +99 -0
  105. package/ValidatableElements.js +99 -0
  106. package/ValidatableMultiSelectDropdown.js +99 -0
  107. package/ValidatableNumberInput.js +194 -0
  108. package/ValidatableRadio.js +117 -0
  109. package/ValidatableSwitcher.js +94 -0
  110. package/ValidatableTextInput.js +164 -0
  111. package/ValidatableTimeInput.js +171 -0
  112. package/ValidatableUploader.js +94 -0
  113. package/Widget.js +99 -0
  114. package/_commonjsHelpers-24198af3.js +35 -0
  115. package/_rollupPluginBabelHelpers-e8fb2e5c.js +16 -0
  116. package/checkTimeValidation-e56771be.js +16 -0
  117. package/checkboxRadioSwitcher-5b69d7bd.js +4 -0
  118. package/clsx.m-2bb6df4b.js +3 -0
  119. package/configs-91c86664.js +96 -0
  120. package/configs.js +131 -0
  121. package/dateValidation-67caec66.js +225 -0
  122. package/debounce-4419bc2f.js +17 -0
  123. package/globalStyling-9c60a159.js +4 -0
  124. package/guid-8ddf77b3.js +16 -0
  125. package/index-00fe8887.js +193 -0
  126. package/index-0cf65939.js +30991 -0
  127. package/index-122432cd.js +270 -0
  128. package/index-262edd7a.js +77 -0
  129. package/index-5cea9a7d.js +407 -0
  130. package/index-5e722d91.js +867 -0
  131. package/index-67f4d4d1.js +6568 -0
  132. package/index-6ff23041.js +66 -0
  133. package/index-702bf24a.js +1938 -0
  134. package/index-a4635754.js +329 -0
  135. package/index-a59530cd.js +4 -0
  136. package/index-ac59cb10.js +169 -0
  137. package/index-b7a33c58.js +11 -0
  138. package/index-d9e8a888.js +987 -0
  139. package/index-e0af0caf.js +1182 -0
  140. package/index-e8776f3d.js +807 -0
  141. package/index.js +128 -0
  142. package/localization-4ba17032.js +46 -0
  143. package/objectWithoutPropertiesLoose-299691d8.js +78 -0
  144. package/package.json +190 -0
  145. package/rangeAndSlider-20599da4.js +8839 -0
  146. package/react-beautiful-dnd.esm-38c37304.js +10117 -0
  147. package/style-inject.es-746bb8ed.js +28 -0
  148. package/useClickOutside-5183e396.js +25 -0
  149. package/useDeviceType-dd51db38.js +15 -0
  150. package/useEllipsisDetection-ef536015.js +23 -0
  151. package/useKeyDown-38102ae7.js +21 -0
  152. package/useMount-6fef51a5.js +9 -0
  153. package/useWidth-9f4647f8.js +15 -0
  154. package/useWindowSize-80369d76.js +33 -0
@@ -0,0 +1,270 @@
1
+ import * as React from 'react';
2
+
3
+ const LEFT = "Left";
4
+ const RIGHT = "Right";
5
+ const UP = "Up";
6
+ const DOWN = "Down";
7
+
8
+ /* global document */
9
+ const defaultProps = {
10
+ delta: 10,
11
+ preventScrollOnSwipe: false,
12
+ rotationAngle: 0,
13
+ trackMouse: false,
14
+ trackTouch: true,
15
+ swipeDuration: Infinity,
16
+ touchEventOptions: { passive: true },
17
+ };
18
+ const initialState = {
19
+ first: true,
20
+ initial: [0, 0],
21
+ start: 0,
22
+ swiping: false,
23
+ xy: [0, 0],
24
+ };
25
+ const mouseMove = "mousemove";
26
+ const mouseUp = "mouseup";
27
+ const touchEnd = "touchend";
28
+ const touchMove = "touchmove";
29
+ const touchStart = "touchstart";
30
+ function getDirection(absX, absY, deltaX, deltaY) {
31
+ if (absX > absY) {
32
+ if (deltaX > 0) {
33
+ return RIGHT;
34
+ }
35
+ return LEFT;
36
+ }
37
+ else if (deltaY > 0) {
38
+ return DOWN;
39
+ }
40
+ return UP;
41
+ }
42
+ function rotateXYByAngle(pos, angle) {
43
+ if (angle === 0)
44
+ return pos;
45
+ const angleInRadians = (Math.PI / 180) * angle;
46
+ const x = pos[0] * Math.cos(angleInRadians) + pos[1] * Math.sin(angleInRadians);
47
+ const y = pos[1] * Math.cos(angleInRadians) - pos[0] * Math.sin(angleInRadians);
48
+ return [x, y];
49
+ }
50
+ function getHandlers(set, handlerProps) {
51
+ const onStart = (event) => {
52
+ const isTouch = "touches" in event;
53
+ // if more than a single touch don't track, for now...
54
+ if (isTouch && event.touches.length > 1)
55
+ return;
56
+ set((state, props) => {
57
+ // setup mouse listeners on document to track swipe since swipe can leave container
58
+ if (props.trackMouse && !isTouch) {
59
+ document.addEventListener(mouseMove, onMove);
60
+ document.addEventListener(mouseUp, onUp);
61
+ }
62
+ const { clientX, clientY } = isTouch ? event.touches[0] : event;
63
+ const xy = rotateXYByAngle([clientX, clientY], props.rotationAngle);
64
+ props.onTouchStartOrOnMouseDown &&
65
+ props.onTouchStartOrOnMouseDown({ event });
66
+ return Object.assign(Object.assign(Object.assign({}, state), initialState), { initial: xy.slice(), xy, start: event.timeStamp || 0 });
67
+ });
68
+ };
69
+ const onMove = (event) => {
70
+ set((state, props) => {
71
+ const isTouch = "touches" in event;
72
+ // Discount a swipe if additional touches are present after
73
+ // a swipe has started.
74
+ if (isTouch && event.touches.length > 1) {
75
+ return state;
76
+ }
77
+ // if swipe has exceeded duration stop tracking
78
+ if (event.timeStamp - state.start > props.swipeDuration) {
79
+ return state.swiping ? Object.assign(Object.assign({}, state), { swiping: false }) : state;
80
+ }
81
+ const { clientX, clientY } = isTouch ? event.touches[0] : event;
82
+ const [x, y] = rotateXYByAngle([clientX, clientY], props.rotationAngle);
83
+ const deltaX = x - state.xy[0];
84
+ const deltaY = y - state.xy[1];
85
+ const absX = Math.abs(deltaX);
86
+ const absY = Math.abs(deltaY);
87
+ const time = (event.timeStamp || 0) - state.start;
88
+ const velocity = Math.sqrt(absX * absX + absY * absY) / (time || 1);
89
+ const vxvy = [deltaX / (time || 1), deltaY / (time || 1)];
90
+ const dir = getDirection(absX, absY, deltaX, deltaY);
91
+ // if swipe is under delta and we have not started to track a swipe: skip update
92
+ const delta = typeof props.delta === "number"
93
+ ? props.delta
94
+ : props.delta[dir.toLowerCase()] ||
95
+ defaultProps.delta;
96
+ if (absX < delta && absY < delta && !state.swiping)
97
+ return state;
98
+ const eventData = {
99
+ absX,
100
+ absY,
101
+ deltaX,
102
+ deltaY,
103
+ dir,
104
+ event,
105
+ first: state.first,
106
+ initial: state.initial,
107
+ velocity,
108
+ vxvy,
109
+ };
110
+ // call onSwipeStart if present and is first swipe event
111
+ eventData.first && props.onSwipeStart && props.onSwipeStart(eventData);
112
+ // call onSwiping if present
113
+ props.onSwiping && props.onSwiping(eventData);
114
+ // track if a swipe is cancelable (handler for swiping or swiped(dir) exists)
115
+ // so we can call preventDefault if needed
116
+ let cancelablePageSwipe = false;
117
+ if (props.onSwiping ||
118
+ props.onSwiped ||
119
+ props[`onSwiped${dir}`]) {
120
+ cancelablePageSwipe = true;
121
+ }
122
+ if (cancelablePageSwipe &&
123
+ props.preventScrollOnSwipe &&
124
+ props.trackTouch &&
125
+ event.cancelable) {
126
+ event.preventDefault();
127
+ }
128
+ return Object.assign(Object.assign({}, state), {
129
+ // first is now always false
130
+ first: false, eventData, swiping: true });
131
+ });
132
+ };
133
+ const onEnd = (event) => {
134
+ set((state, props) => {
135
+ let eventData;
136
+ if (state.swiping && state.eventData) {
137
+ // if swipe is less than duration fire swiped callbacks
138
+ if (event.timeStamp - state.start < props.swipeDuration) {
139
+ eventData = Object.assign(Object.assign({}, state.eventData), { event });
140
+ props.onSwiped && props.onSwiped(eventData);
141
+ const onSwipedDir = props[`onSwiped${eventData.dir}`];
142
+ onSwipedDir && onSwipedDir(eventData);
143
+ }
144
+ }
145
+ else {
146
+ props.onTap && props.onTap({ event });
147
+ }
148
+ props.onTouchEndOrOnMouseUp && props.onTouchEndOrOnMouseUp({ event });
149
+ return Object.assign(Object.assign(Object.assign({}, state), initialState), { eventData });
150
+ });
151
+ };
152
+ const cleanUpMouse = () => {
153
+ // safe to just call removeEventListener
154
+ document.removeEventListener(mouseMove, onMove);
155
+ document.removeEventListener(mouseUp, onUp);
156
+ };
157
+ const onUp = (e) => {
158
+ cleanUpMouse();
159
+ onEnd(e);
160
+ };
161
+ /**
162
+ * The value of passive on touchMove depends on `preventScrollOnSwipe`:
163
+ * - true => { passive: false }
164
+ * - false => { passive: true } // Default
165
+ *
166
+ * NOTE: When preventScrollOnSwipe is true, we attempt to call preventDefault to prevent scroll.
167
+ *
168
+ * props.touchEventOptions can also be set for all touch event listeners,
169
+ * but for `touchmove` specifically when `preventScrollOnSwipe` it will
170
+ * supersede and force passive to false.
171
+ *
172
+ */
173
+ const attachTouch = (el, props) => {
174
+ let cleanup = () => { };
175
+ if (el && el.addEventListener) {
176
+ const baseOptions = Object.assign(Object.assign({}, defaultProps.touchEventOptions), props.touchEventOptions);
177
+ // attach touch event listeners and handlers
178
+ const tls = [
179
+ [touchStart, onStart, baseOptions],
180
+ // preventScrollOnSwipe option supersedes touchEventOptions.passive
181
+ [
182
+ touchMove,
183
+ onMove,
184
+ Object.assign(Object.assign({}, baseOptions), (props.preventScrollOnSwipe ? { passive: false } : {})),
185
+ ],
186
+ [touchEnd, onEnd, baseOptions],
187
+ ];
188
+ tls.forEach(([e, h, o]) => el.addEventListener(e, h, o));
189
+ // return properly scoped cleanup method for removing listeners, options not required
190
+ cleanup = () => tls.forEach(([e, h]) => el.removeEventListener(e, h));
191
+ }
192
+ return cleanup;
193
+ };
194
+ const onRef = (el) => {
195
+ // "inline" ref functions are called twice on render, once with null then again with DOM element
196
+ // ignore null here
197
+ if (el === null)
198
+ return;
199
+ set((state, props) => {
200
+ // if the same DOM el as previous just return state
201
+ if (state.el === el)
202
+ return state;
203
+ const addState = {};
204
+ // if new DOM el clean up old DOM and reset cleanUpTouch
205
+ if (state.el && state.el !== el && state.cleanUpTouch) {
206
+ state.cleanUpTouch();
207
+ addState.cleanUpTouch = void 0;
208
+ }
209
+ // only attach if we want to track touch
210
+ if (props.trackTouch && el) {
211
+ addState.cleanUpTouch = attachTouch(el, props);
212
+ }
213
+ // store event attached DOM el for comparison, clean up, and re-attachment
214
+ return Object.assign(Object.assign(Object.assign({}, state), { el }), addState);
215
+ });
216
+ };
217
+ // set ref callback to attach touch event listeners
218
+ const output = {
219
+ ref: onRef,
220
+ };
221
+ // if track mouse attach mouse down listener
222
+ if (handlerProps.trackMouse) {
223
+ output.onMouseDown = onStart;
224
+ }
225
+ return [output, attachTouch];
226
+ }
227
+ function updateTransientState(state, props, previousProps, attachTouch) {
228
+ // if trackTouch is off or there is no el, then remove handlers if necessary and exit
229
+ if (!props.trackTouch || !state.el) {
230
+ if (state.cleanUpTouch) {
231
+ state.cleanUpTouch();
232
+ }
233
+ return Object.assign(Object.assign({}, state), { cleanUpTouch: undefined });
234
+ }
235
+ // trackTouch is on, so if there are no handlers attached, attach them and exit
236
+ if (!state.cleanUpTouch) {
237
+ return Object.assign(Object.assign({}, state), { cleanUpTouch: attachTouch(state.el, props) });
238
+ }
239
+ // trackTouch is on and handlers are already attached, so if preventScrollOnSwipe changes value,
240
+ // remove and reattach handlers (this is required to update the passive option when attaching
241
+ // the handlers)
242
+ if (props.preventScrollOnSwipe !== previousProps.preventScrollOnSwipe ||
243
+ props.touchEventOptions.passive !== previousProps.touchEventOptions.passive) {
244
+ state.cleanUpTouch();
245
+ return Object.assign(Object.assign({}, state), { cleanUpTouch: attachTouch(state.el, props) });
246
+ }
247
+ return state;
248
+ }
249
+ function useSwipeable(options) {
250
+ const { trackMouse } = options;
251
+ const transientState = React.useRef(Object.assign({}, initialState));
252
+ const transientProps = React.useRef(Object.assign({}, defaultProps));
253
+ // track previous rendered props
254
+ const previousProps = React.useRef(Object.assign({}, transientProps.current));
255
+ previousProps.current = Object.assign({}, transientProps.current);
256
+ // update current render props & defaults
257
+ transientProps.current = Object.assign(Object.assign({}, defaultProps), options);
258
+ // Force defaults for config properties
259
+ let defaultKey;
260
+ for (defaultKey in defaultProps) {
261
+ if (transientProps.current[defaultKey] === void 0) {
262
+ transientProps.current[defaultKey] = defaultProps[defaultKey];
263
+ }
264
+ }
265
+ const [handlers, attachTouch] = React.useMemo(() => getHandlers((stateSetter) => (transientState.current = stateSetter(transientState.current, transientProps.current)), { trackMouse }), [trackMouse]);
266
+ transientState.current = updateTransientState(transientState.current, transientProps.current, previousProps.current, attachTouch);
267
+ return handlers;
268
+ }
269
+
270
+ export { useSwipeable as u };
@@ -0,0 +1,77 @@
1
+ import React__default, { useContext, useReducer, useState, useCallback, useMemo, createContext } from 'react';
2
+
3
+ const Context = /*#__PURE__*/createContext();
4
+ const useFormContext = () => useContext(Context);
5
+ const reducer = (state, _ref) => {
6
+ let {
7
+ type,
8
+ field
9
+ } = _ref;
10
+ switch (type) {
11
+ case 'add':
12
+ return [...state, field];
13
+ case 'validation':
14
+ return state.map(item => ({
15
+ ...item,
16
+ isValid: field.name === item.name ? field.isValid : item.isValid
17
+ }));
18
+ case 'change':
19
+ return state.map(item => ({
20
+ ...item,
21
+ isChanged: field.name === item.name ? field.isChanged : item.isChanged
22
+ }));
23
+ case 'unmount':
24
+ return state.filter(item => field.name !== item.name);
25
+ default:
26
+ return state;
27
+ }
28
+ };
29
+ function FormProvider(_ref2) {
30
+ let {
31
+ value,
32
+ children
33
+ } = _ref2;
34
+ const [fields, dispatch] = useReducer(reducer, []);
35
+ const [readOnlyState, setReadOnly] = useState(value.readOnly);
36
+ const [allowValidation, setAllowValidation] = useState(false);
37
+
38
+ // handle field `isChanged` prop when value changes
39
+ const handleFieldChange = useCallback(field => dispatch({
40
+ type: 'change',
41
+ field
42
+ }), []);
43
+
44
+ // add field to store when mounted
45
+ const handleFieldMount = useCallback(field => dispatch({
46
+ type: 'add',
47
+ field
48
+ }), []);
49
+
50
+ // remove field when unmounted
51
+ const handleFieldUnMount = useCallback(field => dispatch({
52
+ type: 'unmount',
53
+ field
54
+ }), []);
55
+
56
+ // handle field `isValid` prop when validation changes
57
+ const handleValidationChange = useCallback(field => dispatch({
58
+ type: 'validation',
59
+ field
60
+ }), []);
61
+ const contextProps = useMemo(() => ({
62
+ fields,
63
+ setReadOnly,
64
+ readOnlyState,
65
+ allowValidation,
66
+ handleFieldMount,
67
+ handleFieldUnMount,
68
+ handleFieldChange,
69
+ setAllowValidation,
70
+ handleValidationChange
71
+ }), [fields, readOnlyState, allowValidation]);
72
+ return /*#__PURE__*/React__default.createElement(Context.Provider, {
73
+ value: contextProps
74
+ }, children);
75
+ }
76
+
77
+ export { FormProvider as F, useFormContext as u };